data_crate 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/crate/crate.rb +27 -1
- data/lib/crate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0615d86db1dac768da4efc39e5fa48a2a344449970c2b65a58f2f0d2d46a860b
|
4
|
+
data.tar.gz: 3c3df4057e0694668237824d15930c16a64613bfafc7c2ba2755784490bc4fe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a17e0fd1d9cb0d4b619992cfd3f16e17136fef030f2b641ff40a39bd324dd58de021bf75fed9cc2dcad07e698879a8e7b732640924f7d9679728d07623ef1f0f
|
7
|
+
data.tar.gz: d473b70b5345e03ab9c55c0e36ac8766bb6000d90b0ae2a6ff10f7f4febee0177df94d9900d6bde72608fd4db2956c9e42950fdb2aadde5eb95af39baa5fa00d
|
data/Gemfile.lock
CHANGED
data/lib/crate/crate.rb
CHANGED
@@ -8,6 +8,7 @@ module Crate
|
|
8
8
|
def _initialize(**options)
|
9
9
|
@_names = []
|
10
10
|
@_crates = {}
|
11
|
+
@_arrays = {}
|
11
12
|
@_hooks = []
|
12
13
|
@_options = { logger: Logger.new(nil), **options }
|
13
14
|
@_crate_klasses = []
|
@@ -33,6 +34,15 @@ module Crate
|
|
33
34
|
)
|
34
35
|
end
|
35
36
|
|
37
|
+
def array(*args, **options, &initializer)
|
38
|
+
name, klass, = args
|
39
|
+
declare(name)
|
40
|
+
@_arrays[name] = klass || _class(
|
41
|
+
**_options, basename: name.to_s, **options,
|
42
|
+
&initializer
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
36
46
|
def versions(*crate_klasses)
|
37
47
|
@_crate_klasses = crate_klasses
|
38
48
|
end
|
@@ -97,7 +107,8 @@ module Crate
|
|
97
107
|
end
|
98
108
|
end
|
99
109
|
|
100
|
-
attr_reader :_options, :_names, :_crates, :
|
110
|
+
attr_reader :_options, :_names, :_crates, :_arrays,
|
111
|
+
:_hooks, :_crate_klasses
|
101
112
|
|
102
113
|
def _basename
|
103
114
|
_options[:basename]
|
@@ -121,6 +132,10 @@ module Crate
|
|
121
132
|
"#{_fullname}[#{name.inspect}]"
|
122
133
|
end
|
123
134
|
|
135
|
+
def _array_name(name, index)
|
136
|
+
"#{_name(name)}[#{index}]"
|
137
|
+
end
|
138
|
+
|
124
139
|
attr_reader :_raw, :_options
|
125
140
|
|
126
141
|
def initialize(raw, **options)
|
@@ -128,6 +143,7 @@ module Crate
|
|
128
143
|
{ **self.class._options, fullname: self.class._basename, **options }
|
129
144
|
@_raw = Raw.new(raw, **_options).to_hash
|
130
145
|
_new_crates
|
146
|
+
_new_arrays
|
131
147
|
_run_hooks
|
132
148
|
_select_klass_if_exist(**options)
|
133
149
|
end
|
@@ -140,6 +156,16 @@ module Crate
|
|
140
156
|
end
|
141
157
|
end
|
142
158
|
|
159
|
+
def _new_arrays
|
160
|
+
self.class._arrays \
|
161
|
+
.select { |name, _klass| _raw.key?(name) } \
|
162
|
+
.each do |name, klass|
|
163
|
+
_raw[name].map!.with_index do |raw, index|
|
164
|
+
klass.new(raw, **_options, fullname: _array_name(name, index))
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
143
169
|
def _run_hooks
|
144
170
|
self.class._hooks.each { |hook| instance_eval(&hook) }
|
145
171
|
end
|
data/lib/crate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_crate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minwoo Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|