orm_adapter-her 0.2.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
+ SHA1:
3
+ metadata.gz: 0c9074f72065ce1e20090bebda456222fa995025
4
+ data.tar.gz: 7714a012857dd5a68b95bb843d061b5cf8edc679
5
+ SHA512:
6
+ metadata.gz: 5f57017a5a93be14a4f72ad5d2d902ddf56192347ea038ff09c660fda5e130a292974f4feb62ace2d8de2723250ddb129a745d546d4636b3443a77a6ab276aab
7
+ data.tar.gz: 75a2c9ebe5472ba7a9b95c0bb838d37f42b7e03a3ffd36f278b8c38884c24ee2fe87aee9a3463952580a05128098fce21243e3998fc93996bd0de3fa57189cbe
data/.gitignore ADDED
@@ -0,0 +1,112 @@
1
+ # rspec failure tracking
2
+ .rspec_status
3
+ ### JetBrains template
4
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
5
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
6
+
7
+ # User-specific stuff:
8
+ .idea/
9
+
10
+ ## File-based project format:
11
+ *.iws
12
+
13
+ ## Plugin-specific files:
14
+
15
+ # IntelliJ
16
+ /out/
17
+
18
+ # mpeltonen/sbt-idea plugin
19
+ .idea_modules/
20
+
21
+ # JIRA plugin
22
+ atlassian-ide-plugin.xml
23
+
24
+ # Crashlytics plugin (for Android Studio and IntelliJ)
25
+ com_crashlytics_export_strings.xml
26
+ crashlytics.properties
27
+ crashlytics-build.properties
28
+ fabric.properties
29
+ ### Rails template
30
+ *.rbc
31
+ capybara-*.html
32
+ .rspec
33
+ /log
34
+ /tmp
35
+ /db/*.sqlite3
36
+ /db/*.sqlite3-journal
37
+ /public/system
38
+ /spec/tmp
39
+ **.orig
40
+ rerun.txt
41
+ pickle-email-*.html
42
+
43
+ config/initializers/secret_token.rb
44
+
45
+ # Only include if you have production secrets in this file, which is no longer a Rails default
46
+ # config/secrets.yml
47
+
48
+ # dotenv
49
+ .env
50
+
51
+ ## Environment normalization:
52
+ /.bundle
53
+ /vendor/bundle
54
+
55
+ # these should all be checked in to normalize the environment:
56
+ # Gemfile.lock, .ruby-version, .ruby-gemset
57
+
58
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
59
+ .rvmrc
60
+
61
+ # if using bower-rails ignore default bower_components path bower.json files
62
+ /vendor/assets/bower_components
63
+ *.bowerrc
64
+ bower.json
65
+
66
+ # Ignore pow environment settings
67
+ .powenv
68
+
69
+ # Ignore Byebug command history file.
70
+ .byebug_history
71
+ ### Ruby template
72
+ *.gem
73
+ /.config
74
+ /InstalledFiles
75
+ /spec/examples.txt
76
+ /test/tmp/
77
+ /test/version_tmp/
78
+
79
+ # Used by dotenv library to load environment variables.
80
+ # .env
81
+
82
+ ## Specific to RubyMotion:
83
+ .dat*
84
+ .repl_history
85
+ build/
86
+ *.bridgesupport
87
+ build-iPhoneOS/
88
+ build-iPhoneSimulator/
89
+
90
+ ## Specific to RubyMotion (use of CocoaPods):
91
+ #
92
+ # We recommend against adding the Pods directory to your .gitignore. However
93
+ # you should judge for yourself, the pros and cons are mentioned at:
94
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
95
+ #
96
+ # vendor/Pods/
97
+
98
+ ## Documentation cache and generated files:
99
+ /.yardoc/
100
+ /rdoc/
101
+
102
+ ## Environment normalization:
103
+ /lib/bundler/man/
104
+
105
+ # for a library or gem, you might want to ignore these files since the code is
106
+ # intended to run in multiple environments; otherwise, check them in:
107
+ # Gemfile.lock
108
+ # .ruby-version
109
+ # .ruby-gemset
110
+
111
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
112
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in orm_adapter-her.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Aleksey Zolotov
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,82 @@
1
+ # ORM Adapter - Her ORM Adapter
2
+
3
+ Adds Her ORM adapter to the orm_adapter 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
+ ### Her ORM
11
+ >Her is an ORM (Object Relational Mapper) that maps REST resources to Ruby objects. It is designed to build applications that are powered by a RESTful API instead of a database.
12
+
13
+ For more information see the [Her ORM](https://github.com/remiprev/her)
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'orm_adapter-her'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install orm_adapter-her
30
+
31
+ ## Devise
32
+
33
+ >Devise is a flexible authentication solution for Rails.
34
+
35
+ For more information see the [Devise](https://github.com/plataformatec/devise).
36
+
37
+ And now you can use Devise authentication based on Her ORM.
38
+
39
+ Add the following lines to Gemfile:
40
+
41
+ ```ruby
42
+ gem 'her'
43
+ gem 'orm_adapter-her'
44
+ gem 'devise'
45
+ ```
46
+
47
+ And then configure Devise using "--orm her" parameter:
48
+
49
+ $ rails generate devise:install --orm her
50
+ $ rails generate devise User --orm her
51
+
52
+ After that you can create User model:
53
+
54
+ ```ruby
55
+ class User
56
+ include Her::Model
57
+ extend Devise::Models
58
+ devise :database_authenticatable, :rememberable, :trackable
59
+
60
+ attributes :email, :encrypted_password, :reset_password_token, :reset_password_sent_at, :remember_created_at,
61
+ :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip, :last_sign_in_ip
62
+
63
+ end
64
+ ```
65
+
66
+ ## Known Limitations and Issues
67
+
68
+ * The find_ methods does not supports order, limit and offset options. Her ORM limitation.
69
+ * Her ORM does not supports save method with arguments, but Devise has save(validate: false). This is why there is SaveFix module. Remove it if any related gems will fix the issues.
70
+ * There is no unit test. Fill free to add it.
71
+
72
+ ## Contributing
73
+
74
+ 1. Fork it
75
+ 2. Create your feature branch (git checkout -b my-new-feature)
76
+ 3. Commit your changes (git commit -am 'Add some feature')
77
+ 4. Push to the branch (git push origin my-new-feature)
78
+ 5. Create new Pull Request
79
+
80
+ ## License
81
+
82
+ 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
File without changes
@@ -0,0 +1,3 @@
1
+ require 'orm_adapter'
2
+ require 'orm_adapter/her/version'
3
+ require 'orm_adapter/her/adapter' if defined? Her::Model
@@ -0,0 +1,86 @@
1
+ require 'her/model'
2
+
3
+ module Her
4
+ module Model
5
+
6
+ module ClassMethods
7
+ include OrmAdapter::ToAdapter
8
+
9
+ def model_attributes
10
+ @model_attributes
11
+ end
12
+
13
+ def attributes(*args)
14
+ @model_attributes = args
15
+ super(*args)
16
+ end
17
+
18
+ end
19
+
20
+ class OrmAdapter < ::OrmAdapter::Base
21
+
22
+ # Get a list of column/property/field names
23
+ def column_names
24
+ klass.model_attributes
25
+ end
26
+
27
+ # Get an instance by id of the model. Raises an error if a model is not found.
28
+ # This should comply with ActiveModel#to_key API, i.e.:
29
+ #
30
+ # User.to_adapter.get!(@user.to_key) == @user
31
+ #
32
+ def get!(id)
33
+ klass.find(klass.primary_key => wrap_key(id)) || raise(ArgumentError, "#{klass.name} not found with #{klass.primary_key} of #{wrap_key(id)}")
34
+ end
35
+
36
+ # Get an instance by id of the model. Returns nil if a model is not found.
37
+ # This should comply with ActiveModel#to_key API, i.e.:
38
+ #
39
+ # User.to_adapter.get(@user.to_key) == @user
40
+ #
41
+ def get(id)
42
+ klass.find(klass.primary_key => wrap_key(id))
43
+ end
44
+
45
+ # Find the first instance, optionally matching conditions, and specifying order
46
+ #
47
+ # You can call with just conditions, providing a hash
48
+ #
49
+ # User.to_adapter.find_first :name => "Fred", :age => 23
50
+ #
51
+ # Or you can specify :order, and :conditions as keys
52
+ #
53
+ # User.to_adapter.find_first :conditions => {:name => "Fred", :age => 23}
54
+ # User.to_adapter.find_first :order => [:age, :desc]
55
+ # User.to_adapter.find_first :order => :name, :conditions => {:age => 18}
56
+ #
57
+ # When specifying :order, it may be
58
+ # * a single arg e.g. <tt>:order => :name</tt>
59
+ # * a single pair with :asc, or :desc as last, e.g. <tt>:order => [:name, :desc]</tt>
60
+ # * an array of single args or pairs (with :asc or :desc as last), e.g. <tt>:order => [[:name, :asc], [:age, :desc]]</tt>
61
+ #
62
+ def find_first(options = {})
63
+ conditions, order = extract_conditions!(options)
64
+ klass.where(conditions).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
+ def find_all(options = {})
70
+ conditions, order = extract_conditions!(options)
71
+ klass.where(conditions).all
72
+ end
73
+
74
+ # Create a model using attributes
75
+ def create!(attributes = {})
76
+ klass.create(attributes)
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
+ end
85
+ end
86
+ end
@@ -0,0 +1,16 @@
1
+ require 'her/model'
2
+
3
+ module Her
4
+ module Model
5
+
6
+ module SaveFix
7
+
8
+ def save(*args)
9
+ super()
10
+ end
11
+
12
+ end
13
+ include Her::Model::SaveFix
14
+
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module OrmAdapter
2
+ module Her
3
+ VERSION = '0.2.0'
4
+ end
5
+ end
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'orm_adapter/her/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'orm_adapter-her'
8
+ spec.version = OrmAdapter::Her::VERSION
9
+ spec.authors = ['Aleksey Zolotov']
10
+ spec.email = ['myxrome@gmail.com']
11
+
12
+ spec.summary = 'Adds Her ORM adapter to the orm_adapter project.'
13
+ spec.description = 'Adds Her adapter to orm_adapter which provides a single point of entry for using basic features of popular ruby ORMs.'
14
+ spec.homepage = 'https://github.com/myxrome/orm_adapter-her'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'activemodel', '>= 3.0.0', '<= 6.0.0'
31
+ spec.add_dependency 'activesupport', '>= 3.0.0', '<= 6.0.0'
32
+ spec.add_dependency 'orm_adapter', '>= 0.5.0'
33
+ spec.add_dependency 'her', '>= 0.8.6'
34
+
35
+ spec.add_development_dependency 'bundler', '~> 1.15'
36
+ spec.add_development_dependency 'rake', '~> 10.0'
37
+ spec.add_development_dependency 'rspec', '~> 3.0'
38
+ end
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orm_adapter-her
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Aleksey Zolotov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-19 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: 6.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: 6.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: 6.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: 6.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: her
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 0.8.6
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 0.8.6
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.15'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '1.15'
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: Adds Her adapter to orm_adapter which provides a single point of entry
124
+ for using basic features of popular ruby ORMs.
125
+ email:
126
+ - myxrome@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - ".gitignore"
132
+ - Gemfile
133
+ - LICENSE.txt
134
+ - README.md
135
+ - Rakefile
136
+ - lib/devise/orm/her.rb
137
+ - lib/orm_adapter/her.rb
138
+ - lib/orm_adapter/her/adapter.rb
139
+ - lib/orm_adapter/her/save_method_fix.rb
140
+ - lib/orm_adapter/her/version.rb
141
+ - orm_adapter-her.gemspec
142
+ homepage: https://github.com/myxrome/orm_adapter-her
143
+ licenses:
144
+ - MIT
145
+ metadata:
146
+ allowed_push_host: https://rubygems.org
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.6.11
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Adds Her ORM adapter to the orm_adapter project.
167
+ test_files: []