bsm-models 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bsm/model/coders/json_column.rb +1 -1
- data/lib/bsm/model/has_many_serialized.rb +26 -42
- metadata +9 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c6172daeb49538b3218a2977257687578c67f8c
|
4
|
+
data.tar.gz: 28fde20a2ea86841f93eff4fb13558567af21d54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43d9390c4e4de157ae7d6c26f259071ee027790c9a49c1ffd31e3c5e16b163e4903bbc412dcc2e670e0fcd0cd44b42da5469a41ae82c725b484f7bad0291c7d6
|
7
|
+
data.tar.gz: 9169146d166a892a713002a2ec0ea8f0e31ef107f8511a0c8b7c0c7ed16887d305bd7ae6e8ae89dc3e132f41616f12ecf4b87204bc230bd0bd8293ae2ab12ad0
|
@@ -13,59 +13,43 @@ module Bsm::Model::HasManySerialized
|
|
13
13
|
|
14
14
|
class Builder < ActiveRecord::Associations::Builder::CollectionAssociation
|
15
15
|
|
16
|
-
def build
|
17
|
-
|
18
|
-
super.tap do
|
19
|
-
define_accessors
|
16
|
+
def self.build(model, name, *)
|
17
|
+
model.serialize "#{name.to_s.singularize}_ids", ::Bsm::Model::Coders::JsonColumn.new(Array)
|
18
|
+
super.tap do |reflection|
|
20
19
|
end
|
21
20
|
end
|
22
21
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
[]
|
29
|
-
end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
def serialize_attribute
|
34
|
-
model.serialize attribute_name, ::Bsm::Model::Coders::JsonColumn.new(Array)
|
35
|
-
end
|
22
|
+
def self.define_accessors(model, reflection)
|
23
|
+
mixin = model.generated_association_methods
|
24
|
+
name = reflection.name
|
25
|
+
klass = reflection.klass
|
26
|
+
attribute_name = "#{name.to_s.singularize}_ids"
|
36
27
|
|
37
|
-
|
38
|
-
|
28
|
+
mixin.redefine_method(name) do
|
29
|
+
klass.where(klass.primary_key => send(attribute_name))
|
39
30
|
end
|
40
31
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
klass.
|
32
|
+
model.redefine_method("#{name}=") do |records|
|
33
|
+
records = Array.wrap(records)
|
34
|
+
records.each do |record|
|
35
|
+
next if record.is_a?(klass)
|
36
|
+
raise ActiveRecord::AssociationTypeMismatch, "#{klass.name} expected, got #{record.class}"
|
46
37
|
end
|
38
|
+
write_attribute attribute_name, records.map(&:id).sort
|
47
39
|
end
|
48
40
|
|
49
|
-
|
50
|
-
name,
|
51
|
-
|
52
|
-
model.redefine_method("#{name}=") do |records|
|
53
|
-
records = Array.wrap(records)
|
54
|
-
records.each do |record|
|
55
|
-
next if record.is_a?(klass)
|
56
|
-
raise ActiveRecord::AssociationTypeMismatch, "#{klass.name} expected, got #{record.class}"
|
57
|
-
end
|
58
|
-
write_attribute attribute_name, records.map(&:id).sort
|
59
|
-
end
|
60
|
-
|
61
|
-
model.redefine_method("#{attribute_name}=") do |values|
|
62
|
-
send "#{name}=", klass.where(klass.primary_key => Array.wrap(values)).select(:id).to_a.sort
|
63
|
-
end
|
41
|
+
model.redefine_method("#{attribute_name}=") do |values|
|
42
|
+
send "#{name}=", klass.where(klass.primary_key => Array.wrap(values)).select(:id).to_a.sort
|
64
43
|
end
|
44
|
+
end
|
65
45
|
|
66
|
-
|
67
|
-
|
68
|
-
|
46
|
+
def macro
|
47
|
+
:has_many
|
48
|
+
end
|
49
|
+
|
50
|
+
def valid_dependent_options
|
51
|
+
[]
|
52
|
+
end
|
69
53
|
|
70
54
|
end
|
71
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bsm-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitrij Denissenko
|
@@ -30,40 +30,40 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.
|
33
|
+
version: 4.1.0
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: 4.
|
36
|
+
version: 4.2.0
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 4.
|
43
|
+
version: 4.1.0
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 4.
|
46
|
+
version: 4.2.0
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: railties
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
51
|
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: 4.
|
53
|
+
version: 4.1.0
|
54
54
|
- - "<"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: 4.
|
56
|
+
version: 4.2.0
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 4.
|
63
|
+
version: 4.1.0
|
64
64
|
- - "<"
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 4.
|
66
|
+
version: 4.2.0
|
67
67
|
- !ruby/object:Gem::Dependency
|
68
68
|
name: rspec
|
69
69
|
requirement: !ruby/object:Gem::Requirement
|