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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef16467be2cf5b1af8c2563e1756c231b0488f23
4
- data.tar.gz: 40d99eba2608411081c3dca132b83ce6cbeba957
3
+ metadata.gz: 95dcda301025a843f99a3e567bdf268f8f1ac2a3
4
+ data.tar.gz: ec1a9c8f7b448f4f1e2c5d4ba7b2936c68663e66
5
5
  SHA512:
6
- metadata.gz: ddd989a5d05a2e12224f737b745b96872f37c5f5d7161409b6a05bd0a83121b532b74af56095fb674b2aa24bd579341a20a0ea94f589db80bf5147b92610af10
7
- data.tar.gz: 1a320c81218ceb01903cc2cb8ba57e99a06c0d6e946fd1b47b9c723f05a83e9c0aedd66a0f5307a83f8ca46b8cdc560fe7ef454f03578397cbf58bac0f73a0a6
6
+ metadata.gz: 10b2dee5e6e4f24d3c9bc11fb94c8b9308859387b37335514c6075ffab7ca28a5653fbda888066834ba7cd9f7316a47db0c29666f4d343dea4e48414297cc5b7
7
+ data.tar.gz: 19bc8ff8a614b322001596469dfb2f96933f18e3ba9f941cfd5a0b8deb12547cdf136d2c1738ad19a295fd3c34dc916551255f447a5973351fbc57b7e2f5242b
@@ -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
- send("#{association}=", expected_class.find_by_code(value))
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
@@ -1,3 +1,3 @@
1
1
  module StaticModels
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  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.6
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-09-03 00:00:00.000000000 Z
11
+ date: 2018-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport