Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
dleadbetter committed Aug 18, 2023
0 parents commit d6a3fd0
Show file tree
Hide file tree
Showing 32 changed files with 762 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.bundle/
/doc/
/log/*.log
/pkg/
/tmp/
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'faker', '~> 3.2.1'
gem 'resource_api', git: 'https://github.com/performant-software/resource-api.git', tag: 'v0.4.5'

gem 'sqlite3'

# Specify your gem's dependencies in core_data_connector.gemspec.
gemspec
172 changes: 172 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
GIT
remote: https://github.com/performant-software/resource-api.git
revision: ebfc4357bdfd13ae863f1e1aebdcc637be2ff6de
tag: v0.4.5
specs:
resource_api (0.1.0)
pagy (~> 5.10)
rails (>= 7.0, < 8)

PATH
remote: .
specs:
core_data_connector (0.1.0)
rails (>= 6.0.3.2, < 8)
resource_api

GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.7)
actionpack (= 7.0.7)
activesupport (= 7.0.7)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.7)
actionpack (= 7.0.7)
activejob (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.7)
actionpack (= 7.0.7)
actionview (= 7.0.7)
activejob (= 7.0.7)
activesupport (= 7.0.7)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.7)
actionview (= 7.0.7)
activesupport (= 7.0.7)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.7)
actionpack (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.7)
activesupport (= 7.0.7)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.7)
activesupport (= 7.0.7)
globalid (>= 0.3.6)
activemodel (7.0.7)
activesupport (= 7.0.7)
activerecord (7.0.7)
activemodel (= 7.0.7)
activesupport (= 7.0.7)
activestorage (7.0.7)
actionpack (= 7.0.7)
activejob (= 7.0.7)
activerecord (= 7.0.7)
activesupport (= 7.0.7)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
builder (3.2.4)
concurrent-ruby (1.2.2)
crass (1.0.6)
date (3.3.3)
erubi (1.12.0)
globalid (1.1.0)
activesupport (>= 5.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.5)
minitest (5.19.0)
net-imap (0.3.7)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.3-x86_64-darwin)
racc (~> 1.4)
pagy (5.10.1)
activesupport
racc (1.7.1)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.7)
actioncable (= 7.0.7)
actionmailbox (= 7.0.7)
actionmailer (= 7.0.7)
actionpack (= 7.0.7)
actiontext (= 7.0.7)
actionview (= 7.0.7)
activejob (= 7.0.7)
activemodel (= 7.0.7)
activerecord (= 7.0.7)
activestorage (= 7.0.7)
activesupport (= 7.0.7)
bundler (>= 1.15.0)
railties (= 7.0.7)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.7)
actionpack (= 7.0.7)
activesupport (= 7.0.7)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
sqlite3 (1.6.3-x86_64-darwin)
thor (1.2.2)
timeout (0.4.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.11)

PLATFORMS
x86_64-darwin-19

DEPENDENCIES
core_data_connector!
resource_api!
sqlite3

BUNDLED WITH
2.3.16
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2023 Derek Leadbetter

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# CoreDataConnector
Short description and motivation.

## Usage
How to use my plugin.

## Installation
Add this line to your application's Gemfile:

```ruby
gem "core_data_connector"
```

And then execute:
```bash
$ bundle
```

Or install it yourself as:
```bash
$ gem install core_data_connector
```

## Contributing
Contribution directions go here.

## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "bundler/setup"

load "rails/tasks/statistics.rake"

require "bundler/gem_tasks"
Empty file added app/controllers/concerns/.keep
Empty file.
17 changes: 17 additions & 0 deletions app/controllers/core_data_connector/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module CoreDataConnector
class ApplicationController < CoreDataConnector.config.base_controller_class.constantize
def current_user
return super if defined?(super)

nil
end

def item_class
"CoreDataConnector::#{controller_name.singularize.classify}".constantize
end

def serializer_class
"CoreDataConnector::#{"#{controller_name}_serializer".classify}".constantize
end
end
end
12 changes: 12 additions & 0 deletions app/controllers/core_data_connector/places_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module CoreDataConnector
class PlacesController < ApplicationController
# Search attributes
search_attributes 'core_data_connector_place_names.name'

# Left joins
left_joins :primary_name

# Preloads
preloads :primary_name
end
end
11 changes: 11 additions & 0 deletions app/jobs/core_data_connector/analyze_tables_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module CoreDataConnector
class AnalyzeTablesJob < ApplicationJob

# Analyzes all foreign tables to keep statistics up to date
def perform
postgres = Postgres.new
postgres.analyze_tables
end

end
end
4 changes: 4 additions & 0 deletions app/jobs/core_data_connector/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CoreDataConnector
class ApplicationJob < ActiveJob::Base
end
end
6 changes: 6 additions & 0 deletions app/mailers/core_data_connector/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module CoreDataConnector
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout "mailer"
end
end
Empty file added app/models/concerns/.keep
Empty file.
16 changes: 16 additions & 0 deletions app/models/concerns/core_data_connector/locateable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module CoreDataConnector
module Locateable
extend ActiveSupport::Concern

included do
# Relationships
has_many :locations, as: :locateable, dependent: :destroy, class_name: Location.to_s

# Nested attributes
accepts_nested_attributes_for :locations, allow_destroy: true

# Resourceable parameters
allow_params locations_attributes: [:id, :place_id, :_destroy]
end
end
end
8 changes: 8 additions & 0 deletions app/models/core_data_connector/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module CoreDataConnector
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

# Includes
include Resourceable
end
end
9 changes: 9 additions & 0 deletions app/models/core_data_connector/location.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module CoreDataConnector
class Location < ApplicationRecord
self.primary_key = :id

# Relationships
belongs_to :place
belongs_to :locateable, polymorphic: true
end
end
19 changes: 19 additions & 0 deletions app/models/core_data_connector/place.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module CoreDataConnector
class Place < ApplicationRecord
self.primary_key = :id

# Relationships
has_many :place_names, dependent: :destroy
has_one :primary_name, -> { where(primary: true) }, class_name: 'PlaceName'

# Nested attributes
accepts_nested_attributes_for :place_names, allow_destroy: true

# Resourceable parameters
allow_params place_names_attributes: [:id, :name, :primary, :_destroy]

def name
primary_name&.name
end
end
end
8 changes: 8 additions & 0 deletions app/models/core_data_connector/place_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module CoreDataConnector
class PlaceName < ApplicationRecord
self.primary_key = :id

# Relationships
belongs_to :place
end
end
6 changes: 6 additions & 0 deletions app/serializers/core_data_connector/places_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module CoreDataConnector
class PlacesSerializer < BaseSerializer
index_attributes :id, :name
show_attributes :id, place_names: [:id, :name, :primary]
end
end
Loading

0 comments on commit d6a3fd0

Please sign in to comment.