rmodel 0.4.0.dev → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +4 -0
  4. data/.travis.yml +4 -3
  5. data/README.md +119 -153
  6. data/Rakefile +1 -2
  7. data/examples/mongo_embedded.rb +27 -21
  8. data/examples/scopes.rb +28 -0
  9. data/examples/sql_repository.rb +14 -26
  10. data/examples/timestamps.rb +7 -10
  11. data/examples/webapp/models/task.rb +9 -0
  12. data/examples/webapp/repositories/task_repository.rb +14 -0
  13. data/examples/webapp/server.rb +25 -0
  14. data/examples/webapp/support/mappers.rb +11 -0
  15. data/examples/webapp/support/repositories.rb +12 -0
  16. data/examples/webapp/support/sources.rb +13 -0
  17. data/examples/webapp/views/index.erb +20 -0
  18. data/lib/rmodel.rb +11 -8
  19. data/lib/rmodel/array_mapper.rb +23 -0
  20. data/lib/rmodel/base_mapper.rb +56 -0
  21. data/lib/rmodel/dummy_mapper.rb +15 -0
  22. data/lib/rmodel/mongo/mapper.rb +11 -0
  23. data/lib/rmodel/mongo/source.rb +50 -0
  24. data/lib/rmodel/repository.rb +36 -0
  25. data/lib/rmodel/repository_ext/scopable.rb +44 -0
  26. data/lib/rmodel/repository_ext/sugarable.rb +35 -0
  27. data/lib/rmodel/repository_ext/timestampable.rb +29 -0
  28. data/lib/rmodel/scope.rb +31 -0
  29. data/lib/rmodel/sequel/mapper.rb +6 -0
  30. data/lib/rmodel/sequel/source.rb +43 -0
  31. data/lib/rmodel/uni_hash.rb +16 -0
  32. data/lib/rmodel/version.rb +1 -1
  33. data/rmodel.gemspec +9 -3
  34. data/spec/rmodel/array_mapper_spec.rb +43 -0
  35. data/spec/rmodel/mongo/mapper_spec.rb +154 -0
  36. data/spec/rmodel/mongo/repository_spec.rb +16 -37
  37. data/spec/rmodel/mongo/source_spec.rb +113 -0
  38. data/spec/rmodel/sequel/mapper_spec.rb +57 -0
  39. data/spec/rmodel/sequel/repository_spec.rb +27 -38
  40. data/spec/rmodel/sequel/source_spec.rb +121 -0
  41. data/spec/shared/base_mapper.rb +39 -0
  42. data/spec/shared/clean_moped.rb +6 -2
  43. data/spec/shared/clean_sequel.rb +1 -1
  44. data/spec/shared/{repository_ext → repository}/crud.rb +20 -14
  45. data/spec/shared/repository/initialization.rb +39 -0
  46. data/spec/shared/repository/scopable.rb +137 -0
  47. data/spec/shared/repository/sugarable.rb +67 -0
  48. data/spec/shared/repository/timestampable.rb +137 -0
  49. data/spec/spec_helper.rb +17 -18
  50. metadata +120 -54
  51. data/examples/advanced_creation_of_repository.rb +0 -15
  52. data/examples/user.rb +0 -48
  53. data/lib/rmodel/base/repository.rb +0 -12
  54. data/lib/rmodel/base/repository_ext/sugarable.rb +0 -17
  55. data/lib/rmodel/base/repository_ext/timestampable.rb +0 -19
  56. data/lib/rmodel/mongo/repository.rb +0 -62
  57. data/lib/rmodel/mongo/repository_ext/query.rb +0 -34
  58. data/lib/rmodel/mongo/repository_ext/queryable.rb +0 -34
  59. data/lib/rmodel/mongo/setup.rb +0 -17
  60. data/lib/rmodel/mongo/simple_factory.rb +0 -78
  61. data/lib/rmodel/sequel/repository.rb +0 -61
  62. data/lib/rmodel/sequel/repository_ext/query.rb +0 -34
  63. data/lib/rmodel/sequel/repository_ext/queryable.rb +0 -30
  64. data/lib/rmodel/sequel/setup.rb +0 -12
  65. data/lib/rmodel/sequel/simple_factory.rb +0 -28
  66. data/lib/rmodel/setup.rb +0 -34
  67. data/spec/rmodel/mongo/repository_ext/queryable_spec.rb +0 -103
  68. data/spec/rmodel/mongo/repository_initialize_spec.rb +0 -174
  69. data/spec/rmodel/mongo/simple_factory_spec.rb +0 -195
  70. data/spec/rmodel/sequel/repository_ext/queryable_spec.rb +0 -114
  71. data/spec/rmodel/sequel/repository_initialize_spec.rb +0 -118
  72. data/spec/rmodel/sequel/simple_factory_spec.rb +0 -55
  73. data/spec/rmodel/setup_spec.rb +0 -54
  74. data/spec/shared/repository_ext/sugarable.rb +0 -44
  75. data/spec/shared/repository_ext/timestampable.rb +0 -67
