transproc 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile +8 -4
- data/README.md +8 -4
- data/lib/transproc.rb +1 -1
- data/lib/transproc/all.rb +1 -0
- data/lib/transproc/composite.rb +1 -1
- data/lib/transproc/error.rb +0 -12
- data/lib/transproc/function.rb +1 -3
- data/lib/transproc/hash.rb +34 -3
- data/lib/transproc/proc.rb +46 -0
- data/lib/transproc/recursion.rb +10 -3
- data/lib/transproc/rspec.rb +12 -5
- data/lib/transproc/support/deprecations.rb +2 -2
- data/lib/transproc/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/unit/function_not_found_error_spec.rb +3 -3
- data/spec/unit/hash_transformations_spec.rb +78 -11
- data/spec/unit/proc_transformations_spec.rb +18 -0
- data/spec/unit/recursion_spec.rb +2 -2
- data/spec/unit/transproc_spec.rb +0 -16
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01eecdd5844cf6c0c3b491536ceb189ad6790517
|
4
|
+
data.tar.gz: c90ca55ae62ce7c30e182827695a299719725205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc6de084dda67ce23903aa7f9fc55c070508828759f4a55b324089738a51e9919d2e69598664ee637185293ce8254a93b593b38b17550b57fe5644f2e3c625cd
|
7
|
+
data.tar.gz: 4acba367f90300be3aee4dedb910db44ac0eed89efa998094e50d4b716f51c584c9e8db8f362670aad752febd70f1d95decefa107fefc2d5c7a9b0b72020d060
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
## v0.3.3 to-be-released
|
2
|
+
|
3
|
+
## Fixed
|
4
|
+
|
5
|
+
* `rename_keys` no longer creates new keys (robmiller)
|
6
|
+
|
7
|
+
## Deleted
|
8
|
+
|
9
|
+
* `MalformedInputError` exception. Transproc doesn't catch and re-raise exceptions any longer (nepalez)
|
10
|
+
|
11
|
+
[Compare v0.3.2...HEAD](https://github.com/solnic/transproc/compare/v0.3.2...HEAD)
|
12
|
+
|
1
13
|
## v0.3.2 2015-08-17
|
2
14
|
|
3
15
|
## Changed
|
data/Gemfile
CHANGED
@@ -4,12 +4,16 @@ gemspec
|
|
4
4
|
|
5
5
|
group :test do
|
6
6
|
gem 'equalizer'
|
7
|
-
gem 'anima'
|
8
7
|
gem 'codeclimate-test-reporter', require: nil
|
9
8
|
|
10
|
-
|
11
|
-
gem '
|
12
|
-
|
9
|
+
if RUBY_VERSION >= '2.1'
|
10
|
+
gem 'anima'
|
11
|
+
platform :mri do
|
12
|
+
gem 'mutant', github: 'mbj/mutant', branch: 'master'
|
13
|
+
gem 'mutant-rspec'
|
14
|
+
end
|
15
|
+
else
|
16
|
+
gem 'anima', '~> 0.2.0'
|
13
17
|
end
|
14
18
|
end
|
15
19
|
|
data/README.md
CHANGED
@@ -39,20 +39,24 @@ Or install it yourself as:
|
|
39
39
|
``` ruby
|
40
40
|
require 'json'
|
41
41
|
require 'transproc/all'
|
42
|
-
require 'inflecto'
|
43
42
|
|
44
43
|
# create your own local registry for transformation functions
|
45
44
|
module Functions
|
46
45
|
extend Transproc::Registry
|
47
46
|
end
|
48
47
|
|
49
|
-
# import necessary functions from
|
48
|
+
# import necessary functions from other transprocs...
|
50
49
|
module Functions
|
51
|
-
# all
|
50
|
+
# import all singleton methods from a module/class
|
52
51
|
import Transproc::HashTransformations
|
53
52
|
import Transproc::ArrayTransformations
|
53
|
+
end
|
54
54
|
|
55
|
-
|
55
|
+
# ...or from any external library
|
56
|
+
require 'inflecto'
|
57
|
+
module Functions
|
58
|
+
# import only necessary singleton methods from a module/class
|
59
|
+
# and rename them locally
|
56
60
|
import :camelize, from: Inflecto, as: :camel_case
|
57
61
|
end
|
58
62
|
|
data/lib/transproc.rb
CHANGED
data/lib/transproc/all.rb
CHANGED
data/lib/transproc/composite.rb
CHANGED
data/lib/transproc/error.rb
CHANGED
@@ -8,16 +8,4 @@ module Transproc
|
|
8
8
|
super "No globally registered function for #{function}"
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
12
|
-
class MalformedInputError < Error
|
13
|
-
attr_reader :function, :value, :original_error
|
14
|
-
|
15
|
-
def initialize(function, value, error)
|
16
|
-
@function = function
|
17
|
-
@value = value
|
18
|
-
@original_error = error
|
19
|
-
super "Failed to call_function #{function} with #{value.inspect} - #{error}"
|
20
|
-
set_backtrace(error.backtrace)
|
21
|
-
end
|
22
|
-
end
|
23
11
|
end
|
data/lib/transproc/function.rb
CHANGED
data/lib/transproc/hash.rb
CHANGED
@@ -171,7 +171,37 @@ module Transproc
|
|
171
171
|
#
|
172
172
|
# @api public
|
173
173
|
def self.rename_keys!(hash, mapping)
|
174
|
-
mapping.each { |k, v| hash[v] = hash.delete(k) }
|
174
|
+
mapping.each { |k, v| hash[v] = hash.delete(k) if hash.has_key?(k) }
|
175
|
+
hash
|
176
|
+
end
|
177
|
+
|
178
|
+
# Copy all keys in a hash using provided mapping hash
|
179
|
+
#
|
180
|
+
# @example
|
181
|
+
# Transproc(:copy_keys, user_name: :name)[user_name: 'Jane']
|
182
|
+
# # => {:user_name => "Jane", :name => "Jane"}
|
183
|
+
#
|
184
|
+
# @param [Hash] hash The input hash
|
185
|
+
# @param [Hash] mapping The key-copy mapping
|
186
|
+
#
|
187
|
+
# @return [Hash]
|
188
|
+
#
|
189
|
+
# @api public
|
190
|
+
def self.copy_keys(hash, mapping)
|
191
|
+
copy_keys!(Hash[hash], mapping)
|
192
|
+
end
|
193
|
+
|
194
|
+
# Same as `:copy_keys` but mutates the hash
|
195
|
+
#
|
196
|
+
# @see HashTransformations.copy_keys
|
197
|
+
#
|
198
|
+
# @api public
|
199
|
+
def self.copy_keys!(hash, mapping)
|
200
|
+
mapping.each do |original_key, new_keys|
|
201
|
+
[*new_keys].each do |new_key|
|
202
|
+
hash[new_key] = hash[original_key]
|
203
|
+
end
|
204
|
+
end
|
175
205
|
hash
|
176
206
|
end
|
177
207
|
|
@@ -446,8 +476,9 @@ module Transproc
|
|
446
476
|
#
|
447
477
|
# @api public
|
448
478
|
def self.deep_merge(hash, other)
|
449
|
-
Hash[hash].merge(other) do |
|
450
|
-
if original_value.respond_to?(:to_hash) &&
|
479
|
+
Hash[hash].merge(other) do |_, original_value, new_value|
|
480
|
+
if original_value.respond_to?(:to_hash) &&
|
481
|
+
new_value.respond_to?(:to_hash)
|
451
482
|
deep_merge(Hash[original_value], Hash[new_value])
|
452
483
|
else
|
453
484
|
new_value
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Transproc
|
2
|
+
# Transformation functions for Procs
|
3
|
+
#
|
4
|
+
# @example
|
5
|
+
# require 'ostruct'
|
6
|
+
# require 'transproc/proc'
|
7
|
+
#
|
8
|
+
# include Transproc::Helper
|
9
|
+
#
|
10
|
+
# fn = t(
|
11
|
+
# :map_value,
|
12
|
+
# 'foo_bar',
|
13
|
+
# t(:bind, OpenStruct.new(prefix: 'foo'), -> s { [prefix, s].join('_') })
|
14
|
+
# )
|
15
|
+
#
|
16
|
+
# fn["foo_bar" => "bar"]
|
17
|
+
# # => {"foo_bar" => "foo_bar"}
|
18
|
+
#
|
19
|
+
# @api public
|
20
|
+
module ProcTransformations
|
21
|
+
extend Registry
|
22
|
+
|
23
|
+
# Change the binding for the given function
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# Transproc(
|
27
|
+
# :bind,
|
28
|
+
# OpenStruct.new(prefix: 'foo'),
|
29
|
+
# -> s { [prefix, s].join('_') }
|
30
|
+
# )['bar']
|
31
|
+
# # => "foo_bar"
|
32
|
+
#
|
33
|
+
# @param [Proc]
|
34
|
+
#
|
35
|
+
# @return [Proc]
|
36
|
+
#
|
37
|
+
# @api public
|
38
|
+
def self.bind(value, binding, fn)
|
39
|
+
binding.instance_exec(value, &fn)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @deprecated Register methods globally
|
43
|
+
(methods - Registry.instance_methods - Registry.methods)
|
44
|
+
.each { |name| Transproc.register name, t(name) }
|
45
|
+
end
|
46
|
+
end
|
data/lib/transproc/recursion.rb
CHANGED
@@ -10,8 +10,8 @@ module Transproc
|
|
10
10
|
#
|
11
11
|
# fn = t(:hash_recursion, t(:symbolize_keys))
|
12
12
|
#
|
13
|
-
# fn["name" => "Jane", "address" => { "street" => "Street 1"
|
14
|
-
# # => {:name=>"Jane", :address=>{:street=>"Street 1"
|
13
|
+
# fn["name" => "Jane", "address" => { "street" => "Street 1" }]
|
14
|
+
# # => {:name=>"Jane", :address=>{:street=>"Street 1"}}
|
15
15
|
#
|
16
16
|
# @api public
|
17
17
|
module Recursion
|
@@ -36,7 +36,14 @@ module Transproc
|
|
36
36
|
# ]
|
37
37
|
# }
|
38
38
|
# ]
|
39
|
-
# => {
|
39
|
+
# => {
|
40
|
+
# :id=>1,
|
41
|
+
# :name=>"Jane",
|
42
|
+
# :tasks=>[
|
43
|
+
# {:id=>1, :description=>"Write some code"},
|
44
|
+
# {:id=>2, :description=>"Write some more code"}
|
45
|
+
# ]
|
46
|
+
# }
|
40
47
|
#
|
41
48
|
# @param [Enumerable]
|
42
49
|
#
|
data/lib/transproc/rspec.rb
CHANGED
@@ -5,8 +5,15 @@
|
|
5
5
|
# ==============================================================================
|
6
6
|
|
7
7
|
shared_context :call_transproc do
|
8
|
-
let!(:
|
9
|
-
let!(:
|
8
|
+
let!(:__fn__) { described_class[*arguments] }
|
9
|
+
let!(:__initial__) do
|
10
|
+
begin
|
11
|
+
input.dup
|
12
|
+
rescue
|
13
|
+
input
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
10
17
|
subject { __fn__[input] }
|
11
18
|
end
|
12
19
|
|
@@ -14,7 +21,7 @@ shared_examples :transforming_data do
|
|
14
21
|
include_context :call_transproc
|
15
22
|
|
16
23
|
it '[returns the expected output]' do
|
17
|
-
expect(subject).to eql(output), <<-REPORT.gsub(
|
24
|
+
expect(subject).to eql(output), <<-REPORT.gsub(%r{.+\|}, '')
|
18
25
|
|
|
19
26
|
|fn = #{described_class}#{Array[*arguments]}
|
20
27
|
|
|
@@ -33,7 +40,7 @@ shared_examples :transforming_immutable_data do
|
|
33
40
|
|
34
41
|
it '[keeps input unchanged]' do
|
35
42
|
expect { subject }
|
36
|
-
.not_to change { input }, <<-REPORT.gsub(
|
43
|
+
.not_to change { input }, <<-REPORT.gsub(%r{.+\|}, '')
|
37
44
|
|
|
38
45
|
|fn = #{described_class}#{Array[*arguments]}
|
39
46
|
|
|
@@ -51,7 +58,7 @@ shared_examples :mutating_input_data do
|
|
51
58
|
it '[changes input]' do
|
52
59
|
expect { subject }
|
53
60
|
.to change { input }
|
54
|
-
.to(output), <<-REPORT.gsub(
|
61
|
+
.to(output), <<-REPORT.gsub(%r{.+\|}, '')
|
55
62
|
|
|
56
63
|
|fn = #{described_class}#{Array[*arguments]}
|
57
64
|
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module Transproc
|
2
2
|
module Deprecations
|
3
3
|
def self.announce(name, msg)
|
4
|
-
warn <<-MSG.gsub(
|
4
|
+
warn <<-MSG.gsub(%r{^\s+}, '')
|
5
5
|
#{name} is deprecated and will be removed in 1.0.0.
|
6
6
|
#{msg}
|
7
|
-
#{caller.detect { |l| !l.include?('lib/transproc')}}
|
7
|
+
#{caller.detect { |l| !l.include?('lib/transproc') } }
|
8
8
|
MSG
|
9
9
|
end
|
10
10
|
end
|
data/lib/transproc/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -4,8 +4,8 @@ describe Transproc::FunctionNotFoundError do
|
|
4
4
|
it 'complains that the function not registered globally' do
|
5
5
|
expect { Transproc(:foo) }.to raise_error do |error|
|
6
6
|
expect(error).to be_kind_of described_class
|
7
|
-
expect(error.message[
|
8
|
-
expect(error.message[
|
7
|
+
expect(error.message['foo']).not_to be_nil
|
8
|
+
expect(error.message['global']).not_to be_nil
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -14,7 +14,7 @@ describe Transproc::FunctionNotFoundError do
|
|
14
14
|
|
15
15
|
expect { Foo[:foo] }.to raise_error do |error|
|
16
16
|
expect(error).to be_kind_of described_class
|
17
|
-
expect(error.message[
|
17
|
+
expect(error.message['function Foo[:foo]']).not_to be_nil
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -31,7 +31,7 @@ describe Transproc::HashTransformations do
|
|
31
31
|
symbolize_keys = described_class.t(:symbolize_keys)
|
32
32
|
|
33
33
|
input = { 1 => 'bar' }
|
34
|
-
output = {
|
34
|
+
output = { '1'.to_sym => 'bar' }
|
35
35
|
|
36
36
|
expect(symbolize_keys[input]).to eql(output)
|
37
37
|
expect { symbolize_keys[input] }.not_to change { input }
|
@@ -46,7 +46,7 @@ describe Transproc::HashTransformations do
|
|
46
46
|
output = { foo: 'bar', baz: [{ one: 1 }, 'two'] }
|
47
47
|
|
48
48
|
expect(symbolize_keys[input]).to eql(output)
|
49
|
-
expect(input).to eql(
|
49
|
+
expect(input).to eql('foo' => 'bar', 'baz' => [{ 'one' => 1 }, 'two'])
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -121,6 +121,16 @@ describe Transproc::HashTransformations do
|
|
121
121
|
expect(map[input]).to eql(output)
|
122
122
|
expect(input).to eql('foo' => 'bar', :bar => 'baz')
|
123
123
|
end
|
124
|
+
|
125
|
+
it "only renames keys and never creates new ones" do
|
126
|
+
map = described_class.t(:rename_keys, 'foo' => :foo, 'bar' => :bar)
|
127
|
+
|
128
|
+
input = { 'bar' => 'baz' }
|
129
|
+
output = { bar: 'baz' }
|
130
|
+
|
131
|
+
expect(map[input]).to eql(output)
|
132
|
+
expect(input).to eql('bar' => 'baz')
|
133
|
+
end
|
124
134
|
end
|
125
135
|
|
126
136
|
describe '.rename_keys!' do
|
@@ -135,6 +145,59 @@ describe Transproc::HashTransformations do
|
|
135
145
|
expect(input).to eql(output)
|
136
146
|
end
|
137
147
|
end
|
148
|
+
describe '.copy_keys' do
|
149
|
+
context 'with single destination key' do
|
150
|
+
it 'returns a new hash with applied functions' do
|
151
|
+
map = described_class.t(:copy_keys, 'foo' => :foo)
|
152
|
+
|
153
|
+
input = { 'foo' => 'bar', :bar => 'baz' }
|
154
|
+
output = { 'foo' => 'bar', foo: 'bar', bar: 'baz' }
|
155
|
+
|
156
|
+
expect(map[input]).to eql(output)
|
157
|
+
expect(input).to eql('foo' => 'bar', :bar => 'baz')
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'with multiple destination keys' do
|
162
|
+
it 'returns a new hash with applied functions' do
|
163
|
+
map = described_class.t(:copy_keys, 'foo' => [:foo, :baz])
|
164
|
+
|
165
|
+
input = { 'foo' => 'bar', :bar => 'baz' }
|
166
|
+
output = { 'foo' => 'bar', foo: 'bar', baz: 'bar', bar: 'baz' }
|
167
|
+
|
168
|
+
expect(map[input]).to eql(output)
|
169
|
+
expect(input).to eql('foo' => 'bar', :bar => 'baz')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe '.copy_keys!' do
|
175
|
+
context 'with single destination key' do
|
176
|
+
it 'returns updated hash with applied functions' do
|
177
|
+
map = described_class.t(:copy_keys!, 'foo' => :foo)
|
178
|
+
|
179
|
+
input = { 'foo' => 'bar', :bar => 'baz' }
|
180
|
+
output = { 'foo' => 'bar', foo: 'bar', bar: 'baz' }
|
181
|
+
|
182
|
+
map[input]
|
183
|
+
|
184
|
+
expect(input).to eql(output)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'with multiple destination keys' do
|
189
|
+
it 'returns updated hash with applied functions' do
|
190
|
+
map = described_class.t(:copy_keys!, 'foo' => [:foo, :baz])
|
191
|
+
|
192
|
+
input = { 'foo' => 'bar', :bar => 'baz' }
|
193
|
+
output = { 'foo' => 'bar', foo: 'bar', baz: 'bar', bar: 'baz' }
|
194
|
+
|
195
|
+
map[input]
|
196
|
+
|
197
|
+
expect(input).to eql(output)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
138
201
|
|
139
202
|
describe '.map_value' do
|
140
203
|
it 'applies function to value under specified key' do
|
@@ -178,7 +241,7 @@ describe Transproc::HashTransformations do
|
|
178
241
|
|
179
242
|
describe '.nest!' do
|
180
243
|
it 'returns new hash with keys nested under a new key' do
|
181
|
-
nest = described_class.t(:nest!, :baz,
|
244
|
+
nest = described_class.t(:nest!, :baz, %w(one two not-here))
|
182
245
|
|
183
246
|
input = { 'foo' => 'bar', 'one' => nil, 'two' => false }
|
184
247
|
output = { 'foo' => 'bar', baz: { 'one' => nil, 'two' => false } }
|
@@ -291,7 +354,7 @@ describe Transproc::HashTransformations do
|
|
291
354
|
describe 'combining transformations' do
|
292
355
|
it 'applies functions to the hash' do
|
293
356
|
symbolize_keys = described_class.t(:symbolize_keys)
|
294
|
-
map = described_class.t
|
357
|
+
map = described_class.t :rename_keys, user_name: :name, user_email: :email
|
295
358
|
|
296
359
|
transformation = symbolize_keys >> map
|
297
360
|
|
@@ -477,8 +540,8 @@ describe Transproc::HashTransformations do
|
|
477
540
|
evaluate = described_class.t(:eval_values, 1)
|
478
541
|
|
479
542
|
input = {
|
480
|
-
one: 1, two: -> i { i+1 },
|
481
|
-
three: -> i { i+2 }, four: 4,
|
543
|
+
one: 1, two: -> i { i + 1 },
|
544
|
+
three: -> i { i + 2 }, four: 4,
|
482
545
|
more: [{ one: -> i { i }, two: 2 }]
|
483
546
|
}
|
484
547
|
|
@@ -495,8 +558,8 @@ describe Transproc::HashTransformations do
|
|
495
558
|
evaluate = described_class.t(:eval_values, 1, [:one, :two])
|
496
559
|
|
497
560
|
input = {
|
498
|
-
one: 1, two: -> i { i+1 },
|
499
|
-
three: -> i { i+2 }, four: 4,
|
561
|
+
one: 1, two: -> i { i + 1 },
|
562
|
+
three: -> i { i + 2 }, four: 4,
|
500
563
|
array: [{ one: -> i { i }, two: 2 }],
|
501
564
|
hash: { one: -> i { i } }
|
502
565
|
}
|
@@ -511,7 +574,7 @@ describe Transproc::HashTransformations do
|
|
511
574
|
end
|
512
575
|
|
513
576
|
describe '.deep_merge' do
|
514
|
-
let(:hash){
|
577
|
+
let(:hash) {
|
515
578
|
{
|
516
579
|
name: 'Jane',
|
517
580
|
email: 'jane@doe.org',
|
@@ -522,7 +585,7 @@ describe Transproc::HashTransformations do
|
|
522
585
|
}
|
523
586
|
}
|
524
587
|
|
525
|
-
let(:update){
|
588
|
+
let(:update) {
|
526
589
|
{
|
527
590
|
email: 'jane@example.org',
|
528
591
|
favorites:
|
@@ -534,7 +597,11 @@ describe Transproc::HashTransformations do
|
|
534
597
|
|
535
598
|
it 'recursively merges hash values' do
|
536
599
|
deep_merge = described_class.t(:deep_merge)
|
537
|
-
output = {
|
600
|
+
output = {
|
601
|
+
name: 'Jane',
|
602
|
+
email: 'jane@example.org',
|
603
|
+
favorites: { food: 'stroopwafel', color: 'orange' }
|
604
|
+
}
|
538
605
|
|
539
606
|
expect(deep_merge[hash, update]).to eql(output)
|
540
607
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Transproc::ProcTransformations do
|
4
|
+
describe '.bind' do
|
5
|
+
let(:fn) { described_class.t(:bind, binding, proc) }
|
6
|
+
let(:binding) { OpenStruct.new(prefix: prefix) }
|
7
|
+
let(:proc) { -> v { [prefix, v].join('_') } }
|
8
|
+
let(:prefix) { 'foo' }
|
9
|
+
let(:input) { 'bar' }
|
10
|
+
let(:output) { 'foo_bar' }
|
11
|
+
|
12
|
+
subject { fn[input] }
|
13
|
+
|
14
|
+
it 'binds the given proc to the specified binding' do
|
15
|
+
is_expected.to eq(output)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/unit/recursion_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe Transproc::Recursion do
|
|
9
9
|
'foo' => 'bar',
|
10
10
|
'bar' => {
|
11
11
|
'foo' => 'bar',
|
12
|
-
'bar' =>
|
12
|
+
'bar' => %w(foo bar baz),
|
13
13
|
'baz' => 'foo'
|
14
14
|
},
|
15
15
|
'baz' => 'bar'
|
@@ -23,7 +23,7 @@ describe Transproc::Recursion do
|
|
23
23
|
'foo' => 'bar',
|
24
24
|
'bar' => {
|
25
25
|
'foo' => 'bar',
|
26
|
-
'bar' =>
|
26
|
+
'bar' => %w(foo bar)
|
27
27
|
}
|
28
28
|
}
|
29
29
|
end
|
data/spec/unit/transproc_spec.rb
CHANGED
@@ -57,20 +57,4 @@ describe Transproc do
|
|
57
57
|
expect(fn.args).to include(Transproc(:to_string))
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
61
|
-
describe 'handling malformed input' do
|
62
|
-
it 'raises a Transproc::MalformedInputError' do
|
63
|
-
expect {
|
64
|
-
Transproc(:to_integer)[{}]
|
65
|
-
}.to raise_error(Transproc::MalformedInputError)
|
66
|
-
|
67
|
-
begin
|
68
|
-
Transproc(:to_integer)[{}]
|
69
|
-
rescue Transproc::MalformedInputError => e
|
70
|
-
expect(e.message).to include('to_integer')
|
71
|
-
expect(e.message).to include("undefined method `to_i'")
|
72
|
-
expect(e.backtrace).to eql(e.original_error.backtrace)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transproc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/transproc/function.rb
|
83
83
|
- lib/transproc/functions.rb
|
84
84
|
- lib/transproc/hash.rb
|
85
|
+
- lib/transproc/proc.rb
|
85
86
|
- lib/transproc/recursion.rb
|
86
87
|
- lib/transproc/registry.rb
|
87
88
|
- lib/transproc/rspec.rb
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- spec/unit/function_not_found_error_spec.rb
|
101
102
|
- spec/unit/function_spec.rb
|
102
103
|
- spec/unit/hash_transformations_spec.rb
|
104
|
+
- spec/unit/proc_transformations_spec.rb
|
103
105
|
- spec/unit/recursion_spec.rb
|
104
106
|
- spec/unit/registry_spec.rb
|
105
107
|
- spec/unit/store_spec.rb
|
@@ -140,7 +142,9 @@ test_files:
|
|
140
142
|
- spec/unit/function_not_found_error_spec.rb
|
141
143
|
- spec/unit/function_spec.rb
|
142
144
|
- spec/unit/hash_transformations_spec.rb
|
145
|
+
- spec/unit/proc_transformations_spec.rb
|
143
146
|
- spec/unit/recursion_spec.rb
|
144
147
|
- spec/unit/registry_spec.rb
|
145
148
|
- spec/unit/store_spec.rb
|
146
149
|
- spec/unit/transproc_spec.rb
|
150
|
+
has_rdoc:
|