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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2ceca071140a27ffd3ec6767e726b890491f726
4
- data.tar.gz: 51536dee838ad39c97905a1950303a2ca11c9fd3
3
+ metadata.gz: 8c6172daeb49538b3218a2977257687578c67f8c
4
+ data.tar.gz: 28fde20a2ea86841f93eff4fb13558567af21d54
5
5
  SHA512:
6
- metadata.gz: fc905253548fa5946306ae4936bce3d38ecacd687fc2891ee4b9aa0f7da0f39c3ff837baef8312cf5f696b36e1dae690f1ca2aa058968a926202d180f0c552fd
7
- data.tar.gz: 306c540b9ab2615aec5aed158f01c3fe2502e093bd19b3509686699c89b4afc818367b88d4ca3f9e115b0057db2c0b4a784531bd3c981c2fc778801c4fe499b3
6
+ metadata.gz: 43d9390c4e4de157ae7d6c26f259071ee027790c9a49c1ffd31e3c5e16b163e4903bbc412dcc2e670e0fcd0cd44b42da5469a41ae82c725b484f7bad0291c7d6
7
+ data.tar.gz: 9169146d166a892a713002a2ec0ea8f0e31ef107f8511a0c8b7c0c7ed16887d305bd7ae6e8ae89dc3e132f41616f12ecf4b87204bc230bd0bd8293ae2ab12ad0
@@ -1,7 +1,7 @@
1
1
  class Bsm::Model::Coders::JsonColumn < Bsm::Model::Coders::AbstractColumn
2
2
 
3
3
  def self.rescue_errors
4
- [ MultiJson::DecodeError ]
4
+ [ ::JSON::ParserError ]
5
5
  end
6
6
 
7
7
  def dump(obj)
@@ -13,59 +13,43 @@ module Bsm::Model::HasManySerialized
13
13
 
14
14
  class Builder < ActiveRecord::Associations::Builder::CollectionAssociation
15
15
 
16
- def build
17
- serialize_attribute
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 macro
24
- :has_many
25
- end
26
-
27
- def valid_dependent_options
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
- def define_accessors
38
- super if reflection
28
+ mixin.redefine_method(name) do
29
+ klass.where(klass.primary_key => send(attribute_name))
39
30
  end
40
31
 
41
- def define_readers
42
- name, attribute_name, klass = self.name, self.attribute_name, reflection.klass
43
-
44
- model.redefine_method(name) do
45
- klass.where(klass.primary_key => send(attribute_name))
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
- def define_writers
50
- name, attribute_name, klass = self.name, self.attribute_name, reflection.klass
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
- def attribute_name
67
- @attribute_name ||= "#{name.to_s.singularize}_ids"
68
- end
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.7.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.0.0
33
+ version: 4.1.0
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: 4.1.0
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.0.0
43
+ version: 4.1.0
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: 4.1.0
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.0.0
53
+ version: 4.1.0
54
54
  - - "<"
55
55
  - !ruby/object:Gem::Version
56
- version: 4.1.0
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.0.0
63
+ version: 4.1.0
64
64
  - - "<"
65
65
  - !ruby/object:Gem::Version
66
- version: 4.1.0
66
+ version: 4.2.0
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: rspec
69
69
  requirement: !ruby/object:Gem::Requirement