conformist 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7d066dfeac09134316436b908aae6722cc6f605
4
- data.tar.gz: b3e9cfd42875b40279b380fc88558cf54636af67
3
+ metadata.gz: 522d7fcbc544f4bfc13ffbf3dc5a5b17a722de88
4
+ data.tar.gz: 6cfbcc1646ffae7f81add151b478a85ec0b35f57
5
5
  SHA512:
6
- metadata.gz: a4612f7cad313a5d199b34e12ecb0a1191eaa296463d251fd9258ea941e501edcc8476d2f78a82da98e778f15470120d47d88346bf2529835c4f5bf37fbe22be
7
- data.tar.gz: 8e53fb246d2beb4eb1f138c5aafd04b7e36cc9f30194c83cfa94babbc9b6fbc42494108dd94d15a52a9c18aa0110c1e62455be50a1705a25eb747c2babc5351c
6
+ metadata.gz: c55cf94d0a0d3d759dcbc4520407182ed9900593b76e2343333c2b49e53d403ccd56214f4667a8905d3c469addd1d856c2d3b2a5a0407653986b45a4f1fa3c44
7
+ data.tar.gz: becc47e0d07e3547d751eb8501d4f5f56f6068337b88e2af5843b749059b7409e3599a2ac153dea58ef6ca56f7f98c28fe83ecbbbb690c9960f51c2fc3dc786f
@@ -5,6 +5,7 @@ rvm:
5
5
  - 2.1.0
6
6
  - 2.2.0
7
7
  - 2.3.1
8
+ - 2.4.0
8
9
  - jruby
9
10
 
10
11
  before_install:
@@ -1,5 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.5 / 2017-01-31
4
+
5
+ * Add support for context. (@jcmfernandes)
6
+ * Official support for Ruby 2.4.0.
7
+
3
8
  ## 0.2.4 / 2016-10-14
4
9
 
5
10
  * Speed up processing large amounts of columns (@splattael)
data/README.md CHANGED
@@ -262,6 +262,18 @@ column :first_name, 0 do |value|
262
262
  end
263
263
  ```
264
264
 
265
+ It's also possible to provide a context object that is made available during preprocessing.
266
+
267
+ ``` ruby
268
+ citizen = Conformist.new do
269
+ column :name, 0, 1 do |values, context|
270
+ (context[:upcase?] ? values.map(&:upcase) : values) * ' '
271
+ end
272
+ end
273
+
274
+ citizen.conform [['tate', 'johnson']], context: {upcase?: true}
275
+ ```
276
+
265
277
  ### Virtual Columns
266
278
 
267
279
  Virtual columns are not sourced from input. Omit the index to create a virtual column. Like real columns, virtual columns are included in the conformed output.
@@ -346,7 +358,7 @@ See CHANGELOG.md for a full list of changes.
346
358
 
347
359
  ## Compatibility
348
360
 
349
- * MRI 2.3.1, 2.2.0, 2.1.0, 2.0.0, 1.9.3
361
+ * MRI 2.4.0, 2.3.1, 2.2.0, 2.1.0, 2.0.0, 1.9.3
350
362
  * JRuby
351
363
 
352
364
  ## Dependencies
@@ -1,9 +1,9 @@
1
1
  module Conformist
2
2
  class Builder
3
- def self.call schema, enumerable
3
+ def self.call schema, enumerable, context = nil
4
4
  columns = schema.columns
5
5
  hash = columns.each_with_object({}) do |column, hash|
6
- hash[column.name] = column.values_in(enumerable)
6
+ hash[column.name] = column.values_in(enumerable, context)
7
7
  end
8
8
  HashStruct.new hash
9
9
  end
@@ -21,7 +21,7 @@ module Conformist
21
21
  end
22
22
  end
23
23
 
24
- def values_in enumerable
24
+ def values_in enumerable, context = nil
25
25
  enumerable = Array(enumerable)
26
26
 
27
27
  values = Array(indexes).map do |index|
@@ -35,7 +35,11 @@ module Conformist
35
35
  end
36
36
  values = values.first if values.size == 1
37
37
  if preprocessor
38
- preprocessor.call values
38
+ if preprocessor.arity == 1
39
+ preprocessor.call values
40
+ else
41
+ preprocessor.call values, context
42
+ end
39
43
  else
40
44
  values
41
45
  end
@@ -53,6 +53,7 @@ module Conformist
53
53
 
54
54
  def conform enumerables, options = {}
55
55
  options = options.dup
56
+ context = options.delete(:context)
56
57
 
57
58
  Enumerator.new do |yielder|
58
59
  enumerables.each do |enumerable|
@@ -61,7 +62,7 @@ module Conformist
61
62
  next
62
63
  end
63
64
 
64
- yielder.yield builder.call(self, enumerable)
65
+ yielder.yield builder.call(self, enumerable, context)
65
66
  end
66
67
  end
67
68
  end
@@ -1,3 +1,3 @@
1
1
  module Conformist
2
- VERSION = '0.2.4'
2
+ VERSION = '0.2.5'
3
3
  end
@@ -4,9 +4,9 @@ class Conformist::BuilderTest < Minitest::Test
4
4
  def test_call
5
5
  column = Minitest::Mock.new
6
6
  column.expect :name, :a
7
- column.expect :values_in, [1], [Array]
7
+ column.expect :values_in, [1], [Array, Hash]
8
8
  definition = Minitest::Mock.new
9
9
  definition.expect :columns, [column]
10
- assert_equal HashStruct.new({:a => [1]}), Builder.call(definition, [])
10
+ assert_equal HashStruct.new({:a => [1]}), Builder.call(definition, [], {})
11
11
  end
12
12
  end
@@ -50,4 +50,16 @@ class Conformist::ColumnTest < Minitest::Test
50
50
  column = Column.new :foo, 0
51
51
  assert_nil column.values_in([])
52
52
  end
53
+
54
+ def test_passes_context
55
+ context = {'a' => 'b'}
56
+ column = Column.new(:foo, 0) { |_, ctx| ctx }
57
+ assert_equal context, column.values_in([], context)
58
+ end
59
+
60
+ def test_respects_preprocessor_arity
61
+ context = {'a' => 'b'}
62
+ column = Column.new(:foo, 0, &lambda { |values| })
63
+ column.values_in([], context)
64
+ end
53
65
  end
@@ -26,7 +26,7 @@ class Conformist::SchemaTest < Minitest::Test
26
26
  definition = Class.new { extend Schema }
27
27
  definition.builder = Object
28
28
  assert_equal Object, definition.builder
29
- end
29
+ end
30
30
 
31
31
  def test_columns_reader
32
32
  assert_empty Class.new { extend Schema }.columns
@@ -66,7 +66,7 @@ class Conformist::SchemaTest < Minitest::Test
66
66
 
67
67
  def test_conform_calls_builders_call_method
68
68
  definition = Class.new { extend Schema }
69
- definition.builder = lambda { |definition, value| value }
69
+ definition.builder = lambda { |definition, value, context| value }
70
70
  assert_equal [2, 4], definition.conform([1, 2]).map { |value| value * 2 }
71
71
  end
72
72
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conformist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tate Johnson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-14 00:00:00.000000000 Z
11
+ date: 2017-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest