stack_commander 0.0.5.pre.2 → 0.0.5

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
2
  SHA1:
3
- metadata.gz: 1dae7fd632f00edc3706a9f842914a777c1627b0
4
- data.tar.gz: 3c04261a6b4cec730cea9a7d5738769af9f95ad6
3
+ metadata.gz: 595990555153b67f3183dbca5f68d2e1f10fe746
4
+ data.tar.gz: 097710148b29367a54622fc4181c22b3175edb1f
5
5
  SHA512:
6
- metadata.gz: fee8c6a2d3c1ad2652d918d1880b0889c8eae16f6896ae576eca932f80c0095031c9e9c22580530e158c2211414c6b38d0bf825c43243005dbb60d0190593b9d
7
- data.tar.gz: f27cb2d4341f3015bbe93d069bcf7cd7e0870296644a35929dd519a81b8fa0f1042b1f696c928f0bcbd6f6e6c3aa53523039838842a9f38458b4c83f4bb7b8a8
6
+ metadata.gz: 29509d72c79c3dad4cd4fbe788eead74769472bb09ad70bfe3a6a7b66896ca32d0997ea39cf352319fc9f311d03f38552755c9acea666beae5c37b890be229d6
7
+ data.tar.gz: 420c6a813a99c4fe2f06c7b12477d755c903791ce4879363f370d67e1bf16bedad6dff237855159f4c60a1973fe86e5edfae4153ae47da171807565d612f1054
data/README.md CHANGED
@@ -101,6 +101,10 @@ other command insurance
101
101
  command insurance
