subroutine 0.5.1 → 0.5.2

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: 3acb651d981b9e158e41c5e36b9fcf2fc644fb51
4
- data.tar.gz: ff3571355496f5202702a26ab935a1d7944c73a3
3
+ metadata.gz: a1bc6198e47ce610c393d061ea8d657d9fbaed30
4
+ data.tar.gz: d51c78f5328d91119eb2ec1c252383645d8e9485
5
5
  SHA512:
6
- metadata.gz: e651e0bbbcb6a355d6f07613becee56d67c08b7016b72660cda62608956a0b7db58006ed8ff45b58346ec827b02b8af2d1b2b6ad191d55ccb42c9935f24a4dff
7
- data.tar.gz: 9fbb7f7d91c60a1c71ac4a965179efd9f45a665e93bc9c9bfb70da2ef0d07d06cdebeb2ef3526f968477c71c7eaa4515b20c097aa5bf66d8cdbd5141150a11f9
6
+ metadata.gz: 265862ad55b33f9c16ab8665666d870480d7297c095dcd9a387e86d8c4a7ff81b512cae2a2cfbaea57eda3ffff134c4a943b6bf1835a2508a59be11661fd4e0c
7
+ data.tar.gz: e4b8325a9f266f14bf1915ca05080e74d3e7361a759433997e4f4d602df8ed5a63707933e0e636b741868bbd9d1443cfea004a1080176faf4f5ca69b4883a40e
data/lib/subroutine/op.rb CHANGED
@@ -72,13 +72,20 @@ module Subroutine
72
72
  alias_method :ignore_errors, :ignore_error
73
73
 
74
74
  def inputs_from(*ops)
75
+ options = ops.extract_options!
76
+ excepts = options.key?(:except) ? Array(options.delete(:except)) : nil
77
+ onlys = options.key?(:only) ? Array(options.delete(:only)) : nil
78
+
75
79
  ops.each do |op|
76
- op._fields.each_pair do |field_name, options|
77
- if options[:association]
80
+ op._fields.each_pair do |field_name, op_options|
81
+ next if excepts && excepts.include?(field_name)
82
+ next if onlys && !onlys.include?(field_name)
83
+
84
+ if op_options[:association]
78
85
  include ::Subroutine::Association unless included_modules.include?(::Subroutine::Association)
79
- association(field_name, options)
86
+ association(field_name, op_options)
80
87
  else
81
- field(field_name, options)
88
+ field(field_name, op_options)
82
89
  end
83
90
  end
84
91
  end
@@ -2,7 +2,7 @@ module Subroutine
2
2
 
3
3
  MAJOR = 0
4
4
  MINOR = 5
5
- PATCH = 1
5
+ PATCH = 2
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
@@ -33,6 +33,20 @@ module Subroutine
33
33
  end
34
34
  end
35
35
 
36
+ def test_inputs_from_ignores_except_fields
37
+ op = ::ExceptFooBarOp.new
38
+ refute op._fields.keys.include? :foo
39
+ refute op._fields.keys.include? :bar
40
+ assert_equal [:baz], op._fields.keys.sort
41
+ end
42
+
43
+ def test_inputs_from_only_fields
44
+ op = ::OnlyFooBarOp.new
45
+ assert op._fields.keys.include? :foo
46
+ assert op._fields.keys.include? :bar
47
+ refute_equal [:baz], op._fields.keys.sort
48
+ end
49
+
36
50
  def test_defaults_declaration_options
37
51
  op = ::DefaultsOp.new
38
52
  assert_equal 'foo', op.foo
data/test/support/ops.rb CHANGED
@@ -92,6 +92,14 @@ class DefaultsOp < ::Subroutine::Op
92
92
 
93
93
  end
94
94
 
95
+ class ExceptFooBarOp < ::Subroutine::Op
96
+ inputs_from ::DefaultsOp, except: %i[foo bar]
97
+ end
98
+
99
+ class OnlyFooBarOp < ::Subroutine::Op
100
+ inputs_from ::DefaultsOp, only: %i[foo bar]
101
+ end
102
+
95
103
  class InheritedDefaultsOp < ::DefaultsOp
96
104
 
97
105
  field :bar, :default => 'barstool'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subroutine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-02 00:00:00.000000000 Z
11
+ date: 2017-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel