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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +4 -3
- data/README.md +119 -153
- data/Rakefile +1 -2
- data/examples/mongo_embedded.rb +27 -21
- data/examples/scopes.rb +28 -0
- data/examples/sql_repository.rb +14 -26
- data/examples/timestamps.rb +7 -10
- data/examples/webapp/models/task.rb +9 -0
- data/examples/webapp/repositories/task_repository.rb +14 -0
- data/examples/webapp/server.rb +25 -0
- data/examples/webapp/support/mappers.rb +11 -0
- data/examples/webapp/support/repositories.rb +12 -0
- data/examples/webapp/support/sources.rb +13 -0
- data/examples/webapp/views/index.erb +20 -0
- data/lib/rmodel.rb +11 -8
- data/lib/rmodel/array_mapper.rb +23 -0
- data/lib/rmodel/base_mapper.rb +56 -0
- data/lib/rmodel/dummy_mapper.rb +15 -0
- data/lib/rmodel/mongo/mapper.rb +11 -0
- data/lib/rmodel/mongo/source.rb +50 -0
- data/lib/rmodel/repository.rb +36 -0
- data/lib/rmodel/repository_ext/scopable.rb +44 -0
- data/lib/rmodel/repository_ext/sugarable.rb +35 -0
- data/lib/rmodel/repository_ext/timestampable.rb +29 -0
- data/lib/rmodel/scope.rb +31 -0
- data/lib/rmodel/sequel/mapper.rb +6 -0
- data/lib/rmodel/sequel/source.rb +43 -0
- data/lib/rmodel/uni_hash.rb +16 -0
- data/lib/rmodel/version.rb +1 -1
- data/rmodel.gemspec +9 -3
- data/spec/rmodel/array_mapper_spec.rb +43 -0
- data/spec/rmodel/mongo/mapper_spec.rb +154 -0
- data/spec/rmodel/mongo/repository_spec.rb +16 -37
- data/spec/rmodel/mongo/source_spec.rb +113 -0
- data/spec/rmodel/sequel/mapper_spec.rb +57 -0
- data/spec/rmodel/sequel/repository_spec.rb +27 -38
- data/spec/rmodel/sequel/source_spec.rb +121 -0
- data/spec/shared/base_mapper.rb +39 -0
- data/spec/shared/clean_moped.rb +6 -2
- data/spec/shared/clean_sequel.rb +1 -1
- data/spec/shared/{repository_ext → repository}/crud.rb +20 -14
- data/spec/shared/repository/initialization.rb +39 -0
- data/spec/shared/repository/scopable.rb +137 -0
- data/spec/shared/repository/sugarable.rb +67 -0
- data/spec/shared/repository/timestampable.rb +137 -0
- data/spec/spec_helper.rb +17 -18
- metadata +120 -54
- data/examples/advanced_creation_of_repository.rb +0 -15
- data/examples/user.rb +0 -48
- data/lib/rmodel/base/repository.rb +0 -12
- data/lib/rmodel/base/repository_ext/sugarable.rb +0 -17
- data/lib/rmodel/base/repository_ext/timestampable.rb +0 -19
- data/lib/rmodel/mongo/repository.rb +0 -62
- data/lib/rmodel/mongo/repository_ext/query.rb +0 -34
- data/lib/rmodel/mongo/repository_ext/queryable.rb +0 -34
- data/lib/rmodel/mongo/setup.rb +0 -17
- data/lib/rmodel/mongo/simple_factory.rb +0 -78
- data/lib/rmodel/sequel/repository.rb +0 -61
- data/lib/rmodel/sequel/repository_ext/query.rb +0 -34
- data/lib/rmodel/sequel/repository_ext/queryable.rb +0 -30
- data/lib/rmodel/sequel/setup.rb +0 -12
- data/lib/rmodel/sequel/simple_factory.rb +0 -28
- data/lib/rmodel/setup.rb +0 -34
- data/spec/rmodel/mongo/repository_ext/queryable_spec.rb +0 -103
- data/spec/rmodel/mongo/repository_initialize_spec.rb +0 -174
- data/spec/rmodel/mongo/simple_factory_spec.rb +0 -195
- data/spec/rmodel/sequel/repository_ext/queryable_spec.rb +0 -114
- data/spec/rmodel/sequel/repository_initialize_spec.rb +0 -118
- data/spec/rmodel/sequel/simple_factory_spec.rb +0 -55
- data/spec/rmodel/setup_spec.rb +0 -54
- data/spec/shared/repository_ext/sugarable.rb +0 -44
- 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
|
-
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
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
|
+
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:
|
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:
|
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:
|
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:
|
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: :
|
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:
|
84
|
+
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
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: '
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
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:
|
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:
|
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
|
-
|
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/
|
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/
|
146
|
-
- lib/rmodel/
|
147
|
-
- lib/rmodel/
|
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/
|
150
|
-
- lib/rmodel/mongo/
|
151
|
-
- lib/rmodel/
|
152
|
-
- lib/rmodel/
|
153
|
-
- lib/rmodel/
|
154
|
-
- lib/rmodel/
|
155
|
-
- lib/rmodel/
|
156
|
-
- lib/rmodel/sequel/
|
157
|
-
- lib/rmodel/sequel/
|
158
|
-
- lib/rmodel/
|
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/
|
163
|
-
- spec/rmodel/mongo/
|
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/
|
166
|
-
- spec/rmodel/sequel/
|
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/
|
170
|
-
- spec/
|
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/
|
174
|
-
- spec/shared/
|
175
|
-
- spec/shared/
|
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:
|
259
|
+
version: '0'
|
195
260
|
requirements: []
|
196
261
|
rubyforge_project:
|
197
|
-
rubygems_version: 2.4.
|
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/
|
203
|
-
- spec/rmodel/mongo/
|
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/
|
206
|
-
- spec/rmodel/sequel/
|
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/
|
210
|
-
- spec/
|
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/
|
214
|
-
- spec/shared/
|
215
|
-
- spec/shared/
|
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
|