102
102
  ```
103
103
 
104
+ # TODO
105
+ * figure out how to configure commands without need of subclassing
106
+ for example Command Gzip accepts a file and outputs a gzipped file, how you can use this command twice in one stack?
107
+
104
108
  ## Contributing
105
109
 
106
110
  1. Fork it ( https://github.com/mikz/stack_commander/fork )
@@ -1,12 +1,9 @@
1
1
  module StackCommander
2
2
  module Command
3
- def self.included(base)
4
- base.extend(ClassMethods)
5
- end
6
-
7
3
  def call(stack)
8
4
  action
9
5
  stack.call
6
+ cleanup
10
7
  rescue => exception
11
8
  recover(exception)
12
9
  raise
@@ -14,6 +11,9 @@ module StackCommander
14
11
  insurance
15
12
  end
16
13
 
14
+ def cleanup
15
+ end
16
+
17
17
  def action
18
18
  end
19
19
 
@@ -22,31 +22,5 @@ module StackCommander
22
22
 
23
23
  def insurance
24
24
  end
25
-
26
- def configuration
27
- self.class.configuration
28
- end
29
-
30
- private
31
-
32
- module ClassMethods
33
- CONFIGURATION = :@@configuration
34
-
35
- def configuration
36
- class_variable_get(CONFIGURATION) if class_variable_defined?(CONFIGURATION)
37
- end
38
-
39
- def dependency_injection(&block)
40
- class_variable_set(:@@dependency_injection, block)
41
- end
42
-
43
- # Creates an anonymous subclass of current command, configured with passed value
44
- # then all instances of that command will have the same configuration
45
- def [](value)
46
- subclass = Class.new(self)
47
- subclass.class_variable_set(CONFIGURATION, value)
48
- subclass
49
- end
50
- end
51
25
  end
52
26
  end
@@ -2,8 +2,6 @@ module StackCommander
2
2
  class DependencyInjection
3
3
  InvalidScope = Class.new(StandardError)
4
4
 
5
- CVAR = :@@dependency_injection
6
-
7
5
  def initialize(klass)
8
6
  @klass = klass
9
7
  end
@@ -17,29 +15,20 @@ module StackCommander
17
15
  Array(parameters)
18
16
  end
19
17
 
20
- def configured_parameters
21
- parameters = @klass.class_variable_defined?(CVAR) && @klass.class_variable_get(CVAR)
22
- parameters && parameters.respond_to?(:to_proc) ? @klass.instance_exec(:initialize, &parameters) : parameters
23
- end
24
-
25
- def parameters
26
- configured_parameters || required_parameters
27
- end
28
-
29
- def matching?(scope)
30
- parameters.all? do |param|
18
+ def matches?(scope)
19
+ required_parameters.all? do |param|
31
20
  scope.respond_to?(param)
32
21
  end
33
22
  end
34
23
 
35
24
  def match!(scope)
36
- raise InvalidScope, scope unless matching?(scope)
25
+ raise InvalidScope, scope unless matches?(scope)
37
26
  end
38
27
 
39
28
  def extract(scope)
40
29
  match!(scope)
41
30
 
42
- parameters.map do |param|
31
+ required_parameters.map do |param|
43
32
  scope.public_send(param)
44
33
  end
45
34
  end
@@ -1,3 +1,3 @@
1
1
  module StackCommander
2
- VERSION = '0.0.5.pre.2'
2
+ VERSION = '0.0.5'
3
3
  end
data/spec/command_spec.rb CHANGED
@@ -11,6 +11,7 @@ describe StackCommander::Command do
11
11
 
12
12
  expect_it { to respond_to(:action) }
13
13
  expect_it { to respond_to(:insurance) }
14
+ expect_it { to respond_to(:cleanup) }
14
15
  expect_it { to respond_to(:recover).with(1).argument }
15
16
 
16
17
 
@@ -26,6 +27,11 @@ describe StackCommander::Command do
26
27
  subject.call(stack)
27
28
  end
28
29
 
30
+ it 'calls cleanup' do
31
+ expect(subject).to receive(:cleanup)
32
+ subject.call(stack)
33
+ end
34
+
29
35
  it 'calls insurance' do
30
36
  expect(subject).to receive(:insurance)
31
37
  subject.call(stack)
@@ -51,43 +57,10 @@ describe StackCommander::Command do
51
57
  expect(subject).to receive(:recover).with(an_instance_of(StandardError))
52
58
  expect{ subject.call(stack) }.to raise_error(StandardError)
53
59
  end
54
- end
55
- end
56
-
57
- context 'classes including command' do
58
- subject(:command) { Class.new{ include StackCommander::Command } }
59
-
60
- before do
61
- stub_const('TestCommand', command)
62
- end
63
-
64
- it 'has name' do
65
- expect(command.to_s).to eq('TestCommand')
66
- end
67
-
68
- it 'has configuration' do
69
- expect(command.configuration).to be_nil
70
- end
71
-
72
- context 'with config' do
73
- subject(:configured_command) { command[:test] }
74
-
75
- expect_it { to be }
76
-
77
- it 'does not have a name' do
78
- expect(configured_command.to_s).not_to eq('TestCommand')
79
- end
80
-
81
- it 'has configuration' do
82
- expect(configured_command.configuration).to eq(:test)
83
- end
84
60
 
85
- context 'an instance' do
86
- subject(:instance) { configured_command.new }
87
-
88
- it 'has configuration' do
89
- expect(instance.configuration).to eq(:test)
90
- end
61
+ it 'does not call cleanup' do
62
+ expect(subject).not_to receive(:cleanup)
63
+ expect{ subject.call(stack) }.to raise_error(StandardError)
91
64
  end
92
65
  end
93
66
  end
@@ -14,7 +14,7 @@ describe StackCommander::DependencyInjection do
14
14
  let(:scope) { double('scope', one: 'one value', two: 'two') }
15
15
 
16
16
  it do
17
- expect(di).to be_matching(scope)
17
+ expect(di.matches?(scope)).to be
18
18
  end
19
19
 
20
20
  it do
@@ -22,30 +22,15 @@ describe StackCommander::DependencyInjection do
22
22
  end
23
23
  end
24
24
 
25
- context 'scope does not have required methods' do
25
+ context 'scope does not have requried methods' do
26
26
  let(:scope) { double('scope', one: true) }
27
27
 
28
28
  it do
29
- expect(di).not_to be_matching(scope)
29
+ expect(di.matches?(scope)).not_to be
30
30
  end
31
31
 
32
32
  it do
33
33
  expect{ di.extract(scope) }.to raise_error(StackCommander::DependencyInjection::InvalidScope)
34
34
  end
35
35
  end
36
-
37
- context 'class has configured parameters' do
38
- before do
39
- custom_class.class_variable_set :@@dependency_injection, proc { [:three, :four] }
40
- end
41
-
42
- it do
43
- expect(di.parameters).to eq([:three, :four])
44
- end
45
-
46
- it 'matches new scope' do
47
- scope = double(three: true, four: true)
48
- expect(di).to be_matching(scope)
49
- end
50
- end
51
36
  end
data/spec/stack_spec.rb CHANGED
@@ -49,9 +49,13 @@ describe StackCommander::Stack do
49
49
  stack << other_command
50
50
  end
51
51
 
52
- it 'calls action in stack manner' do
52
+ it 'calls actions in stack manner' do
53
53
  expect_any_instance_of(command).to receive(:action) do
54
- expect_any_instance_of(other_command).to receive(:action)
54
+ expect_any_instance_of(other_command).to receive(:action) do
55
+ expect_any_instance_of(other_command).to receive(:cleanup) do
56
+ expect_any_instance_of(command).to receive(:cleanup)
57
+ end
58
+ end
55
59
  end
56
60
 
57
61
  stack.call
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_commander
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.pre.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Cichra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-16 00:00:00.000000000 Z
11
+ date: 2014-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,9 +108,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  requirements:
111
- - - ">"
111
+ - - ">="
112
112
  - !ruby/object:Gem::Version
113
- version: 1.3.1
113
+ version: '0'
114
114
  requirements: []
115
115
  rubyforge_project:
116
116
  rubygems_version: 2.2.2