foraneus 0.0.13 → 0.0.14
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 +7 -7
- data/README.md +12 -0
- data/lib/foraneus.rb +82 -41
- data/lib/foraneus/compatibility/ruby-1.8.7.rb +12 -0
- data/lib/foraneus/converters/integer.rb +3 -1
- data/spec/lib/foraneus/converters/float_converter_spec.rb +1 -1
- data/spec/lib/foraneus_spec.rb +1 -1
- data/spec/runner.rb +1 -3
- data/spec/spec_helper.rb +2 -0
- metadata +50 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6a1af4481bfbdeb0cc0aa78900c6b7f4512d7a21
|
4
|
+
data.tar.gz: 58cd1c7f084558def0575754919263b6763ba17a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 093a3fdc5eecea2934cd2ef01c88191bcf62fe317f61ed73519d8a77b4afcadd2ff96b5af17d4e5337e43da96bdd325861b6f94ca53d0a6642db6ffaf0aa5a03
|
7
|
+
data.tar.gz: cbf2a485c1df7a4da036256ea27f6a8097f7433cb8b4bcd3e5c922e1ef985b2003ed6a5e442f3755af1f89a66da393efd6c80f314787f54c6d9767223304fd1f
|
data/README.md
CHANGED
@@ -251,12 +251,24 @@ Tests are written in MiniTest. To run them all just execute the following from y
|
|
251
251
|
ruby spec/runner.rb
|
252
252
|
```
|
253
253
|
|
254
|
+
Execute the following when ruby 1.8.7:
|
255
|
+
|
256
|
+
``` shell
|
257
|
+
ruby -rubygems spec/runner.rb
|
258
|
+
```
|
259
|
+
|
254
260
|
To run a specific test case:
|
255
261
|
|
256
262
|
``` shell
|
257
263
|
ruby -Ispec -Ilib spec/lib/foraneus_spec.rb
|
258
264
|
```
|
259
265
|
|
266
|
+
When running under ruby 1.8.7:
|
267
|
+
|
268
|
+
``` shell
|
269
|
+
ruby -rubygems -Ispec -Ilib spec/lib/foraneus_spec.rb
|
270
|
+
```
|
271
|
+
|
260
272
|
## Code documentation
|
261
273
|
|
262
274
|
Documentation is written in Yard. To see it in a browser, execute this command:
|
data/lib/foraneus.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
if RUBY_VERSION == '1.8.7'
|
2
|
+
require 'foraneus/compatibility/ruby-1.8.7'
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'foraneus/converters/boolean'
|
6
|
+
require 'foraneus/converters/date'
|
7
|
+
require 'foraneus/converters/decimal'
|
8
|
+
require 'foraneus/converters/float'
|
9
|
+
require 'foraneus/converters/integer'
|
10
|
+
require 'foraneus/converters/noop'
|
11
|
+
require 'foraneus/converters/string'
|
12
|
+
require 'foraneus/errors'
|
9
13
|
|
10
14
|
# Foraneus base class used to declare a data set, aka 'form'.
|
11
15
|
class Foraneus
|
12
16
|
|
13
|
-
|
14
17
|
# @api private
|
15
18
|
def initialize
|
16
19
|
@_ = {}
|
@@ -105,18 +108,9 @@ class Foraneus
|
|
105
108
|
|
106
109
|
def self.create_instance
|
107
110
|
instance = self.new
|
108
|
-
spec = self
|
109
|
-
|
110
|
-
instance.singleton_class.send(:attr_reader, self.accessors[:data])
|
111
111
|
|
112
|
-
instance
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
instance.singleton_class.send(:attr_reader, self.accessors[:errors])
|
117
|
-
instance.instance_exec do
|
118
|
-
instance.instance_variable_set(:"@#{spec.accessors[:errors]}", {})
|
119
|
-
end
|
112
|
+
__singleton_attr_reader(instance, :data, {})
|
113
|
+
__singleton_attr_reader(instance, :errors, {})
|
120
114
|
|
121
115
|
instance
|
122
116
|
end
|
@@ -167,20 +161,7 @@ class Foraneus
|
|
167
161
|
data.fetch(given_key, nil)
|
168
162
|
end
|
169
163
|
|
170
|
-
|
171
|
-
|
172
|
-
if v.nil?
|
173
|
-
v = converter.opts[:default]
|
174
|
-
end
|
175
|
-
|
176
|
-
s = if v.nil?
|
177
|
-
nil
|
178
|
-
else
|
179
|
-
converter.raw(v)
|
180
|
-
end
|
181
|
-
|
182
|
-
instance[given_key] = s
|
183
|
-
instance.send(self.accessors[:data])[given_key] = v
|
164
|
+
__raw_datum(given_key, v, instance, converter)
|
184
165
|
end
|
185
166
|
|
186
167
|
instance
|
@@ -232,6 +213,29 @@ class Foraneus
|
|
232
213
|
|
233
214
|
foraneus[k] = v
|
234
215
|
|
216
|
+
v = __parse(k, v, converter)
|
217
|
+
|
218
|
+
foraneus.send("#{field}=", v)
|
219
|
+
foraneus.send(self.accessors[:data])[k] = v
|
220
|
+
|
221
|
+
rescue
|
222
|
+
error = Foraneus::Error.new($!.class.name, $!.message)
|
223
|
+
foraneus.send(self.accessors[:errors])[k] = error
|
224
|
+
end
|
225
|
+
private_class_method :__parse_raw_datum
|
226
|
+
|
227
|
+
# @api private
|
228
|
+
#
|
229
|
+
# Parses a raw value.
|
230
|
+
#
|
231
|
+
# @param [String, Symbol] field
|
232
|
+
# @param [String] v Raw value.
|
233
|
+
# @param converter
|
234
|
+
#
|
235
|
+
# @raise [KeyError] if converter requires a value but no one is given.
|
236
|
+
#
|
237
|
+
# @return [Object]
|
238
|
+
def self.__parse(field, v, converter)
|
235
239
|
if v == '' && converter.opts.fetch(:blanks_as_nil, true)
|
236
240
|
v = nil
|
237
241
|
end
|
@@ -239,18 +243,55 @@ class Foraneus
|
|
239
243
|
if v.nil? && converter.opts[:required]
|
240
244
|
raise KeyError, "required parameter not found: #{field.inspect}"
|
241
245
|
elsif v.nil?
|
242
|
-
|
246
|
+
converter.opts[:default]
|
243
247
|
else
|
244
|
-
|
248
|
+
converter.parse(v)
|
245
249
|
end
|
250
|
+
end
|
251
|
+
private_class_method :__parse
|
246
252
|
|
247
|
-
|
253
|
+
# @api private
|
254
|
+
#
|
255
|
+
# Obtains a raw representation of a value and assigns it to the corresponding field.
|
256
|
+
#
|
257
|
+
# It also registers errors if the conversion fails.
|
258
|
+
#
|
259
|
+
# @param [String, Symbol] k
|
260
|
+
# @param [String] v
|
261
|
+
# @param [Foraneus] foraneus
|
262
|
+
# @param [Converter] converter
|
263
|
+
def self.__raw_datum(k, v, foraneus, converter)
|
264
|
+
foraneus.send("#{k}=", v)
|
265
|
+
|
266
|
+
if v.nil?
|
267
|
+
v = converter.opts[:default]
|
268
|
+
end
|
269
|
+
|
270
|
+
s = unless v.nil?
|
271
|
+
converter.raw(v)
|
272
|
+
end
|
273
|
+
|
274
|
+
foraneus[k] = s
|
248
275
|
foraneus.send(self.accessors[:data])[k] = v
|
276
|
+
end
|
277
|
+
private_class_method :__raw_datum
|
249
278
|
|
250
|
-
|
251
|
-
|
252
|
-
|
279
|
+
# @api private
|
280
|
+
#
|
281
|
+
# Creates a singleton attribute reader on an instance.
|
282
|
+
#
|
283
|
+
# @param [Foraneus] instance
|
284
|
+
# @param [Symbol] attribute
|
285
|
+
# @param initial_value
|
286
|
+
def self.__singleton_attr_reader(instance, attribute, initial_value = nil)
|
287
|
+
spec = instance.class
|
288
|
+
|
289
|
+
instance.singleton_class.send(:attr_reader, spec.accessors[attribute])
|
290
|
+
|
291
|
+
instance.instance_exec do
|
292
|
+
instance.instance_variable_set(:"@#{spec.accessors[attribute]}", initial_value)
|
293
|
+
end
|
253
294
|
end
|
254
|
-
private_class_method :
|
295
|
+
private_class_method :__singleton_attr_reader
|
255
296
|
|
256
297
|
end
|
@@ -13,10 +13,12 @@ class Foraneus
|
|
13
13
|
@delimiter = opts[:delimiter]
|
14
14
|
end
|
15
15
|
|
16
|
-
# @raise [
|
16
|
+
# @raise [TypeError] with message 'invalid value for Integer(): ...'
|
17
17
|
#
|
18
18
|
# @return [Integer]
|
19
19
|
def parse(s)
|
20
|
+
raise TypeError, "can't convert nil into Integer" if s.nil?
|
21
|
+
|
20
22
|
s = s.gsub(@delimiter, '') if @delimiter
|
21
23
|
|
22
24
|
Kernel.Integer(s)
|
data/spec/lib/foraneus_spec.rb
CHANGED
data/spec/runner.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,53 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: foraneus
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- Gianfranco Zas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
11
|
+
|
12
|
+
date: 2014-12-04 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: minitest
|
21
16
|
prerelease: false
|
22
|
-
|
23
|
-
requirements:
|
24
|
-
-
|
25
|
-
-
|
26
|
-
|
27
|
-
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- &id002
|
20
|
+
- ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
type: :development
|
24
|
+
version_requirements: *id001
|
25
|
+
- !ruby/object:Gem::Dependency
|
28
26
|
name: yard
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
version: '0'
|
27
|
+
prerelease: false
|
28
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- *id002
|
34
31
|
type: :development
|
32
|
+
version_requirements: *id003
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: kramdown
|
35
35
|
prerelease: false
|
36
|
-
|
37
|
-
requirements:
|
38
|
-
-
|
39
|
-
|
40
|
-
|
36
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- *id002
|
39
|
+
type: :development
|
40
|
+
version_requirements: *id004
|
41
41
|
description: Provides two way transformation mechanisms to external data.
|
42
42
|
email: snmgian@gmail.com
|
43
43
|
executables: []
|
44
|
+
|
44
45
|
extensions: []
|
46
|
+
|
45
47
|
extra_rdoc_files: []
|
46
|
-
|
48
|
+
|
49
|
+
files:
|
47
50
|
- COPYING
|
48
51
|
- COPYING.LESSER
|
49
52
|
- README.md
|
50
53
|
- lib/foraneus.rb
|
54
|
+
- lib/foraneus/compatibility/ruby-1.8.7.rb
|
51
55
|
- lib/foraneus/converters/boolean.rb
|
52
56
|
- lib/foraneus/converters/date.rb
|
53
57
|
- lib/foraneus/converters/decimal.rb
|
@@ -68,30 +72,31 @@ files:
|
|
68
72
|
- spec/spec_helper.rb
|
69
73
|
- spec/spec_helper_its.rb
|
70
74
|
homepage: https://github.com/snmgian/foraneus
|
71
|
-
licenses:
|
75
|
+
licenses:
|
72
76
|
- LGPL
|
73
77
|
metadata: {}
|
78
|
+
|
74
79
|
post_install_message:
|
75
80
|
rdoc_options: []
|
76
|
-
|
81
|
+
|
82
|
+
require_paths:
|
77
83
|
- lib
|
78
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
85
86
|
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version:
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.8.7
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- *id002
|
88
92
|
requirements: []
|
93
|
+
|
89
94
|
rubyforge_project:
|
90
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.4.5
|
91
96
|
signing_key:
|
92
97
|
specification_version: 4
|
93
98
|
summary: Transforms external data.
|
94
|
-
test_files:
|
99
|
+
test_files:
|
95
100
|
- spec/lib/foraneus_spec.rb
|
96
101
|
- spec/lib/foraneus/converters/noop_converter_spec.rb
|
97
102
|
- spec/lib/foraneus/converters/decimal_converter_spec.rb
|
@@ -103,3 +108,4 @@ test_files:
|
|
103
108
|
- spec/spec_helper.rb
|
104
109
|
- spec/spec_helper_its.rb
|
105
110
|
- spec/runner.rb
|
111
|
+
has_rdoc:
|