schema-model 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/schema/array_headers.rb +1 -1
- data/lib/schema/associations/has_many.rb +11 -11
- data/lib/schema/associations/has_one.rb +11 -11
- data/lib/schema/model.rb +12 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b72fb0e41743e3c662c33b14ab05ac593d638f7b13815f59a61f911ecedd96fb
|
4
|
+
data.tar.gz: 5240afec97492c8a362acbc8de0e1257e2cbdac1251db48e22cb5a33b6ec855d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99de0c37026fad9c8d976d47d75af0c65fc39c4b527503398227084e4d582c53a213ea12d8b782483bf7d0242f370bdec19bbad676031faf1b49e5e0a35952b1
|
7
|
+
data.tar.gz: 6e3f5ece082047b713af401875d2004c422d777605c89ccd0e69ae01fa0ce9a341f222f1f8ba37cd4b158cd0ff28a1c4bfa0648ccc040a8ad13adb8e93197b68
|
data/lib/schema/array_headers.rb
CHANGED
@@ -47,7 +47,7 @@ module Schema
|
|
47
47
|
mapped_model = mapped_headers[field_name] || {}
|
48
48
|
const_get(field_options[:class_name]).get_field_names(
|
49
49
|
mapped_model,
|
50
|
-
header_prefix || field_options[:aliases]
|
50
|
+
header_prefix || (field_options[:aliases] && field_options[:aliases].first),
|
51
51
|
mapped
|
52
52
|
)
|
53
53
|
end
|
@@ -15,19 +15,19 @@ module Schema
|
|
15
15
|
options = ::Schema::Utils.add_association_class(self, name, :has_many, options)
|
16
16
|
|
17
17
|
class_eval(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
<<~STR
|
19
|
+
def #{options[:getter]}
|
20
|
+
#{options[:instance_variable]}
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def #{name}_schema_creator
|
24
|
+
@#{name}_schema_creator ||= ::Schema::Associations::SchemaCreator.new(self, #{name.inspect})
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def #{options[:setter]}(v)
|
28
|
+
#{options[:instance_variable]} = #{name}_schema_creator.create_schemas(self, v)
|
29
|
+
end
|
30
|
+
STR
|
31
31
|
)
|
32
32
|
|
33
33
|
kls = const_get(options[:class_name])
|
@@ -15,19 +15,19 @@ module Schema
|
|
15
15
|
options = ::Schema::Utils.add_association_class(self, name, :has_one, options)
|
16
16
|
|
17
17
|
class_eval(
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
<<~STR
|
19
|
+
def #{options[:getter]}
|
20
|
+
#{options[:instance_variable]}
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def #{name}_schema_creator
|
24
|
+
@#{name}_schema_creator ||= ::Schema::Associations::SchemaCreator.new(self, #{name.inspect})
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def #{options[:setter]}(v)
|
28
|
+
#{options[:instance_variable]} = #{name}_schema_creator.create_schema(self, v)
|
29
|
+
end
|
30
|
+
STR
|
31
31
|
)
|
32
32
|
|
33
33
|
kls = const_get(options[:class_name])
|
data/lib/schema/model.rb
CHANGED
@@ -69,20 +69,22 @@ module Schema
|
|
69
69
|
|
70
70
|
def add_attribute_methods(name, options)
|
71
71
|
class_eval(
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
72
|
+
<<~STR
|
73
|
+
def #{options[:getter]}
|
74
|
+
#{options[:instance_variable]}
|
75
|
+
end
|
76
|
+
|
77
|
+
def #{options[:setter]}(v)
|
78
|
+
#{options[:instance_variable]} = #{options[:parser]}(#{name.inspect}, parsing_errors, v)
|
79
|
+
end
|
80
|
+
STR
|
81
81
|
)
|
82
82
|
end
|
83
83
|
|
84
84
|
def add_aliases(name, options)
|
85
|
-
options[:aliases]
|
85
|
+
return unless options[:aliases]
|
86
|
+
|
87
|
+
options[:aliases].each do |alias_name|
|
86
88
|
add_value_to_class_method(:schema, alias_name.to_sym => options.merge(key: alias_name.to_s, alias_of: name))
|
87
89
|
alias_method(alias_name, options[:getter])
|
88
90
|
alias_method("#{alias_name}=", options[:setter])
|