singularity_dsl 2.2.2 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTYwMDQ2MDU3YjIwYjZjMWY3YzRmNTAyOGE0ZjNkZDIzMjJjYTVlZg==
4
+ NzcwOGJhZDM1OTA0YjZhM2QxOGVkMjdlNDAzOGY2YTFhOWVhMDUxZg==
5
5
  data.tar.gz: !binary |-
6
- ZjhhOWM5NjgxMzE0NmM5ZTUyNWI0ODJiMDBkYTg3N2JmZDZhM2UyMg==
6
+ OTY4NTVlZTEzMGE3Zjc0NjZjYWIwZDg0ZGQ4MzM0NWVjNTFhZmZmYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDIzMWMxY2ZkMTUxYzJhMzczZGE2MTVjYWY5MTNlNGY1N2JhOWVhNWU2MjVk
10
- Y2U3ZmY4OTM1ZGM3YzVmMDdjYmQ3NTI0M2MwNTdmYmY1NjcyZDE5YzFjYWUw
11
- NDBlYjBmYTFiYmU0OTQ3OTg3NzIzMzMxMmRkYmQ5NWMzNzdjNWY=
9
+ MmY5ZjgyOTY0ODg0YjgzNWRiZDk5MDQ2MmQ0YmI1NTk3ZTBiZmNlYzkzZGIz
10
+ ZWQ4ZjhiMGZhMmZjNGIwNzllYjE3ZGQwMDFkZGM1MTI4MGZjZDhkZTZlMjY0
11
+ ZTQxYmU0ZDI4NDlhMTUyNjRjNTQ0M2U2OGE4ZTUwNGM2ZmU1YzI=
12
12
  data.tar.gz: !binary |-
13
- NzI1ZWFmZjI3NGM5YjY3NzM5N2NiMDgyZDUxZjY0YTU1M2U4ZDlmY2FhODky
14
- NzZhYWY4NGMzYmNlOTkzZTU4OWI3ZDYzMmZlMWJkNjJkYWU0YjdhYWMxMzhi
15
- MGQ1MTExMGY0MzQzMDA5Yzc3ZTJjYTVlMjhkNWZlYzFiYzRkYzE=
13
+ YjE0MzQ0MmIwZGVkM2Y3M2NmNDEzNTU2MzBkZjQyOWRlNzFmNWI3OWZlMjgx
14
+ YzI4YzRiNWU2OTFjYWRjNzc1OWU1NGNjODUyZTU1ODFjZTIxNGIyY2Q0YWQ0
15
+ YzE1MWNlZWU4NzFlOWYxYjUzZDE2MTY0ZTUzY2VmYzY4ODg5YjI=
data/.singularityrc CHANGED
@@ -2,13 +2,22 @@
2
2
 
3
3
  batch :test do
4
4
  rubocop
5
- bootcoveralls if flag? 'coveralls'
5
+ bootcoveralls { pr ENV.fetch('PULL', nil) } if flag? 'coveralls'
6
6
  rspec
7
7
  end
8
8
 
9
+ batch :callback_integration do
10
+ rubocop
11
+ on_fail { fail 'fail callback' }
12
+ on_error { fail 'error callback' }
13
+ on_success { rspec }
14
+ always { puts 'Callback Integrations seem ok!' }
15
+ end
16
+
9
17
  batch :ci do
10
18
  shelltask { command 'bundle install --path ./vendor' }
11
19
  shelltask { command 'bundle exec singularity_runner batch test --flags coveralls' }
20
+ shelltask { command 'bundle exec singularity_runner batch callback_integration' }
12
21
  end
13
22
 
14
23
  invoke_batch :test
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- singularity_dsl (2.2.2)
4
+ singularity_dsl (3.0.0)
5
5
  coveralls (~> 0.8.0)
6
6
  json (~> 1.0)
7
7
  mixlib-shellout (~> 2.0)
@@ -49,16 +49,16 @@ GEM
49
49
  rspec-core (~> 3.2.0)
50
50
  rspec-expectations (~> 3.2.0)
51
51
  rspec-mocks (~> 3.2.0)
52
- rspec-core (3.2.2)
52
+ rspec-core (3.2.3)
53
53
  rspec-support (~> 3.2.0)
54
- rspec-expectations (3.2.0)
54
+ rspec-expectations (3.2.1)
55
55
  diff-lcs (>= 1.2.0, < 2.0)
56
56
  rspec-support (~> 3.2.0)
57
57
  rspec-mocks (3.2.1)
58
58
  diff-lcs (>= 1.2.0, < 2.0)
59
59
  rspec-support (~> 3.2.0)
60
60
  rspec-support (3.2.2)
61
- rubocop (0.29.1)
61
+ rubocop (0.30.0)
62
62
  astrolabe (~> 1.3)
63
63
  parser (>= 2.2.0.1, < 3.0)
64
64
  powerpack (~> 0.1)
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require 'singularity_dsl/dsl/dsl'
3
4
  require 'singularity_dsl/dsl/runner'
4
5
  require 'singularity_dsl/errors'
5
6
  require 'rainbow'
@@ -12,20 +13,21 @@ module SingularityDsl
12
13
  attr_reader :runner, :dsl
13
14
 
14
15
  def initialize
16
+ @dsl = Dsl::Dsl.new
15
17
  @runner = Dsl::Runner.new
16
18
  end
17
19
 
18
20
  def load_script(script)
19
- @runner.load_ex_script script
21
+ dsl.load_ex_script script
20
22
  end
21
23
 
22
24
  def load_tasks(path)
23
- @runner.dsl.load_tasks_in_path path
25
+ dsl.load_tasks_in_path path
24
26
  end
25
27
 
26
28
  def run(batch = false, pass_errors = false)
27
29
  begin
28
- @runner.execute batch, pass_errors
30
+ @runner.execute dsl, batch, pass_errors
29
31
  # resource failed, :all_tasks not specified
30
32
  rescue ResourceFail => failure
31
33
  log_resource_fail failure
@@ -41,13 +43,13 @@ module SingularityDsl
41
43
  def post_task_runner_actions
42
44
  script_warn @runner.state.failures if @runner.state.failed
43
45
  script_error @runner.state.errors if @runner.state.error
44
- @runner.post_actions
46
+ @runner.post_actions(dsl)
45
47
  end
46
48
 
47
49
  def change_list(list)
48
50
  list = [*list]
49
51
  list.sort!
50
- @runner.dsl.changeset = list
52
+ dsl.changeset = list
51
53
  end
52
54
 
53
55
  private
@@ -46,8 +46,8 @@ module SingularityDsl
46
46
  flags.each do |pair|
47
47
  key = pair.split(':', 2).first
48
48
  val = pair.split(':', 2).last
49
- app.runner.dsl.flag key if key == val
50
- app.runner.dsl.flag key, val unless key == val
49
+ app.dsl.flag key if key == val
50
+ app.dsl.flag key, val unless key == val
51
51
  end
52
52
  end
53
53
  end
@@ -11,9 +11,8 @@ module SingularityDsl
11
11
  # DSL classes & fxs
12
12
  module Dsl
13
13
  # wrapper for DSL
14
- class Dsl
14
+ class Dsl < EventStore
15
15
  include Changeset
16
- include EventStore
17
16
  include Files
18
17
  include Utils
19
18
 
@@ -26,6 +25,16 @@ module SingularityDsl
26
25
  load_tasks_in_path default_task_dir
27
26
  end
28
27
 
28
+ def load_ex_proc(&block)
29
+ @registry = Registry.new
30
+ instance_eval(&block)
31
+ end
32
+
33
+ def load_ex_script(path)
34
+ @registry = Registry.new
35
+ instance_eval(::File.read path)
36
+ end
37
+
29
38
  def define_task(klass)
30
39
  raise_task_def_error klass if task_defined klass
31
40
  # because define_method is private
@@ -4,30 +4,30 @@ module SingularityDsl
4
4
  # DSL classes & fxs
5
5
  module Dsl
6
6
  # default methods to for DSL objects
7
- module EventStore
8
- attr_reader :error_proc, :fail_proc, :success_proc, :always_proc
7
+ class EventStore
8
+ attr_reader :error_procs, :fail_procs, :success_procs, :always_procs
9
9
 
10
10
  def initialize
