subroutine-factory 0.1.3 → 0.1.8

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
- SHA1:
3
- metadata.gz: 11fe1b1eb2083aae444968de381654c254282479
4
- data.tar.gz: b7f47712b4f46bf5b08d4e1f34086adf1927efcc
2
+ SHA256:
3
+ metadata.gz: dc88dc64c89f0f831b0ebbe437649c866edb2ca87a58f953b355a27b453abbb0
4
+ data.tar.gz: e6671efa5cdc98c54098dc5518db9e304ce2554062b980fc60203df635e9cc15
5
5
  SHA512:
6
- metadata.gz: 114d75567ba4148cef1d798b46d39eeb619fc6e98a329cb27f19f3c6bdb7df7208d80b0e313cee61e878dd6f5388c1f6baaf41c4b41c4cda03273870f65eeed8
7
- data.tar.gz: 01a4e8da80b5b6d4490f6ad0ec3e492cd79981f42fbf1736e1af59267db5a378376694ac885ab0871a23ae259cceefbaf758602f8629c068b2a908b0b6b100b4
6
+ metadata.gz: 8fb7d4c79e01fc7fbd5459d7d145511d6cb32140da3268eef9d8b16f402bf7ff912b2b96675966426b0eafc3aaec6f4f15c4279c4cc706c7bb7d3b171e4576b5
7
+ data.tar.gz: 8fe2680a14be76556bfe8c81ffe95b3312f9c52a7d2965c1fe665edf2baed874332ceb100e16a6f6ba8700893965bc8e3a06c4807e90fb10a41bff573c10f43f
@@ -0,0 +1 @@
1
+ 2.5.1
@@ -1,4 +1,4 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.1.1
4
+ - 2.5.1
@@ -1,4 +1,7 @@
1
- require 'subroutine'
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+ require "subroutine"
2
5
  require "subroutine/factory/version"
3
6
  require "subroutine/factory/config"
4
7
  require "subroutine/factory/builder"
@@ -29,7 +32,8 @@ module Subroutine
29
32
  def self.get_config!(name)
30
33
  config = get_config(name)
31
34
  raise "Unknown Subroutine::Factory `#{name}`" unless config
32
- return config
35
+
36
+ config
33
37
  end
34
38
 
35
39
  def self.create(name, *args)
@@ -47,15 +51,48 @@ module Subroutine
47
51
 
48
52
  def self.sequence(&lambda)
49
53
  if block_given?
50
- Proc.new{
54
+ proc do |*options|
51
55
  @@sequence += 1
52
- lambda.call(@@sequence)
53
- }
56
+ lambda.call(*[@@sequence, *options].compact)
57
+ end
54
58
  else
55
59
  @@sequence += 1
56
60
  end
57
61
  end
58
62
 
63
+ def self.random(random_options = {}, &lambda)
64
+ if block_given?
65
+ proc do |*options|
66
+ x = build_random(random_options)
67
+ lambda.call(*[x, *options].compact)
68
+ end
69
+ else
70
+ build_random(random_options)
71
+ end
72
+ end
73
+
74
+ RANDOM_FUNCTION_TYPES = %i[alphanumeric numeric alpha]
75
+ ALPHAS = ("a".."z").to_a
76
+ NUMERICS = (0..9).to_a
77
+ ALPHANUMERICS = NUMERICS + ALPHAS
78
+ def self.build_random(length: 8, type: :alphanumeric)
79
+ raise ArgumentError, ":type must be one of #{RANDOM_FUNCTION_TYPES.inspect}" unless RANDOM_FUNCTION_TYPES.include?(type.to_sym)
80
+
81
+ source = (
82
+ case type.to_sym
83
+ when :alphanumeric then ALPHANUMERICS
84
+ when :numeric then NUMERICS
85
+ when :alpha then ALPHAS
86
+ end
87
+ )
88
+
89
+ length.times.inject(+"") do |memo, _i|
90
+ x = source.sample.to_s
91
+ x = x.upcase if rand(2) == 1
92
+ memo << x
93
+ end
94
+ end
95
+
59
96
  def self.set_sequence(n)
60
97
  @@sequence = n
61
98
  end
@@ -6,42 +6,70 @@ module Subroutine
6
6
 
7
7
  def initialize(config, *args)
8
8
  @config = config
9
- @options = config.options
10
- @args = args
9
+ @options = config.options.dup
10
+ @args = args.dup
11
11
  @overrides = @args.extract_options!
12
12
  end
13
13
 
14
14
  def execute!
15
- op = op_class.new(*input_args)
16
- Array(@options[:befores]).each{|block| block.call(op) }
15
+ args = @args.dup
16
+
17
+ Array(@options[:setups]).each{|block| block.call(args, extras) }
18
+
19
+ args.push(inputs)
20
+
21
+ op = op_class.new(*args)
22
+
23
+ Array(@options[:befores]).each{|block| block.call(op, extras) }
24
+
17
25
  op.submit!
26
+
18
27
  output = extract_output(op)
19
- Array(@options[:afters]).each{|block| block.call(op, output) }
28
+
29
+ Array(@options[:afters]).each{|block| block.call(op, output, extras) }
30
+
20
31
  output
21
32
  end
22
33
 
23
34
  def inputs
