subroutine-factory 0.1.4 → 0.1.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 81cef754be11e750d13eb7c4c28596cca62fa8b5
4
- data.tar.gz: a8b9814705f934709c072173a5e03d5f13ef27cf
2
+ SHA256:
3
+ metadata.gz: ac8a961666c4cbb6e6ec1b7dfd0bccfe14fe41b4dff8a42eaf70adc7bf9e4416
4
+ data.tar.gz: 721e88ff965dea9eb041503af3425f0847e0c38809a5d33aacd908c6ed460c79
5
5
  SHA512:
6
- metadata.gz: bd3bc62356f10cf94064ea850bd1fca0fc0b499b4b4d5b61fd4b668bad7fa221a16d0eee6326b387dc10e61297ef6a0ca7f7419ea981ce6ca22c1c1cecab663c
7
- data.tar.gz: 540ffe7d99d9f80cec753b61dfae8637e93be7393b449ff0481a1c2dd59d7cb440e153f9ae173528f730dc5d2a8f954be13be63142e608cf07d42bf72461c666
6
+ metadata.gz: 8b171d7040b5453038b81f956a35163d5b38daef03e15e0b49c9d828f6530bc011772a0a8551fbb2702ef37d0789e1fba4c0f048fa9b702354d215d7ebd76de4
7
+ data.tar.gz: c278fbf850b74c8839c596c920707676dab0ef4ce8bf636c6636998a9466a789c8b4afa4f89b348bea3d2372565def0f5e6d173bbe9e2cebc8d55ea633334e6c
@@ -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,47 @@ 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
+ memo << x
92
+ end
93
+ end
94
+
59
95
  def self.set_sequence(n)
60
96
  @@sequence = n
61
97
  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,5 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Subroutine
2
4
  module Factory
3
- VERSION = "0.1.4"
5
+
6
+ VERSION = "0.1.9"
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.4
4
+ version: 0.1.9
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