store_model 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 272a27d0773295eeb4628b0cfd205ecd78bb0d53c9abad4f195a26a00582c465
4
- data.tar.gz: dd1709b12b83f49f2a67ea0d92bd5db7cb61be8699433630a17c22d6d6fccec2
3
+ metadata.gz: 56c80c30cd987d635b40bcd5863401d5ca45644078eaafbc4f0d4278e6ed29fb
4
+ data.tar.gz: e17b443b615750a1b87b35a0bda3acb6a287b267dbb6e3f3f4b7677e4ec0e11e
5
5
  SHA512:
6
- metadata.gz: 1beb4e1bcc06a983e68db54be1d692023f2e56e82824893d5f918c84056ccf23f49d0768219191fb40869850717ffca8a69d36bc1aa0128056ced6efdeed91c1
7
- data.tar.gz: c9f82ef6a68c480408cb176fe7817a61b8dd069df808f7450c9df3e54059a62a42866989728685af0cb2cdae8b68eeacfa98fbb1a36d324d6e76e6e76e5fe3d1
6
+ metadata.gz: 94605281aeead99bbdff837e4211f019bb4038754a3205b541adb5e76e58089ba1cbb202b22ec4c076dd4e842d2b12044cf28757fee7781b4fd4497851c35cee
7
+ data.tar.gz: 99f12655273e0a70158541723d5314c2b73a76eb21da79ea5ebc58c8d4375646e1ad092570031a7e75932d994f75f9d95720bd48bc8d1321b2c808eab2fcb9d9
@@ -10,10 +10,10 @@ module StoreModel
10
10
  def self.included(base)
11
11
  base.include ActiveModel::Model
12
12
  base.include ActiveModel::Attributes
13
+ base.include StoreModel::NestedAttributes
13
14
 
14
15
  base.extend StoreModel::Enum
15
16
  base.extend StoreModel::TypeBuilders
16
- base.extend StoreModel::NestedAttributes
17
17
  end
18
18
 
19
19
  def as_json(options = {})
@@ -35,5 +35,9 @@ module StoreModel
35
35
  attribute_string = attributes.map { |name, value| "#{name}: #{value || 'nil'}" }.join(", ")
36
36
  "#<#{self.class.name} #{attribute_string}>"
37
37
  end
38
+
39
+ def type_for_attribute(attribute)
40
+ self.class.attribute_types[attribute.to_s]
41
+ end
38
42
  end
39
43
  end
@@ -2,10 +2,30 @@
2
2
 
3
3
  module StoreModel
4
4
  module NestedAttributes
5
- def accepts_nested_attributes_for(*associations)
6
- associations.each do |association|
7
- alias_method "#{association}_attributes=", "#{association}="
5
+ def self.included(base)
6
+ base.extend ClassMethods
7
+ end
8
+
9
+ module ClassMethods
10
+ def accepts_nested_attributes_for(*associations)
11
+ associations.each do |association|
12
+ case attribute_types[association.to_s]
13
+ when Types::JsonType
14
+ alias_method "#{association}_attributes=", "#{association}="
15
+ when Types::ArrayType
16
+ define_method "#{association}_attributes=" do |attributes|
17
+ assign_nested_attributes_for_collection_association(association, attributes)
18
+ end
19
+ end
20
+ end
8
21
  end
9
22
  end
23
+
24
+ private
25
+
26
+ def assign_nested_attributes_for_collection_association(association, attributes)
27
+ attributes = attributes.values if attributes.is_a?(Hash)
28
+ send "#{association}=", attributes
29
+ end
10
30
  end
11
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StoreModel
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - DmitryTsepelev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-26 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails