orm_adapter-fmrest 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e19c15e6fcc08c53a32510c1a98c5dc66271f5d00143c5b5cc18ac30717f51f
4
+ data.tar.gz: c123ee2e3d1fca48ac771444f8b710fd5cb1f5cf8a6903af41578fb5cd60ebad
5
+ SHA512:
6
+ metadata.gz: c5e22129ff41cbf904e0f74182917eaf471bc7cda2356768ccf2ec046a5d1107154eb5dc2921b944c95a2c5f01ee484e6da1ed247e677bc7aef30efcbe1e6b4c
7
+ data.tar.gz: 876ded434edf728ab5237547dcb5f148eeaea321bad7ed9fb62bc24fc5e0a164b5f8e06fed4395ed2b174650cef2d90683b053ed198a1e8f9edfbe87a0b8025b
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.idea/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ /Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.6
7
+ before_install: gem install bundler -v 1.17.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at martin@itcmeier.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in orm_adapter-fmrest.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Martin Meier
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # OrmAdapter::Fmrest
2
+
3
+ Adds Filemaker Rest to the orm_adaptor project.
4
+
5
+ ### ORM Adapter
6
+ >Provides a single point of entry for popular ruby ORMs. Its target audience is gem authors who want to support more than one ORM.
7
+
8
+ For more information see the [orm_adapter project](http://github.com/ianwhite/orm_adapter).
9
+
10
+ ### FmRest
11
+
12
+ >A Ruby client for FileMaker's Data API with ActiveRecord-ish ORM features.
13
+
14
+ For more information see the [fmrest-ruby gem](https://github.com/beezwax/fmrest-ruby).
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'orm_adapter-fmrest'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install orm_adapter-fmrest
31
+
32
+ ## Devise
33
+
34
+ >Devise is a flexible authentication solution for Rails.
35
+
36
+ For more information see the [Devise](https://github.com/plataformatec/devise).
37
+
38
+ And now you can use Devise authentication based on Filemaker REST ORM.
39
+
40
+ Add the following lines to Gemfile:
41
+
42
+ ```ruby
43
+ gem 'fmrest-ruby'
44
+ gem 'orm_adapter-fmrest'
45
+ gem 'devise'
46
+ ```
47
+
48
+ And then configure Devise using "--orm fmrest" parameter:
49
+
50
+ $ rails generate devise:install --orm fmrest
51
+ $ rails generate devise User --orm fmrest
52
+
53
+ After that you can create User model:
54
+
55
+ ```ruby
56
+ class User < FmRest::Layout
57
+ layout('your_user_layout')
58
+ extend Devise::Models
59
+ devise :database_authenticatable, :rememberable, :trackable
60
+
61
+
62
+ end
63
+ ```
64
+
65
+ ## Known Limitations and Issues
66
+
67
+ * There is no unit test. Fill free to add it.
68
+
69
+ ## Acknowledge
70
+
71
+ Part of the code and logic (i.e. devise compatibility) is ripped from [orm_adapter-her](https://github.com/myxrome/orm_adapter-her).
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it
76
+ 2. Create your feature branch (git checkout -b my-new-feature)
77
+ 3. Commit your changes (git commit -am 'Add some feature')
78
+ 4. Push to the branch (git push origin my-new-feature)
79
+ 5. Create new Pull Request
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1 @@
1
+ # stub to enable devise to use orm_adapter-fmrest
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ # ORM adaptor for Filmaker Rest
4
+ require 'fmrest'
5
+
6
+ module FmRest
7
+ module Spyke
8
+ class Base
9
+ extend OrmAdapter::ToAdapter
10
+
11
+ class OrmAdapter < ::OrmAdapter::Base
12
+
13
+ # Get a list of the attribute names (field names) in the Filemaker Layout.
14
+ # Map attribute names
15
+ def column_names
16
+ return [] unless klass.respond_to? :layout
17
+
18
+ field_meta = layout_meta klass.layout
19
+ fields = field_meta.map{|f| f['name']}
20
+ return fields unless klass.respond_to? :mapped_attributes
21
+
22
+ # map attribute names
23
+ fields + klass.mapped_attributes.keys - klass.mapped_attributes.values
24
+ end
25
+
26
+ # Get an instance by id of the model. Raises an error if a model is not found.
27
+ # This should comply with ActiveModel#to_key API, i.e.:
28
+ #
29
+ # User.to_adapter.get!(@user.to_key) == @user
30
+ #
31
+ def get!(id)
32
+ klass.find wrap_key(id)
33
+ end
34
+
35
+ # Get an instance by id of the model. Returns nil if a model is not found.
36
+ # This should comply with ActiveModel#to_key API, i.e.:
37
+ #
38
+ # User.to_adapter.get(@user.to_key) == @user
39
+ #
40
+ def get(id)
41
+ klass.find wrap_key(id)
42
+ rescue FmRest::APIError::RecordMissingError
43
+ nil
44
+ end
45
+
46
+ # Find the first instance, optionally matching conditions, and specifying order
47
+ #
48
+ # You can call with just conditions, providing a hash
49
+ #
50
+ # User.to_adapter.find_first :name => "Fred", :age => 23
51
+ #
52
+ # Or you can specify :order, and :conditions as keys
53
+ #
54
+ # User.to_adapter.find_first :conditions => {:name => "Fred", :age => 23}
55
+ # User.to_adapter.find_first :order => [:age, :desc]
56
+ # User.to_adapter.find_first :order => :name, :conditions => {:age => 18}
57
+ #
58
+ # When specifying :order, it may be
59
+ # * a single arg e.g. <tt>:order => :name</tt>
60
+ # * a single pair with :asc, or :desc as last, e.g. <tt>:order => [:name, :desc]</tt>
61
+ # * an array of single args or pairs (with :asc or :desc as last), e.g. <tt>:order => [[:name, :asc], [:age, :desc]]</tt>
62
+ #
63
+ def find_first(options = {})
64
+ base_relation(options).first
65
+ end
66
+
67
+ # Find all models, optionally matching conditions, and specifying order
68
+ # @see OrmAdapter::Base#find_first for how to specify order and conditions
69
+ # @return Enumerable
70
+ def find_all(options = {})
71
+ base_relation(options)
72
+ end
73
+
74
+ # Create a model using attributes
75
+ def create!(attributes = {})
76
+ klass.new(attributes).save
77
+ end
78
+
79
+ # Destroy an instance by passing in the instance itself.
80
+ def destroy(object)
81
+ object.destroy if valid_object?(object)
82
+ end
83
+
84
+ private
85
+
86
+ # FmRest with converted query and sort parameters
87
+ # @return FmRest::Spyke::Relation
88
+ def base_relation(options)
89
+ conditions, order, limit, offset = extract_conditions!(options)
90
+
91
+ relation = klass.query(exact_conditions(conditions))
92
+ relation = relation.sort(*order_clause(order)) if order.any?
93
+ relation = relation.limit(limit) if limit
94
+ relation = relation.offset(offset) if offset
95
+
96
+ relation
97
+ end
98
+
99
+ def exact_conditions(conditions)
100
+ conditions.transform_values { |v| v.is_a?(String) ? "==#{v}" : v }
101
+ end
102
+
103
+ def order_clause(order)
104
+ order.map {|col, dir| (dir == :desc ? "#{col}__desc" : col).to_sym }
105
+ end
106
+
107
+ # given an order argument, returns an array of attributes (symbols) postfixed with __desc if order is reversed
108
+ def normalize_order(order)
109
+ if order.is_a? Array
110
+ order = [order] unless order.first.is_a?(Array)
111
+ order.map { |key, dir| (dir.to_s.downcase == 'desc' ? "key__desc" : key).to_sym }
112
+ else
113
+ [order.to_sym]
114
+ end
115
+ end
116
+
117
+ # request field meta data for layout of resource class
118
+ def layout_meta(layout)
119
+ FmRest::V1.build_connection(klass.try(:fmrest_config))
120
+ .get("layouts/#{layout}")
121
+ .body.dig('response', 'fieldMetaData')
122
+ end
123
+ end
124
+
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,5 @@
1
+ module OrmAdapter
2
+ module Fmrest
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'orm_adapter'
2
+ require 'orm_adapter/fmrest/version'
3
+ require 'orm_adapter/fmrest/adapter' if defined? FmRest::Layout
@@ -0,0 +1,46 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "orm_adapter/fmrest/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "orm_adapter-fmrest"
8
+ spec.version = OrmAdapter::Fmrest::VERSION
9
+ spec.authors = ["Martin Meier"]
10
+ spec.email = ["martin@itcmeier.de"]
11
+
12
+ spec.summary = %q{Adds Filemaker Rest to the orm_adaptor project.}
13
+ spec.homepage = "https://github.com/mameier"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = "https://github.com/mameier/orm_adapter-fmrest"
23
+ spec.metadata["changelog_uri"] = "https://github.com/mameier/orm_adapter-fmrest/CHANGELOG.md"
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_dependency 'activemodel', '>= 3.0.0', '< 7.0.0'
39
+ spec.add_dependency 'activesupport', '>= 3.0.0', '< 7.0.0'
40
+ spec.add_dependency 'orm_adapter', '>= 0.5.0'
41
+ spec.add_dependency 'fmrest', '>= 0.18.0'
42
+
43
+ spec.add_development_dependency "bundler", "~> 1.17"
44
+ spec.add_development_dependency "rake", "~> 10.0"
45
+ spec.add_development_dependency "rspec", "~> 3.0"
46
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orm_adapter-fmrest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martin Meier
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 7.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 7.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.0.0
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: 7.0.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 3.0.0
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: 7.0.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: orm_adapter
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.5.0
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 0.5.0
67
+ - !ruby/object:Gem::Dependency
68
+ name: fmrest
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 0.18.0
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 0.18.0
81
+ - !ruby/object:Gem::Dependency
82
+ name: bundler
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '1.17'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '1.17'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rake
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '10.0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '10.0'
109
+ - !ruby/object:Gem::Dependency
110
+ name: rspec
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '3.0'
116
+ type: :development
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '3.0'
123
+ description:
124
+ email:
125
+ - martin@itcmeier.de
126
+ executables: []
127
+ extensions: []
128
+ extra_rdoc_files: []
129
+ files:
130
+ - ".gitignore"
131
+ - ".travis.yml"
132
+ - CODE_OF_CONDUCT.md
133
+ - Gemfile
134
+ - LICENSE.txt
135
+ - README.md
136
+ - Rakefile
137
+ - lib/devise/orm/fmrest.rb
138
+ - lib/orm_adapter/fmrest.rb
139
+ - lib/orm_adapter/fmrest/adapter.rb
140
+ - lib/orm_adapter/fmrest/version.rb
141
+ - orm_adapter-fmrest.gemspec
142
+ homepage: https://github.com/mameier
143
+ licenses:
144
+ - MIT
145
+ metadata:
146
+ allowed_push_host: https://rubygems.org
147
+ homepage_uri: https://github.com/mameier
148
+ source_code_uri: https://github.com/mameier/orm_adapter-fmrest
149
+ changelog_uri: https://github.com/mameier/orm_adapter-fmrest/CHANGELOG.md
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ requirements: []
165
+ rubygems_version: 3.0.3
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Adds Filemaker Rest to the orm_adaptor project.
169
+ test_files: []