11
- @error_proc = proc {}
12
- @fail_proc = proc {}
13
- @success_proc = proc {}
14
- @always_proc = proc {}
11
+ @error_procs = []
12
+ @fail_procs = []
13
+ @success_procs = []
14
+ @always_procs = []
15
15
  end
16
16
 
17
17
  def on_error(&block)
18
- @error_proc = Proc.new(&block)
18
+ @error_procs << ::Proc.new(&block)
19
19
  end
20
20
 
21
21
  def on_fail(&block)
22
- @fail_proc = Proc.new(&block)
22
+ @fail_procs << ::Proc.new(&block)
23
23
  end
24
24
 
25
25
  def on_success(&block)
26
- @success_proc = Proc.new(&block)
26
+ @success_procs << ::Proc.new(&block)
27
27
  end
28
28
 
29
29
  def always(&block)
30
- @always_proc = Proc.new(&block)
30
+ @always_procs << ::Proc.new(&block)
31
31
  end
32
32
  end
33
33
  end
@@ -12,15 +12,15 @@ module SingularityDsl
12
12
  class Runner
13
13
  include SingularityDsl::Errors
14
14
 
15
- attr_reader :state, :dsl
15
+ attr_reader :state
16
16
 
17
17
  def initialize
18
- @dsl = Dsl.new
19
18
  @state = Runstate.new
20
19
  end
21
20
 
22
- def execute(batch = false, pass_errors = false)
23
- @dsl.registry.run_list(batch).each do |task|
21
+ def execute(dsl = nil, batch = false, pass_errors = false)
22
+ dsl ||= null_dsl
23
+ dsl.registry.run_list(batch).each do |task|
24
24
  task.execute.tap do |status|
25
25
  failed = task.failed_status status
26
26
  record_failure task if failed
@@ -29,18 +29,39 @@ module SingularityDsl
29
29
  end
30
30
  end
31
31
 
32
- def load_ex_script(path)
33
- @dsl.instance_eval(::File.read path)
32
+ def post_actions(dsl = nil)
33
+ dsl ||= null_dsl
34
+ trigger_events(dsl.error_procs, dsl) if error?
35
+ trigger_events(dsl.fail_procs, dsl) if failed?
36
+ trigger_events(dsl.success_procs, dsl) if success?
37
+ trigger_events(dsl.always_procs, dsl)
34
38
  end
35
39
 
36
- def post_actions
37
- @dsl.error_proc.call if @state.error
38
- @dsl.fail_proc.call if @state.failed
39
- @dsl.success_proc.call unless @state.failed || @state.error
40
- @dsl.always_proc.call
40
+ private
41
+
42
+ def error?
43
+ @state.error
41
44
  end
42
45
 
43
- private
46
+ def failed?
47
+ @state.failed
48
+ end
49
+
50
+ def success?
51
+ !(@state.failed || @state.error)
52
+ end
53
+
54
+ def null_dsl
55
+ @dsl ||= Dsl::Dsl.new
56
+ end
57
+
58
+ def trigger_events(procs, context_dsl = nil)
59
+ context_dsl ||= null_dsl
60
+ procs.each do |p|
61
+ context_dsl.load_ex_proc(&p)
62
+ execute context_dsl
63
+ end
64
+ end
44
65
 
45
66
  def record_failure(task)
46
67
  failure = klass_failed(task)
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version const for gem
4
4
  module SingularityDsl
5
- VERSION = '2.2.2'
5
+ VERSION = '3.0.0'
6
6
  end
@@ -14,7 +14,7 @@ describe 'Application' do
14
14
  context '#load_script' do
15
15
  it 'just calls runner.load_ex_script' do
16
16
  stub_res = 'spooooooky ghooooost'
17
- allow(app.runner).to(receive(:load_ex_script).and_return stub_res)
17
+ allow(app.dsl).to(receive(:load_ex_script).and_return stub_res)
18
18
  expect(app.load_script 'dummy').to eql stub_res
19
19
  end
20
20
  end
@@ -29,6 +29,52 @@ describe 'Dsl' do
29
29
  end
30
30
  end
31
31
 