data/spec/spec_helper.rb CHANGED
@@ -44,57 +44,56 @@ RSpec.configure do |config|
44
44
  mocks.verify_partial_doubles = true
45
45
  end
46
46
 
47
- # The settings below are suggested to provide a good initial experience
48
- # with RSpec, but feel free to customize to your heart's content.
49
- =begin
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+
50
50
  # These two settings work together to allow you to limit a spec run
51
51
  # to individual examples or groups you care about by tagging them with
52
52
  # `:focus` metadata. When nothing is tagged with `:focus`, all examples
53
53
  # get run.
54
- config.filter_run :focus
55
- config.run_all_when_everything_filtered = true
54
+ # config.filter_run :focus
55
+ # config.run_all_when_everything_filtered = true
56
56
 
57
57
  # Allows RSpec to persist some state between runs in order to support
58
58
  # the `--only-failures` and `--next-failure` CLI options. We recommend
59
59
  # you configure your source control system to ignore this file.
60
- config.example_status_persistence_file_path = "spec/examples.txt"
60
+ # config.example_status_persistence_file_path = "spec/examples.txt"
61
61
 
62
62
  # Limits the available syntax to the non-monkey patched syntax that is
63
63
  # recommended. For more details, see:
64
64
  # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
65
65
  # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
66
  # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
67
- config.disable_monkey_patching!
67
+ # config.disable_monkey_patching!
68
68
 
69
69
  # This setting enables warnings. It's recommended, but in some cases may
70
70
  # be too noisy due to issues in dependencies.
71
- config.warnings = true
71
+ # config.warnings = true
72
72
 
73
73
  # Many RSpec users commonly either run the entire suite or an individual
74
74
  # file, and it's useful to allow more verbose output when running an
75
75
  # individual spec file.
76
- if config.files_to_run.one?
77
- # Use the documentation formatter for detailed output,
78
- # unless a formatter has already been configured
79
- # (e.g. via a command-line flag).
80
- config.default_formatter = 'doc'
81
- end
76
+ # if config.files_to_run.one?
77
+ # # Use the documentation formatter for detailed output,
78
+ # # unless a formatter has already been configured
79
+ # # (e.g. via a command-line flag).
80
+ # config.default_formatter = 'doc'
81
+ # end
82
82
 
83
83
  # Print the 10 slowest examples and example groups at the
84
84
  # end of the spec run, to help surface which specs are running
85
85
  # particularly slow.
86
- config.profile_examples = 10
86
+ # config.profile_examples = 10
87
87
 
88
88
  # Run specs in random order to surface order dependencies. If you find an
89
89
  # order dependency and want to debug it, you can fix the order by providing
90
90
  # the seed, which is printed after each run.
91
91
  # --seed 1234
92
- config.order = :random
92
+ # config.order = :random
93
93
 
94
94
  # Seed global randomization in this process using the `--seed` CLI option.
95
95
  # Setting this allows you to use `--seed` to deterministically reproduce
96
96
  # test failures related to randomization by passing the same `--seed` value
97
97
  # as the one that triggered the failure.
98
- Kernel.srand config.seed
99
- =end
98
+ # Kernel.srand config.seed
100
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.dev
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-29 00:00:00.000000000 Z
11
+ date: 2016-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activesupport
28
+ name: origin
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: origin
42
+ name: sequel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,13 +53,27 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: sequel
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '0'
62
- type: :runtime
76
+ type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
@@ -67,21 +81,21 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: bundler
84
+ name: rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - "~>"
87
+ - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '1.6'
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - "~>"
94
+ - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '1.6'
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: rake
98
+ name: sqlite3
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - ">="
@@ -95,7 +109,7 @@ dependencies:
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
- name: rspec
112
+ name: rubocop
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
@@ -109,7 +123,7 @@ dependencies:
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
- name: sqlite3
126
+ name: activesupport
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - ">="
@@ -122,7 +136,51 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
125
- description: Rmodel is an ORM library, which tends to follow the SOLID principles.
139
+ - !ruby/object:Gem::Dependency
140
+ name: sinatra
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: activemodel
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: lazy_injector
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: |-
182
+ Rmodel is an ORM library, which tends to follow the
183
+ SOLID principles.
126
184
  email:
127
185
  - alexei.lexx@gmail.com
128
186
  executables: []
@@ -131,48 +189,55 @@ extra_rdoc_files: []
131
189
  files:
132
190
  - ".gitignore"