24
- out = {}
35
+ @inputs ||= begin
36
+ out = {}
25
37
 
26
- @options[:inputs].each_pair do |k,v|
27
- if @overrides.has_key?(k)
28
- out[k] = @overrides[k]
29
- else
30
- out[k] = v.respond_to?(:call) ? v.call : v
38
+ @options[:inputs].each_pair do |k,v|
39
+ if @overrides.has_key?(k)
40
+ out[k] = @overrides[k]
41
+ else
42
+ out[k] = invoke_input(v)
43
+ end
31
44
  end
45
+
46
+ out
32
47
  end
48
+ end
33
49
 
34
- out
50
+ def extras
51
+ @extras ||= begin
52
+ out = {}
53
+
54
+ @options[:extras].each_pair do |k, v|
55
+ if @overrides.has_key?(k)
56
+ out[k] = @overrides[k]
57
+ elsif !v.nil?
58
+ out[k] = invoke_input(v)
59
+ end
60
+ end
61
+
62
+ out
63
+ end
35
64
  end
36
65
 
37
- def input_args
38
- args = @args.dup
39
- args.push(inputs)
40
- args
66
+ def invoke_input(input)
67
+ return input unless input.respond_to?(:call)
68
+ input.arity.zero? ? input.call : input.call(extras)
41
69
  end
42
70
 
43
71
  def op_class
44
- klass = @options[:op].constantize
72
+ @options[:op].constantize
45
73
  end
46
74
 
47
75
  def extract_output(op)
@@ -5,6 +5,7 @@ module Subroutine
5
5
  class Config
6
6
 
7
7
  delegate :sequence, to: "::Subroutine::Factory"
8
+ delegate :random, to: "::Subroutine::Factory"
8
9
 
9
10
  attr_reader :options
10
11
 
@@ -35,6 +36,10 @@ module Subroutine
35
36
  end
36
37
  end
37
38
 
39
+ def setup(&block)
40
+ @options[:setups].push(block)
41
+ end
42
+
38
43
  def before(&block)
39
44
  @options[:befores].push(block)
40
45
  end
@@ -57,6 +62,10 @@ module Subroutine
57
62
  @options[:outputs] = names
58
63
  end
59
64
 
65
+ def extra(name, value = nil)
66
+ @options[:extras][name.to_sym] = value
67
+ end
68
+
60
69
  protected
61
70
 
62
71
  def inherit_from(parent)
@@ -69,15 +78,22 @@ module Subroutine
69
78
  op(@options[:op]) if @options[:op]
70
79
 
71
80
  @options[:inputs] ||= {}
72
- @options[:inputs].each_pair(&method(:input))
81
+ @options[:inputs].each_pair{|k,v| input(k, v) }
73
82
 
74
83
  outputs(*@options[:outputs]) if @options[:outputs]
75
84
  output(@options[:output]) if @options[:output]
76
85
 
86
+ @options[:setups] = @options[:setups].dup if @options[:setups]
87
+ @options[:setups] ||= []
88
+
77
89
  @options[:befores] = @options[:befores].dup if @options[:befores]
78
90
  @options[:befores] ||= []
91
+
79
92
  @options[:afters] = @options[:afters].dup if @options[:afters]
80
93
  @options[:afters] ||= []
94
+
95
+ @options[:extras] ||= {}
96
+ @options[:extras].each_pair{|k,v| extra(k,v) }
81
97
  end
82
98
 
83
99
  end
@@ -1,6 +1,7 @@
1
1
  module Subroutine
2
2
  module Factory
3
3
  module SpecHelper
4
+
4
5
  def factory(*args)
5
6
  ::Subroutine::Factory.create(*args)
6
7
  end
@@ -8,6 +9,11 @@ module Subroutine
8
9
  def factory!(*args)
9
10
  factory(*args)
10
11
  end
12
+
13
+ def factory_inputs(*args)
14
+ ::Subroutine::Factory.inputs(*args)
15
+ end
16
+
11
17
  end
12
18
  end
13
19
  end
@@ -1,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Subroutine
2
4
  module Factory
3
- VERSION = "0.1.3"
5
+
6
+ VERSION = "0.1.8"
7
+
4
8
  end
5
9
  end
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "subroutine"
31
31
  spec.add_dependency "activesupport", ">= 3.0"
32
32
 
33
- spec.add_development_dependency "bundler", "~> 1.10"
34
- spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "bundler"
34
+ spec.add_development_dependency "rake"
35
35
  spec.add_development_dependency "minitest"
36
36
  spec.add_development_dependency "minitest-reporters"
37
37
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subroutine-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-17 00:00:00.000000000 Z
11
+ date: 2020-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: subroutine
@@ -42,30 +42,30 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.10'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.10'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -102,6 +102,7 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
+ - ".ruby-version"
105
106
  - ".travis.yml"
106
107
  - Gemfile
107
108
  - LICENSE.txt
@@ -135,8 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  - !ruby/object:Gem::Version
136
137
  version: '0'
137
138
  requirements: []
138
- rubyforge_project:
139
- rubygems_version: 2.4.6
139
+ rubygems_version: 3.0.6
140
140
  signing_key:
141
141
  specification_version: 4
142
142
  summary: Test factories for ops using Subroutine Ops