32
+ context '#load_ex_proc' do
33
+ let(:test_proc) { ::Proc.new { flag 'load_ex_proc_flag' } }
34
+ let(:registry_double) { double 'SingularityDsl::Dsl::Registry_DOUBLE' }
35
+
36
+ it 'instance_evals block' do
37
+ expect(dsl).to receive(:flag).with('load_ex_proc_flag')
38
+ dsl.load_ex_proc(&test_proc)
39
+ end
40
+
41
+ it 'wipes the existing task registry' do
42
+ expect(dsl.registry).to_not eql registry_double
43
+
44
+ allow(SingularityDsl::Dsl::Registry).to receive(:new)
45
+ .and_return(registry_double)
46
+
47
+ dsl.load_ex_proc(&test_proc)
48
+
49
+ expect(dsl.registry).to eql registry_double
50
+ end
51
+ end
52
+
53
+ context '#load_ex_script' do
54
+ let(:test_proc) { ::Proc.new {} }
55
+ let(:registry_double) { double 'SingularityDsl::Dsl::Registry_DOUBLE' }
56
+
57
+ it 'instance_evals contents of a file' do
58
+ allow(::File).to receive(:read).and_return('0')
59
+ expect(dsl).to receive(:instance_eval).with('0')
60
+ dsl.load_ex_script 'foo'
61
+ end
62
+
63
+ it 'wipes the existing task registry' do
64
+ expect(dsl.registry).to_not eql registry_double
65
+
66
+ allow(::File).to receive(:read).and_return('0')
67
+ allow(SingularityDsl::Dsl::Registry).to receive(:new)
68
+ .and_return(registry_double)
69
+
70
+ expect(dsl).to receive(:instance_eval).with('0')
71
+
72
+ dsl.load_ex_script 'foo'
73
+
74
+ expect(dsl.registry).to eql registry_double
75
+ end
76
+ end
77
+
32
78
  context '#load_tasks_in_path' do
33
79
  it 'does not load tasks that have already been required' do
34
80
  path = ::File.dirname(__FILE__) + '/../../lib/singularity_dsl/tasks'
@@ -2,43 +2,38 @@
2
2
 
3
3
  require 'singularity_dsl/dsl/event_store'
4
4
 
5
- # container to include DslEventStore
6
- class EventStoreTest
7
- include SingularityDsl::Dsl::EventStore
8
- end
9
-
10
5
  describe 'DslEventStore' do
11
- let(:instance) { EventStoreTest.new }
6
+ let(:instance) { SingularityDsl::Dsl::EventStore.new }
12
7
 
13
8
  context '#on_error' do
14
- it 'creates an error_proc' do
15
- expect(instance.error_proc).to be_a_kind_of Proc
9
+ it 'creates an array of error_procs' do
10
+ expect(instance.error_procs).to be_a_kind_of Array
16
11
  instance.on_error {}
17
- expect(instance.error_proc).to be_a_kind_of Proc
12
+ expect(instance.error_procs.first).to be_a_kind_of Proc
18
13
  end
19
14
  end
20
15
 
21
16
  context '#on_fail' do
22
- it 'creates an fail_proc' do
23
- expect(instance.fail_proc).to be_a_kind_of Proc
17
+ it 'creates an array of fail_procs' do
18
+ expect(instance.fail_procs).to be_a_kind_of Array
24
19
  instance.on_fail {}
25
- expect(instance.fail_proc).to be_a_kind_of Proc
20
+ expect(instance.fail_procs.first).to be_a_kind_of Proc
26
21
  end
27
22
  end
28
23
 
29
24
  context '#on_success' do
30
- it 'creates an error_proc' do
31
- expect(instance.success_proc).to be_a_kind_of Proc
25
+ it 'creates an array of success_procs' do
26
+ expect(instance.success_procs).to be_a_kind_of Array
32
27
  instance.on_success {}
33
- expect(instance.success_proc).to be_a_kind_of Proc
28
+ expect(instance.success_procs.first).to be_a_kind_of Proc
34
29
  end
35
30
  end
36
31
 
37
32
  context '#always' do
38
- it 'creates an error_proc' do
39
- expect(instance.always_proc).to be_a_kind_of Proc
33
+ it 'creates an array of procs to always execute' do
34
+ expect(instance.always_procs).to be_a_kind_of Array
40
35
  instance.always {}
41
- expect(instance.always_proc).to be_a_kind_of Proc
36
+ expect(instance.always_procs.first).to be_a_kind_of Proc
42
37
  end
