static_models 0.4.4 → 0.4.5
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 +18 -1
- data/lib/static_models/version.rb +1 -1
- data/static_models.gemspec +3 -3
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f04db8a1974a679eb14287f3a693315b7f6fd3a
|
4
|
+
data.tar.gz: 360864b05b888ba14c4c1edcca3004843a646e2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b915ac1cdb5db7027699ea4af95c928d6848cfb81b0ee3bf303a41b77b362522090285ed5ec50c43091f11f0ef1cb6f2572581c5907d8e96e45e7bcf4253acc4
|
7
|
+
data.tar.gz: dee03953935995525d7a7b1604a6dfc2fbd401fa57b529cef6746def521a0aecabe91c38187ccb65e7d79045fac3979596427639e366bd54d40c99e371c48836
|
data/lib/static_models.rb
CHANGED
@@ -56,7 +56,11 @@ module StaticModels
|
|
56
56
|
|
57
57
|
def static_models_sparse(table)
|
58
58
|
table.each do |row|
|
59
|
-
expected =
|
59
|
+
expected = if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
|
60
|
+
row.size == 2 ? [Integer, Symbol] : [Integer, Symbol, Hash]
|
61
|
+
else
|
62
|
+
row.size == 2 ? [Fixnum, Symbol] : [Fixnum, Symbol, Hash]
|
63
|
+
end
|
60
64
|
|
61
65
|
if row.collect(&:class) != expected
|
62
66
|
raise ValueError.new("Invalid row #{row}, expected #{expected}")
|
@@ -100,6 +104,10 @@ module StaticModels
|
|
100
104
|
values[id.to_i]
|
101
105
|
end
|
102
106
|
|
107
|
+
def find_by_code(code)
|
108
|
+
all.select{|x| x.code == code.to_sym}.first
|
109
|
+
end
|
110
|
+
|
103
111
|
def all
|
104
112
|
values.values
|
105
113
|
end
|
@@ -156,6 +164,15 @@ module StaticModels
|
|
156
164
|
super(value)
|
157
165
|
end
|
158
166
|
end
|
167
|
+
|
168
|
+
#Adding accesor for code_representation
|
169
|
+
define_method("#{association}_code=") do |value|
|
170
|
+
send("#{association}=", expected_class.find_by_code(value))
|
171
|
+
end
|
172
|
+
|
173
|
+
define_method("#{association}_code") do
|
174
|
+
send(association).try(:code)
|
175
|
+
end
|
159
176
|
end
|
160
177
|
end
|
161
178
|
end
|
data/static_models.gemspec
CHANGED
@@ -23,13 +23,13 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.bindir = "exe"
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ["lib"]
|
26
|
-
spec.add_dependency "activesupport", '~>
|
27
|
-
spec.add_dependency "activemodel",'~>
|
26
|
+
spec.add_dependency "activesupport", '~> 5.1', '>= 5.1.4'
|
27
|
+
spec.add_dependency "activemodel",'~> 5.1', '>= 5.1.4'
|
28
28
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 1.13"
|
30
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
31
31
|
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
-
spec.add_development_dependency "activerecord", '~>
|
32
|
+
spec.add_development_dependency "activerecord", '~> 5.1', '>= 5.1.4'
|
33
33
|
spec.add_development_dependency "sqlite3", "~> 1.0", ">= 1.0.0"
|
34
34
|
spec.add_development_dependency "byebug", "~> 6.0", ">= 6.0.0"
|
35
35
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nubis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,40 +16,40 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.1'
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 5.1.4
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '5.1'
|
30
30
|
- - ">="
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 5.1.4
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activemodel
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '5.1'
|
40
40
|
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
42
|
+
version: 5.1.4
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - "~>"
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '5.1'
|
50
50
|
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
52
|
+
version: 5.1.4
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: bundler
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,20 +98,20 @@ dependencies:
|
|
98
98
|
requirements:
|
99
99
|
- - "~>"
|
100
100
|
- !ruby/object:Gem::Version
|
101
|
-
version: '
|
101
|
+
version: '5.1'
|
102
102
|
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version:
|
104
|
+
version: 5.1.4
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
109
|
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
111
|
+
version: '5.1'
|
112
112
|
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
114
|
+
version: 5.1.4
|
115
115
|
- !ruby/object:Gem::Dependency
|
116
116
|
name: sqlite3
|
117
117
|
requirement: !ruby/object:Gem::Requirement
|