static_models 0.4.5 → 0.4.6
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/static_models/version.rb +1 -1
- data/lib/static_models.rb +9 -7
- 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: ef16467be2cf5b1af8c2563e1756c231b0488f23
|
4
|
+
data.tar.gz: 40d99eba2608411081c3dca132b83ce6cbeba957
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddd989a5d05a2e12224f737b745b96872f37c5f5d7161409b6a05bd0a83121b532b74af56095fb674b2aa24bd579341a20a0ea94f589db80bf5147b92610af10
|
7
|
+
data.tar.gz: 1a320c81218ceb01903cc2cb8ba57e99a06c0d6e946fd1b47b9c723f05a83e9c0aedd66a0f5307a83f8ca46b8cdc560fe7ef454f03578397cbf58bac0f73a0a6
|
data/lib/static_models.rb
CHANGED
@@ -45,6 +45,12 @@ module StaticModels
|
|
45
45
|
end
|
46
46
|
|
47
47
|
class_methods do
|
48
|
+
NumberType = if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
|
49
|
+
Integer
|
50
|
+
else
|
51
|
+
Fixnum
|
52
|
+
end
|
53
|
+
|
48
54
|
def static_models_dense(table)
|
49
55
|
columns = table.first
|
50
56
|
hashes = table[1..-1].collect do |row|
|
@@ -56,11 +62,7 @@ module StaticModels
|
|
56
62
|
|
57
63
|
def static_models_sparse(table)
|
58
64
|
table.each do |row|
|
59
|
-
expected =
|
60
|
-
row.size == 2 ? [Integer, Symbol] : [Integer, Symbol, Hash]
|
61
|
-
else
|
62
|
-
row.size == 2 ? [Fixnum, Symbol] : [Fixnum, Symbol, Hash]
|
63
|
-
end
|
65
|
+
expected = row.size == 2 ? [NumberType, Symbol] : [NumberType, Symbol, Hash]
|
64
66
|
|
65
67
|
if row.collect(&:class) != expected
|
66
68
|
raise ValueError.new("Invalid row #{row}, expected #{expected}")
|
@@ -79,7 +81,7 @@ module StaticModels
|
|
79
81
|
raise ValueError.new("Table column names must all be Symbols")
|
80
82
|
end
|
81
83
|
|
82
|
-
unless hashes.all?{|h| h[:id].is_a?(
|
84
|
+
unless hashes.all?{|h| h[:id].is_a?(NumberType)}
|
83
85
|
raise ValueError.new("Ids must be integers")
|
84
86
|
end
|
85
87
|
|
@@ -105,7 +107,7 @@ module StaticModels
|
|
105
107
|
end
|
106
108
|
|
107
109
|
def find_by_code(code)
|
108
|
-
all.select{|x| x.code == code.to_sym}.first
|
110
|
+
all.select{|x| x.code == code.try(:to_sym)}.first
|
109
111
|
end
|
110
112
|
|
111
113
|
def all
|
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.6
|
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-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|