43
38
  end
44
39
  end
@@ -6,34 +6,84 @@ require 'singularity_dsl/runstate'
6
6
  require 'singularity_dsl/task'
7
7
 
8
8
  describe 'DslRunner' do
9
+ let!(:dsl) { SingularityDsl::Dsl::Dsl.new }
10
+ let!(:registry) { double('registry double') }
9
11
  let(:runner) { SingularityDsl::Dsl::Runner.new }
10
12
 
13
+ before :each do
14
+ allow(dsl).to receive(:registry).and_return(registry)
15
+ end
16
+
11
17
  context '#initialize' do
12
18
  it 'creates base state' do
13
19
  expect(runner.state).to be_kind_of SingularityDsl::Runstate
14
20
  end
15
-
16
- it 'creates base DSL' do
17
- expect(runner.dsl).to be_kind_of SingularityDsl::Dsl::Dsl
18
- end
19
21
  end
20
22
 
21
23
  context '#execute' do
22
24
  it 'taps & evaluates failed task.execute statuses correctly' do
23
25
  task = SingularityDsl::Task.new
24
26
  allow(task).to receive(:execute).and_return(true)
25
- allow(runner.dsl.registry).to receive(:run_list).and_return([task])
27
+ allow(dsl.registry).to receive(:run_list).and_return([task])
26
28
  expect(runner).to receive(:record_failure).with task
27
29
  expect(runner).to receive(:resource_fail).with task
28
- runner.execute
30
+ runner.execute dsl
29
31
  end
30
32
  end
31
33
 
32
- context '#load_ex_script' do
33
- it 'instance_evals contents of a file' do
34
- allow(::File).to receive(:read).and_return('0')
35
- expect(runner.dsl).to receive(:instance_eval).with('0')
36
- runner.load_ex_script 'foo'
34
+ context '#post_actions' do
35
+ let(:always_proc) { ::Proc.new { always_method } }
36
+ let(:error_proc) { ::Proc.new { error_method } }
37
+ let(:fail_proc) { ::Proc.new { fail_method } }
38
+ let(:success_proc) { ::Proc.new { success_method } }
39
+
40
+ before :each do
41
+ allow(SingularityDsl::Dsl::Dsl).to receive(:new).and_return(dsl)
42
+ allow(dsl).to receive(:always_procs).and_return([always_proc])
43
+
44
+ # to halt #execute
45
+ allow(dsl).to receive(:load_ex_proc).and_call_original
46
+ allow(registry).to receive(:run_list).and_return([])
47
+ end
48
+
49
+ it 'triggers error procs when there is an error' do
50
+ allow(runner.state).to receive(:error).and_return true
51
+ allow(dsl).to receive(:error_procs).and_return([error_proc])
52
+
53
+ expect(dsl).to receive(:always_method)
54
+ expect(dsl).to receive(:error_method)
55
+
56
+ # once for the error proc, other for always
57
+ expect(runner).to receive(:execute).with(dsl).twice
58
+
59
+ runner.post_actions dsl
60
+ end
61
+
62
+ it 'triggers fail procs when there is a failure' do
63
+ allow(runner.state).to receive(:failed).and_return true
64
+ allow(dsl).to receive(:fail_procs).and_return([fail_proc])
65
+
66
+ expect(dsl).to receive(:always_method)
67
+ expect(dsl).to receive(:fail_method)
68
+
69
+ # once for the fail proc, other for always
70
+ expect(runner).to receive(:execute).with(dsl).twice
71
+
72
+ runner.post_actions dsl
73
+ end
74
+
75
+ it 'triggers success procs when no failure nor error' do
76
+ allow(runner.state).to receive(:failed).and_return false
77
+ allow(runner.state).to receive(:error).and_return false
78
+ allow(dsl).to receive(:success_procs).and_return([success_proc])
79
+
80
+ expect(dsl).to receive(:always_method)
81
+ expect(dsl).to receive(:success_method)
82
+
83
+ # once for the success proc, other for always
84
+ expect(runner).to receive(:execute).with(dsl).twice
85
+
86
+ runner.post_actions dsl
37
87
  end
38
88
  end
39
89
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singularity_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - chr0n1x
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-06 00:00:00.000000000 Z
11
+ date: 2015-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json