tasking 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: f3d84bc5f691b364727b241743fb800bf6d571ac3885461124081e959fc6ac78
4
- data.tar.gz: cd7411408417cd0942ba17e66ce38c3f707b4d76ca4f7171027b07bc670ce2cc
3
+ metadata.gz: 4981b897e547aedf77da48a0f5a2f89c5448fd299470279ffda024a5289233e4
4
+ data.tar.gz: d28311cbd4a57f46fe4be001db419bc292b0978d78eca671b620ab0aae2517c7
5
5
  SHA512:
6
- metadata.gz: d4efa63e1c58b9dac0997f1ff46ba067bcb724c052bbba2f221fde224f12e4f83983e3b56fab1e1a4c91759cfd76d5fc64f431fb0d45c671878f01ef5b3d7404
7
- data.tar.gz: 7f25bef3273737f3655809b5af02268c88dc57bbbf1f70e67deca30cf21669584ed6161e02634839f6f0b8b23cbd59975da455fca0126341cd29e144b21ce143
6
+ metadata.gz: c88afa523ba6e423767229752cf1c43d2b1f9712e3b6617d561525c69a9dc9e023afaaf11af7ee26939b5e21ef1878920d7817141dcd080297e17219ac612b6e
7
+ data.tar.gz: 493bae7a0ace2c82abe526e6b8a9f13072313a99ca15b8dc1783c321bfbbe62052844c22d23ee91b35287f5d514ac3dbad54eb9ad29c32e41cd3c9b306b32c69
@@ -130,7 +130,7 @@ module Tasking
130
130
  end
131
131
 
132
132
  def gather_options_for( full_task_name, task )
133
- final_options = {}
133
+ final_options = Tasking::Options.new({})
134
134
 
135
135
  walk_namespace_tree_to( full_task_name, :task ) do |ns_name|
136
136
  namespace = Tasking::Namespace.find_namespace( ns_name )
@@ -159,5 +159,6 @@ module Tasking
159
159
  end
160
160
  end
161
161
 
162
+ require_relative 'tasking/options'
162
163
  require_relative 'tasking/namespace'
163
164
  require_relative 'tasking/task'
@@ -37,7 +37,7 @@ module Tasking
37
37
  def initialize( name, options = {} )
38
38
  @tasks = {}
39
39
  @name = name
40
- @options = options
40
+ @options = Options.build( options )
41
41
 
42
42
  self.class.add_namespace( self )
43
43
  end
@@ -54,7 +54,7 @@ module Tasking
54
54
 
55
55
  def execute( options = {}, &block )
56
56
  @options.merge!( options )
57
- block.call if block
57
+ block&.call
58
58
  end
59
59
 
60
60
  def merge_options( options )
@@ -0,0 +1,48 @@
1
+ module Tasking
2
+ class Options
3
+ attr_reader :options_hash
4
+
5
+ def self.build( options )
6
+ return options if options.is_a?( self )
7
+
8
+ new( options )
9
+ end
10
+
11
+ def initialize(hash)
12
+ @options_hash = hash
13
+ end
14
+
15
+ def [](key)
16
+ resolve_value( options_hash[key] )
17
+ end
18
+
19
+ def merge(other)
20
+ self.class.new( options_hash.merge( extract_options_hash( other ) ) )
21
+ end
22
+
23
+ def merge!(other)
24
+ options_hash.merge!( extract_options_hash( other ) )
25
+ self
26
+ end
27
+
28
+ def ==(other)
29
+ options_hash == extract_options_hash( other )
30
+ end
31
+
32
+ def materialized_hash
33
+ options_hash.map do |key, value|
34
+ [ key, resolve_value( value ) ]
35
+ end.to_h
36
+ end
37
+
38
+ private
39
+
40
+ def resolve_value( value )
41
+ value.respond_to?( :call ) ? value.call( self ) : value
42
+ end
43
+
44
+ def extract_options_hash(other)
45
+ other.is_a?( self.class ) ? other.options_hash : other
46
+ end
47
+ end
48
+ end
@@ -6,7 +6,7 @@ module Tasking
6
6
  def initialize( name, parent_namespace, options = {}, &block )
7
7
  @name = name
8
8
  @parent_namespace = parent_namespace
9
- @options = options
9
+ @options = Options.build( options )
10
10
  @block = block
11
11
  @before_filters = []
12
12
  @after_filters = []
@@ -23,21 +23,17 @@ module Tasking
23
23
  def execute( options = {} )
24
24
  total_options = @options.merge( options )
25
25
  execute_task_chain( before_filters, total_options, "Unknown before task '%s' for task '#{@name}'" )
26
- @block.call( resolve_options( total_options ) ) if @block
26
+ block&.call( total_options )
27
27
  execute_task_chain( after_filters, total_options, "Unknown after task '%s' for task '#{@name}'" )
28
28
  end
29
29
 
30
30
  private
31
31
 
32
- def resolve_options(options)
33
- options.transform_values { |v| v.respond_to?(:call) ? v.call(options) : v }
34
- end
35
-
36
32
  def execute_task_chain( tasks, options, fail_message )
37
33
  tasks.each do |t|
38
34
  task = task_lookup( t )
39
35
  abort( fail_message % t ) unless task
40
- task.execute(options)
36
+ task.execute( options )
41
37
  end
42
38
  end
43
39
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tasking
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Riedel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-01 00:00:00.000000000 Z
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -62,6 +62,7 @@ files:
62
62
  - bin/tasking
63
63
  - lib/tasking.rb
64
64
  - lib/tasking/namespace.rb
65
+ - lib/tasking/options.rb
65
66
  - lib/tasking/task.rb
66
67
  homepage: https://github.com/sriedel/tasking
67
68
  licenses:
@@ -82,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
83
  - !ruby/object:Gem::Version
83
84
  version: '0'
84
85
  requirements: []
85
- rubygems_version: 3.0.3
86
+ rubygems_version: 3.1.2
86
87
  signing_key:
87
88
  specification_version: 4
88
89
  summary: A lightweight task runner DSL