133
191
  - ".rspec"
192
+ - ".rubocop.yml"
134
193
  - ".travis.yml"
135
194
  - Gemfile
136
195
  - LICENSE.txt
137
196
  - README.md
138
197
  - Rakefile
139
- - examples/advanced_creation_of_repository.rb
140
198
  - examples/mongo_embedded.rb
199
+ - examples/scopes.rb
141
200
  - examples/sql_repository.rb
142
201
  - examples/timestamps.rb
143
- - examples/user.rb
202
+ - examples/webapp/models/task.rb
203
+ - examples/webapp/repositories/task_repository.rb
204
+ - examples/webapp/server.rb
205
+ - examples/webapp/support/mappers.rb
206
+ - examples/webapp/support/repositories.rb
207
+ - examples/webapp/support/sources.rb
208
+ - examples/webapp/views/index.erb
144
209
  - lib/rmodel.rb
145
- - lib/rmodel/base/repository.rb
146
- - lib/rmodel/base/repository_ext/sugarable.rb
147
- - lib/rmodel/base/repository_ext/timestampable.rb
210
+ - lib/rmodel/array_mapper.rb
211
+ - lib/rmodel/base_mapper.rb
212
+ - lib/rmodel/dummy_mapper.rb
148
213
  - lib/rmodel/errors.rb
149
- - lib/rmodel/mongo/repository.rb
150
- - lib/rmodel/mongo/repository_ext/query.rb
151
- - lib/rmodel/mongo/repository_ext/queryable.rb
152
- - lib/rmodel/mongo/setup.rb
153
- - lib/rmodel/mongo/simple_factory.rb
154
- - lib/rmodel/sequel/repository.rb
155
- - lib/rmodel/sequel/repository_ext/query.rb
156
- - lib/rmodel/sequel/repository_ext/queryable.rb
157
- - lib/rmodel/sequel/setup.rb
158
- - lib/rmodel/sequel/simple_factory.rb
159
- - lib/rmodel/setup.rb
214
+ - lib/rmodel/mongo/mapper.rb
215
+ - lib/rmodel/mongo/source.rb
216
+ - lib/rmodel/repository.rb
217
+ - lib/rmodel/repository_ext/scopable.rb
218
+ - lib/rmodel/repository_ext/sugarable.rb
219
+ - lib/rmodel/repository_ext/timestampable.rb
220
+ - lib/rmodel/scope.rb
221
+ - lib/rmodel/sequel/mapper.rb
222
+ - lib/rmodel/sequel/source.rb
223
+ - lib/rmodel/uni_hash.rb
160
224
  - lib/rmodel/version.rb
161
225
  - rmodel.gemspec
162
- - spec/rmodel/mongo/repository_ext/queryable_spec.rb
163
- - spec/rmodel/mongo/repository_initialize_spec.rb
226
+ - spec/rmodel/array_mapper_spec.rb
227
+ - spec/rmodel/mongo/mapper_spec.rb
164
228
  - spec/rmodel/mongo/repository_spec.rb
165
- - spec/rmodel/mongo/simple_factory_spec.rb
166
- - spec/rmodel/sequel/repository_ext/queryable_spec.rb
167
- - spec/rmodel/sequel/repository_initialize_spec.rb
229
+ - spec/rmodel/mongo/source_spec.rb
230
+ - spec/rmodel/sequel/mapper_spec.rb
168
231
  - spec/rmodel/sequel/repository_spec.rb
169
- - spec/rmodel/sequel/simple_factory_spec.rb
170
- - spec/rmodel/setup_spec.rb
232
+ - spec/rmodel/sequel/source_spec.rb
233
+ - spec/shared/base_mapper.rb
171
234
  - spec/shared/clean_moped.rb
172
235
  - spec/shared/clean_sequel.rb
173
- - spec/shared/repository_ext/crud.rb
174
- - spec/shared/repository_ext/sugarable.rb
175
- - spec/shared/repository_ext/timestampable.rb
236
+ - spec/shared/repository/crud.rb
237
+ - spec/shared/repository/initialization.rb
238
+ - spec/shared/repository/scopable.rb
239
+ - spec/shared/repository/sugarable.rb
240
+ - spec/shared/repository/timestampable.rb
176
241
  - spec/spec_helper.rb
177
242
  homepage: https://github.com/alexei-lexx/rmodel
178
243
  licenses:
@@ -189,28 +254,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
254
  version: 2.0.0
190
255
  required_rubygems_version: !ruby/object:Gem::Requirement
191
256
  requirements:
192
- - - ">"
257
+ - - ">="
193
258
  - !ruby/object:Gem::Version
194
- version: 1.3.1
259
+ version: '0'
195
260
  requirements: []
196
261
  rubyforge_project:
