static_models 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/static_models.rb +13 -2
- data/lib/static_models/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95dcda301025a843f99a3e567bdf268f8f1ac2a3
|
4
|
+
data.tar.gz: ec1a9c8f7b448f4f1e2c5d4ba7b2936c68663e66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10b2dee5e6e4f24d3c9bc11fb94c8b9308859387b37335514c6075ffab7ca28a5653fbda888066834ba7cd9f7316a47db0c29666f4d343dea4e48414297cc5b7
|
7
|
+
data.tar.gz: 19bc8ff8a614b322001596469dfb2f96933f18e3ba9f941cfd5a0b8deb12547cdf136d2c1738ad19a295fd3c34dc916551255f447a5973351fbc57b7e2f5242b
|
data/lib/static_models.rb
CHANGED
@@ -114,6 +114,10 @@ module StaticModels
|
|
114
114
|
values.values
|
115
115
|
end
|
116
116
|
|
117
|
+
def codes
|
118
|
+
values.values.map(&:code)
|
119
|
+
end
|
120
|
+
|
117
121
|
def model_name
|
118
122
|
ActiveModel::Name.new(self)
|
119
123
|
end
|
@@ -169,11 +173,18 @@ module StaticModels
|
|
169
173
|
|
170
174
|
#Adding accesor for code_representation
|
171
175
|
define_method("#{association}_code=") do |value|
|
172
|
-
|
176
|
+
if thing = expected_class.find_by_code(value)
|
177
|
+
instance_variable_set("@invalid_#{association}_code", nil)
|
178
|
+
send("#{association}=", thing)
|
179
|
+
else
|
180
|
+
instance_variable_set("@invalid_#{association}_code",
|
181
|
+
value.try(:to_sym))
|
182
|
+
end
|
173
183
|
end
|
174
184
|
|
175
185
|
define_method("#{association}_code") do
|
176
|
-
send(association).try(:code)
|
186
|
+
send(association).try(:code) ||
|
187
|
+
instance_variable_get("@invalid_#{association}_code")
|
177
188
|
end
|
178
189
|
end
|
179
190
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: static_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nubis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|