embedson 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +83 -0
- data/Rakefile +2 -0
- data/embedson.gemspec +29 -0
- data/lib/embedson/model.rb +79 -0
- data/lib/embedson/version.rb +3 -0
- data/lib/embedson.rb +2 -0
- data/spec/embedson/model_spec.rb +248 -0
- data/spec/spec_helper.rb +68 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9b52da8a4596e89eaa71d2a1f109988c9157cc51
|
4
|
+
data.tar.gz: adf12afbc8c12ca1c1b751def0865010217fa421
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9463f20a91ef4449246cda718aa4e1a2671d1b7fe6a37d2f92836392e6f76b3caa84b0042482b5e400c653caa7deb6969c3335b3016b17f7e5339946283a5a1b
|
7
|
+
data.tar.gz: e0346bfea5cd34fc28bd695b96ab5160421a65f3c42cf7e8aac19fd0fcdf42e81fe8fb78aeb68cdd4333ae28990b60dc1de2d3c551ae9d68f737cccfe3a39349
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 sufleR
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# Embedson
|
2
|
+
|
3
|
+
Adds functionality of `embedded_one` and `embedded_in`.
|
4
|
+
|
5
|
+
Embeded class is saved in json column.
|
6
|
+
|
7
|
+
Embedded class have to provide `to_h` method which should return data to store in database.
|
8
|
+
|
9
|
+
####TODO
|
10
|
+
|
11
|
+
1. More tests
|
12
|
+
2. Code refactoring to clean up `embedded_in` and `embeds_one` from define methods
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
gem 'embedson'
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install embedson
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Example with [Virtus](https://github.com/solnic/virtus):
|
31
|
+
|
32
|
+
```RUBY
|
33
|
+
|
34
|
+
#create_tests.rb - migration
|
35
|
+
class CreateTests < ActiveRecord::Migration
|
36
|
+
def change
|
37
|
+
create_table :tests do |t|
|
38
|
+
t.json :data
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Test < ActiveRecord::Base
|
44
|
+
extend Embedson::Model
|
45
|
+
|
46
|
+
embeds_one :virt, column_name: :data, inverse_of: :parent
|
47
|
+
end
|
48
|
+
|
49
|
+
class Virt
|
50
|
+
include Virtus.model
|
51
|
+
extend Embedson::Model
|
52
|
+
|
53
|
+
attribute :name, String
|
54
|
+
attribute :address, Hash
|
55
|
+
|
56
|
+
embedded_in :parent, class_name: Test
|
57
|
+
end
|
58
|
+
|
59
|
+
virt = Virt.new(name: 'Sample', address: { street: 'Kind', number: '33' })
|
60
|
+
virt.attributes # => {:name=>"Sample", :address=>{:street=>"Kind", :number=>"33"}}
|
61
|
+
|
62
|
+
test = Test.create!
|
63
|
+
test.attributes # => {"id"=>1, "data"=>nil
|
64
|
+
|
65
|
+
test.virt = virt
|
66
|
+
test.save
|
67
|
+
test.attributes # => {"id"=>1, "data"=>{"name"=>"Sample", "address"=>{"street"=>"Kind", "number"=>"33"}
|
68
|
+
|
69
|
+
test.reload.virt.attributes # => {:name=>"Sample", :address=>{:street=>"Kind", :number=>"33"}, :children=>[]}
|
70
|
+
test.virt == virt # => true
|
71
|
+
test.virt.parent == test # => true
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
1. Fork it ( https://github.com/[my-github-username]/embedson/fork )
|
79
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
80
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
81
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
82
|
+
5. Create a new Pull Request
|
83
|
+
|
data/Rakefile
ADDED
data/embedson.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'embedson/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "embedson"
|
8
|
+
spec.version = Embedson::VERSION
|
9
|
+
spec.authors = ["sufleR"]
|
10
|
+
spec.email = ["szymon.fracczak@netguru.co"]
|
11
|
+
spec.summary = %q{Embedded model for AR with postgresql}
|
12
|
+
spec.description = %q{Save any class which respond to to_h in json column as embedded model.}
|
13
|
+
spec.homepage = "https://github.com/sufleR/embedson"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activerecord"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "pg"
|
26
|
+
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "with_model"
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Embedson::Model
|
2
|
+
|
3
|
+
def embeds_one(name, options = {})
|
4
|
+
column_name = options.fetch(:column_name, nil) || name
|
5
|
+
klass_name = (options.fetch(:class_name, nil) || name).to_s.classify
|
6
|
+
inverse_get = options.fetch(:inverse_of, nil) || self.name.downcase
|
7
|
+
inverse_set = "#{inverse_get}="
|
8
|
+
|
9
|
+
define_method("#{name}=") do |arg|
|
10
|
+
raise TypeError, "wrong argument type #{arg.class.name} (expected #{klass_name})" unless arg.nil? || arg.is_a?(klass_name.constantize)
|
11
|
+
|
12
|
+
if arg.respond_to?(inverse_set) && arg.public_send(inverse_get) != self
|
13
|
+
arg.public_send(inverse_set, self)
|
14
|
+
end
|
15
|
+
|
16
|
+
instance_variable_set("@#{name}", arg)
|
17
|
+
write_attribute(column_name, arg.nil? ? arg : arg.to_h)
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method(name) do
|
21
|
+
return if read_attribute(column_name).nil?
|
22
|
+
|
23
|
+
if instance_variable_get("@#{name}").nil?
|
24
|
+
model = klass_name.constantize.new(read_attribute(column_name))
|
25
|
+
instance_variable_set("@#{name}", model)
|
26
|
+
model.public_send(inverse_set, self) if model.respond_to?(inverse_set)
|
27
|
+
end
|
28
|
+
instance_variable_get("@#{name}")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def embedded_in(name, options = {})
|
33
|
+
klass_name = (options.fetch(:class_name, nil) || name).to_s.classify
|
34
|
+
inverse_get = options.fetch(:inverse_of, nil) || self.name.demodulize.tableize.singularize
|
35
|
+
inverse_set = "#{inverse_get}="
|
36
|
+
|
37
|
+
|
38
|
+
define_method(name) do
|
39
|
+
instance_variable_get("@#{name}")
|
40
|
+
end
|
41
|
+
|
42
|
+
define_method("#{name}=") do |arg|
|
43
|
+
raise TypeError, "wrong argument type #{arg.class.name} (expected #{klass_name})" unless arg.nil? || arg.is_a?(klass_name.constantize)
|
44
|
+
|
45
|
+
instance_variable_set("@#{name}", arg)
|
46
|
+
parent = public_send(name)
|
47
|
+
|
48
|
+
if parent.respond_to?(inverse_set) && parent.public_send(inverse_get) != self
|
49
|
+
parent.public_send(inverse_set, self)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
define_method('destroy') do
|
54
|
+
parent = public_send(name)
|
55
|
+
return false unless parent.present?
|
56
|
+
parent.public_send(inverse_set, nil)
|
57
|
+
parent.save!
|
58
|
+
end
|
59
|
+
|
60
|
+
define_method('save') do
|
61
|
+
parent = public_send(name)
|
62
|
+
return false unless parent.present?
|
63
|
+
parent.save
|
64
|
+
end
|
65
|
+
|
66
|
+
define_method('save!') do
|
67
|
+
parent = public_send(name)
|
68
|
+
raise "No parent model defined!" unless parent.present?
|
69
|
+
parent.save!
|
70
|
+
end
|
71
|
+
|
72
|
+
define_method('embedson_model_changed!') do
|
73
|
+
parent = public_send(name)
|
74
|
+
raise "No parent model defined!" unless parent.present?
|
75
|
+
parent.public_send(inverse_set, self)
|
76
|
+
true
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/embedson.rb
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Embedson::Model do
|
4
|
+
|
5
|
+
describe '#emdbeds_one' do
|
6
|
+
context 'when only relation name is specified' do
|
7
|
+
|
8
|
+
with_model :Parent do
|
9
|
+
table do |t|
|
10
|
+
t.json :embedded
|
11
|
+
end
|
12
|
+
|
13
|
+
model do
|
14
|
+
extend Embedson::Model
|
15
|
+
|
16
|
+
embeds_one :embedded
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Embedded < OpenStruct
|
21
|
+
|
22
|
+
def to_h
|
23
|
+
{ defined: 'in', embedded: true }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:parent) { Parent.new() }
|
28
|
+
let(:embedded) { Embedded.new() }
|
29
|
+
|
30
|
+
it 'adds "embeds_one" method' do
|
31
|
+
expect(Parent).to respond_to(:embeds_one)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'adds "embedded" method' do
|
35
|
+
expect(Parent.new()).to respond_to(:embedded)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'adds "embedded=" method' do
|
39
|
+
expect(Parent.new()).to respond_to("embedded=")
|
40
|
+
end
|
41
|
+
|
42
|
+
describe 'defined .embedded= method' do
|
43
|
+
it 'assigns value of embedded class' do
|
44
|
+
expect {
|
45
|
+
parent.embedded = embedded
|
46
|
+
}.to change{ parent.embedded }.from(nil).to(embedded)
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when assigning nil' do
|
50
|
+
let(:parent) { Parent.new(embedded: embedded) }
|
51
|
+
|
52
|
+
it 'removes assignmnent' do
|
53
|
+
parent
|
54
|
+
expect {
|
55
|
+
parent.embedded = nil
|
56
|
+
}.to change { parent.embedded }.from(embedded).to(nil)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when assigning wrong class' do
|
61
|
+
it 'raises TypeError' do
|
62
|
+
expect{
|
63
|
+
parent.embedded = 'something'
|
64
|
+
}.to raise_error(TypeError)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when Parent is persisted' do
|
69
|
+
before do
|
70
|
+
parent.save!
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'marks parent as changed' do
|
74
|
+
expect {
|
75
|
+
parent.embedded = embedded
|
76
|
+
}.to change{ parent.changed? }.from(false).to(true)
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'and saved after change' do
|
80
|
+
it 'saves Embedded class to json column' do
|
81
|
+
expect{
|
82
|
+
parent.embedded = embedded
|
83
|
+
parent.save!
|
84
|
+
}.to change { parent.reload.read_attribute(:embedded) }.from(nil).to(embedded.to_h.stringify_keys)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe 'defined embedded method' do
|
91
|
+
context 'when value column is null' do
|
92
|
+
it 'returns nil' do
|
93
|
+
expect(parent.embedded).to be nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns embedded class' do
|
98
|
+
parent.embedded = embedded
|
99
|
+
expect(parent.embedded).to be_a Embedded
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'when there is defined value in column' do
|
103
|
+
before do
|
104
|
+
parent.embedded = embedded
|
105
|
+
parent.save!
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'returns embedded class initialized with value from column' do
|
109
|
+
expect(parent.reload.embedded).to eq embedded
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context 'when options include column_name' do
|
116
|
+
|
117
|
+
with_model :Parent do
|
118
|
+
table do |t|
|
119
|
+
t.json :data
|
120
|
+
end
|
121
|
+
|
122
|
+
model do
|
123
|
+
extend Embedson::Model
|
124
|
+
|
125
|
+
embeds_one :embedded, column_name: :data
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
class Embedded < OpenStruct
|
130
|
+
|
131
|
+
def to_h
|
132
|
+
{ defined: 'in', embedded: true }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
let(:parent) { Parent.new() }
|
137
|
+
let(:embedded) { Embedded.new() }
|
138
|
+
|
139
|
+
it 'adds "embeds_one" method' do
|
140
|
+
expect(Parent).to respond_to(:embeds_one)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'adds "embedded" method' do
|
144
|
+
expect(Parent.new()).to respond_to(:embedded)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'adds "embedded=" method' do
|
148
|
+
expect(Parent.new()).to respond_to("embedded=")
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'saves embedded class to data column' do
|
152
|
+
expect {
|
153
|
+
parent.embedded = embedded
|
154
|
+
parent.save!
|
155
|
+
}.to change{ parent.read_attribute(:data) }.from(nil).to(embedded.to_h.stringify_keys)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
context 'when options include inverse_of' do
|
160
|
+
|
161
|
+
with_model :Parent do
|
162
|
+
table do |t|
|
163
|
+
t.json :embedded
|
164
|
+
end
|
165
|
+
|
166
|
+
model do
|
167
|
+
extend Embedson::Model
|
168
|
+
|
169
|
+
embeds_one :embedded, inverse_of: :parent_m
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
class Embedded < OpenStruct
|
174
|
+
extend Embedson::Model
|
175
|
+
|
176
|
+
embedded_in :parent_m, class_name: 'Parent'
|
177
|
+
|
178
|
+
def to_h
|
179
|
+
{ defined: 'in', embedded: true }
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
let(:parent) { Parent.new() }
|
184
|
+
let(:embedded) { Embedded.new() }
|
185
|
+
|
186
|
+
it 'adds "embeds_one" method' do
|
187
|
+
expect(Parent).to respond_to(:embeds_one)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'adds "embedded" method' do
|
191
|
+
expect(Parent.new()).to respond_to(:embedded)
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'adds "embedded=" method' do
|
195
|
+
expect(Parent.new()).to respond_to("embedded=")
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'assigns self to parent_m in embedded class' do
|
199
|
+
parent.embedded = embedded
|
200
|
+
expect(parent.embedded.parent_m).to eq parent
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context 'when options include class_name' do
|
205
|
+
|
206
|
+
with_model :Parent do
|
207
|
+
table do |t|
|
208
|
+
t.json :embedded
|
209
|
+
end
|
210
|
+
|
211
|
+
model do
|
212
|
+
extend Embedson::Model
|
213
|
+
|
214
|
+
embeds_one :emb, class_name: 'Embedded', column_name: :embedded
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
class Embedded < OpenStruct
|
219
|
+
extend Embedson::Model
|
220
|
+
|
221
|
+
embedded_in :parent
|
222
|
+
|
223
|
+
def to_h
|
224
|
+
{ defined: 'in', embedded: true }
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
let(:parent) { Parent.new(embedded: { some: 'thing' }) }
|
229
|
+
let(:embedded) { Embedded.new() }
|
230
|
+
|
231
|
+
it 'adds "embeds_one" method' do
|
232
|
+
expect(Parent).to respond_to(:embeds_one)
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'adds "emb" method' do
|
236
|
+
expect(Parent.new()).to respond_to(:emb)
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'adds "emb=" method' do
|
240
|
+
expect(Parent.new()).to respond_to("emb=")
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'assigns self to parent_m in embedded class' do
|
244
|
+
expect(parent.emb.some).to eq 'thing'
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'embedson'
|
2
|
+
require 'with_model'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.extend WithModel
|
8
|
+
|
9
|
+
config.expect_with :rspec do |expectations|
|
10
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
11
|
+
end
|
12
|
+
|
13
|
+
config.mock_with :rspec do |mocks|
|
14
|
+
mocks.verify_partial_doubles = true
|
15
|
+
end
|
16
|
+
|
17
|
+
ActiveRecord::Base.establish_connection(
|
18
|
+
"postgres://embedson:embedson@localhost/embedson"
|
19
|
+
)
|
20
|
+
# The settings below are suggested to provide a good initial experience
|
21
|
+
# with RSpec, but feel free to customize to your heart's content.
|
22
|
+
=begin
|
23
|
+
# These two settings work together to allow you to limit a spec run
|
24
|
+
# to individual examples or groups you care about by tagging them with
|
25
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
26
|
+
# get run.
|
27
|
+
config.filter_run :focus
|
28
|
+
config.run_all_when_everything_filtered = true
|
29
|
+
|
30
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
31
|
+
# For more details, see:
|
32
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
33
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
34
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
35
|
+
config.disable_monkey_patching!
|
36
|
+
|
37
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
38
|
+
# be too noisy due to issues in dependencies.
|
39
|
+
config.warnings = true
|
40
|
+
|
41
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
42
|
+
# file, and it's useful to allow more verbose output when running an
|
43
|
+
# individual spec file.
|
44
|
+
if config.files_to_run.one?
|
45
|
+
# Use the documentation formatter for detailed output,
|
46
|
+
# unless a formatter has already been configured
|
47
|
+
# (e.g. via a command-line flag).
|
48
|
+
config.default_formatter = 'doc'
|
49
|
+
end
|
50
|
+
|
51
|
+
# Print the 10 slowest examples and example groups at the
|
52
|
+
# end of the spec run, to help surface which specs are running
|
53
|
+
# particularly slow.
|
54
|
+
config.profile_examples = 10
|
55
|
+
|
56
|
+
# Run specs in random order to surface order dependencies. If you find an
|
57
|
+
# order dependency and want to debug it, you can fix the order by providing
|
58
|
+
# the seed, which is printed after each run.
|
59
|
+
# --seed 1234
|
60
|
+
config.order = :random
|
61
|
+
|
62
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
63
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
64
|
+
# test failures related to randomization by passing the same `--seed` value
|
65
|
+
# as the one that triggered the failure.
|
66
|
+
Kernel.srand config.seed
|
67
|
+
=end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embedson
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- sufleR
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pg
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: with_model
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Save any class which respond to to_h in json column as embedded model.
|
112
|
+
email:
|
113
|
+
- szymon.fracczak@netguru.co
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- embedson.gemspec
|
124
|
+
- lib/embedson.rb
|
125
|
+
- lib/embedson/model.rb
|
126
|
+
- lib/embedson/version.rb
|
127
|
+
- spec/embedson/model_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
homepage: https://github.com/sufleR/embedson
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.2.2
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Embedded model for AR with postgresql
|
153
|
+
test_files:
|
154
|
+
- spec/embedson/model_spec.rb
|
155
|
+
- spec/spec_helper.rb
|