197
- rubygems_version: 2.4.5
262
+ rubygems_version: 2.4.8
198
263
  signing_key:
199
264
  specification_version: 4
200
265
  summary: Rmodel is an ORM library, which tends to follow the SOLID principles.
201
266
  test_files:
202
- - spec/rmodel/mongo/repository_ext/queryable_spec.rb
203
- - spec/rmodel/mongo/repository_initialize_spec.rb
267
+ - spec/rmodel/array_mapper_spec.rb
268
+ - spec/rmodel/mongo/mapper_spec.rb
204
269
  - spec/rmodel/mongo/repository_spec.rb
205
- - spec/rmodel/mongo/simple_factory_spec.rb
206
- - spec/rmodel/sequel/repository_ext/queryable_spec.rb
207
- - spec/rmodel/sequel/repository_initialize_spec.rb
270
+ - spec/rmodel/mongo/source_spec.rb
271
+ - spec/rmodel/sequel/mapper_spec.rb
208
272
  - spec/rmodel/sequel/repository_spec.rb
209
- - spec/rmodel/sequel/simple_factory_spec.rb
210
- - spec/rmodel/setup_spec.rb
273
+ - spec/rmodel/sequel/source_spec.rb
274
+ - spec/shared/base_mapper.rb
211
275
  - spec/shared/clean_moped.rb
212
276
  - spec/shared/clean_sequel.rb
213
- - spec/shared/repository_ext/crud.rb
214
- - spec/shared/repository_ext/sugarable.rb
215
- - spec/shared/repository_ext/timestampable.rb
277
+ - spec/shared/repository/crud.rb
278
+ - spec/shared/repository/initialization.rb
279
+ - spec/shared/repository/scopable.rb
280
+ - spec/shared/repository/sugarable.rb
281
+ - spec/shared/repository/timestampable.rb
216
282
  - spec/spec_helper.rb
@@ -1,15 +0,0 @@
1
- require 'rmodel'
2
-
3
- class Thing
4
- attr_accessor :id, :name
5
- end
6
-
7
- class ThingRepository < Rmodel::Mongo::Repository
8
- end
9
-
10
- client = Mongo::Client.new([ 'localhost:27017' ], database: 'test')
11
- collection = :things
12
- factory = Rmodel::Mongo::SimpleFactory.new(Thing, :name)
13
-
14
- repo = ThingRepository.new(client, collection, factory)
15
- p repo.find(1)
data/examples/user.rb DELETED
@@ -1,48 +0,0 @@
1
- require 'rmodel'
2
-
3
- Rmodel.setup do
4
- client :default, { hosts: [ 'localhost' ], database: 'test' }
5
- end
6
-
7
- class User
8
- attr_accessor :id, :name, :email
9
-
10
- def initialize(name = nil, email = nil)
11
- self.name = name
12
- self.email = email
13
- end
14
- end
15
-
16
- class UserRepository < Rmodel::Mongo::Repository
17
- simple_factory User, :name, :email
18
-
19
- scope :have_email do
20
- where(email: { '$exists' => true })
21
- end
22
-
23
- scope :start_with do |letter|
24
- where(name: { '$regex' => "^#{letter}", '$options' => 'i' })
25
- end
26
- end
27
-
28
- userRepository = UserRepository.new
29
- userRepository.query.remove
30
-
31
- john = User.new('John', 'john@example.com')
32
- bill = User.new('Bill', 'bill@example.com')
33
- bob = User.new('Bob', 'bob@example.com')
34
-
35
- userRepository.insert(john)
36
- userRepository.insert(bill)
37
- userRepository.insert(bob)
38
-
39
- john.name = 'John Smith'
40
- userRepository.update(john)
41
-
42
- userRepository.remove(bob)
43
-
44
- p userRepository.find(john.id)
45
- p userRepository.find(bob.id)
46
-
47
- userRepository.query.have_email.remove
48
- p userRepository.query.count
@@ -1,12 +0,0 @@
1
- require 'rmodel/base/repository_ext/sugarable'
2
- require 'rmodel/base/repository_ext/timestampable'
3
-
4
- module Rmodel::Base
5
- class Repository
6
- include RepositoryExt::Sugarable
7
-
8
- def self.inherited(subclass)
9
- subclass.send :prepend, RepositoryExt::Timestampable
10
- end
11
- end
12
- end
@@ -1,17 +0,0 @@
1
- module Rmodel::Base
2
- module RepositoryExt
3
- module Sugarable
4
- def find!(id)
5
- find(id) or raise Rmodel::NotFound.new(self, { id: id })
6
- end
7
-
8
- def save(object)
9
- if object.id.nil?
10
- insert(object)
11
- else
12
- update(object)
13
- end
14
- end
15
- end
16
- end
17
- end