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 +4 -4
- data/lib/store_model/model.rb +5 -1
- data/lib/store_model/nested_attributes.rb +23 -3
- data/lib/store_model/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56c80c30cd987d635b40bcd5863401d5ca45644078eaafbc4f0d4278e6ed29fb
|
4
|
+
data.tar.gz: e17b443b615750a1b87b35a0bda3acb6a287b267dbb6e3f3f4b7677e4ec0e11e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94605281aeead99bbdff837e4211f019bb4038754a3205b541adb5e76e58089ba1cbb202b22ec4c076dd4e842d2b12044cf28757fee7781b4fd4497851c35cee
|
7
|
+
data.tar.gz: 99f12655273e0a70158541723d5314c2b73a76eb21da79ea5ebc58c8d4375646e1ad092570031a7e75932d994f75f9d95720bd48bc8d1321b2c808eab2fcb9d9
|
data/lib/store_model/model.rb
CHANGED
@@ -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
|
6
|
-
|
7
|
-
|
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
|
data/lib/store_model/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2019-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|