anvil-core 0.3.2 → 0.4.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
  SHA1:
3
- metadata.gz: c9ac08ce0101f9b591711a99ea58973b07ecb6df
4
- data.tar.gz: 20d037d2a7845faa66b5b62e37c30e992dfe1083
3
+ metadata.gz: 71ffb03f67a3fed9d510791164f6688a87392fc4
4
+ data.tar.gz: c4dab2c85e2d625ffab883580fa2e2bb88382570
5
5
  SHA512:
6
- metadata.gz: a7f030a95bf219418730dcd7ff69a6aa1c3ce7c2c98293e270413726c769c22e28dafbd87b9aa3f9888efd8f7fa59a1a3d4694d41268dafbf216733b0092438d
7
- data.tar.gz: a84505d91dd37c7a7efadce8a68da11b1765d0084f64968a4cc1e229bbeb57c6129618c41971482745f8e9646b6b600b7f25594f45d9fb2ee23abe68fc664f7a
6
+ metadata.gz: 2a47af0b91a303163f21691c8d520925e7f9558617c8993b22e5d265740679c4bbca464f4b1b8874fa11831563cb14d24e259a52806f0b1485f491f148d5f7d8
7
+ data.tar.gz: a2555fcaedd1ee41e37e66aeb782b7b65bd2b4ed9b09939730649085638bd378b4114d00bce8e25937f9e0e9e39711e9fca3a51bdcbe2e19a2466fccf11f1126
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
@@ -1,8 +1,11 @@
1
1
  module Anvil
2
2
  class Bundler
3
3
  def self.update_gem(gem_name)
4
- line = Cocaine::CommandLine.new('bundle', 'update :gem')
5
- line.run gem: gem_name
4
+ ::Bundler.with_clean_env do
5
+ Cocaine::CommandLine.runner = Cocaine::CommandLine::PopenRunner.new
6
+ line = Cocaine::CommandLine.new('bundle', "update #{gem_name}")
7
+ line.run
8
+ end
6
9
  end
7
10
  end
8
11
  end
@@ -3,6 +3,7 @@
3
3
  require 'anvil/task/class_methods'
4
4
  require 'anvil/task/naming'
5
5
  require 'anvil/task/options'
6
+ require 'anvil/task/callback'
6
7
 
7
8
  module Anvil
8
9
  # Common class for all tasks
@@ -37,9 +38,7 @@ module Anvil
37
38
  protected
38
39
 
39
40
  def run_after_callbacks
40
- self.class.afters.each do |after|
41
- after[0].new(after[1]).run
42
- end
41
+ self.class.afters.each { |callback| callback.run }
43
42
  end
44
43
 
45
44
  def run_assures
@@ -47,9 +46,7 @@ module Anvil
47
46
  end
48
47
 
49
48
  def run_before_callbacks
50
- self.class.befores.each do |before|
51
- before[0].new(before[1]).run
52
- end
49
+ self.class.befores.each { |callback| callback.run }
53
50
  end
54
51
 
55
52
  def run_task
@@ -0,0 +1,19 @@
1
+ require 'anvil/task/naming'
2
+
3
+ module Anvil
4
+ class Task
5
+ class Callback
6
+ include Anvil::Task::Naming
7
+
8
+ attr_reader :task, :options
9
+
10
+ def initialize(task_name, options)
11
+ @task, @options = from_name(task_name), options
12
+ end
13
+
14
+ def run
15
+ task.new(options).run
16
+ end
17
+ end
18
+ end
19
+ end
@@ -18,7 +18,7 @@ module Anvil
18
18
  end
19
19
 
20
20
  def after(task_name, options = {})
21
- afters << [from_name(task_name), options]
21
+ afters << Callback.new(task_name, options)
22
22
  end
23
23
 
24
24
  def assure(assure_name)
@@ -26,7 +26,7 @@ module Anvil
26
26
  end
27
27
 
28
28
  def before(task_name, options = {})
29
- befores << [from_name(task_name), options]
29
+ befores << Callback.new(task_name, options)
30
30
  end
31
31
 
32
32
  def run(*args)
@@ -13,6 +13,11 @@ module Anvil
13
13
  log_project_does_not_exists project
14
14
  end
15
15
 
16
+ # Yields a block in which PWD is the folder of a project managed
17
+ # by anvil.
18
+ #
19
+ # @param [String] project the name of a project managed by anvil
20
+ # @return [Object] anything returned by the yielded block
16
21
  def on_project(project)
17
22
  Dir.chdir(project_path(project)) do
18
23
  yield(git)
@@ -21,8 +26,13 @@ module Anvil
21
26
  log_project_does_not_exists project
22
27
  end
23
28
 
29
+ # Runs on_project on an array of projects
30
+ #
31
+ # @param [Array] projects an array of projects managed by anvil
32
+ # @return [Array] an array with the values returned by each
33
+ # on_project run
24
34
  def on_each_project(projects)
25
- projects.each do |project|
35
+ projects.map do |project|
26
36
  on_project(project) { |project_git| yield project, project_git }
27
37
  end
28
38
  end
@@ -14,7 +14,12 @@ class HelpTask < Anvil::Task
14
14
  end
15
15
 
16
16
  def task
17
+ return default_message unless task_name.present?
17
18
  klazz = Anvil::Task.from_name(task_name)
18
19
  printf(klazz.help)
19
20
  end
21
+
22
+ def default_message
23
+ printf(self.class.help)
24
+ end
20
25
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+ require 'anvil/task/naming'
3
+
4
+ describe Anvil::Task::Callback do
5
+
6
+ subject(:callback) { Anvil::Task::Callback.new(:dummy, option: 'value') }
7
+
8
+ describe '#new' do
9
+ it 'sets the task by the name' do
10
+ expect(callback.task).to be DummyTask
11
+ end
12
+
13
+ it 'sets the options' do
14
+ expect(callback.options).to include(option: 'value')
15
+ end
16
+ end
17
+
18
+ describe '.run' do
19
+ let(:dummy_task) { DummyTask.new }
20
+
21
+ it 'runs the task' do
22
+ expect(DummyTask).to receive(:new)
23
+ .with(option: 'value')
24
+ .and_return(dummy_task)
25
+ expect(dummy_task).to receive(:run)
26
+ callback.run
27
+ end
28
+ end
29
+ end
@@ -44,6 +44,12 @@ describe Anvil::Task::Projects, fakefs: true do
44
44
  it 'yields a git project object' do
45
45
  expect { |b| subject.on_project(project, &b) }.to yield_with_args
46
46
  end
47
+
48
+ it 'returns the same thing returned by the yielded block' do
49
+ return_value = 'return-value'
50
+
51
+ expect(subject.on_project(project) { return_value }).to eq(return_value)
52
+ end
47
53
  end
48
54
 
49
55
  describe '#on_each_project' do
@@ -53,7 +59,8 @@ describe Anvil::Task::Projects, fakefs: true do
53
59
  end
54
60
 
55
61
  it 'works on each project' do
56
- expect { |b| subject.on_each_project(projects, &b) }.to yield_control.twice
62
+ expect { |b| subject.on_each_project(projects, &b) }
63
+ .to yield_control.twice
57
64
  end
58
65
  end
59
66
  end
@@ -10,8 +10,10 @@ describe Anvil::Task do
10
10
  describe '.after' do
11
11
  before { dummy_task.class_eval { after :dummy_after, argument: 'value' } }
12
12
 
13
+ subject(:afters) { dummy_task.afters }
13
14
  it 'adds DummyBeforeTask to the after callbacks' do
14
- dummy_task.afters.should include([after_task, arguments])
15
+ afters.first.should be_an_instance_of Anvil::Task::Callback
16
+ afters.first.task.should be DummyAfterTask
15
17
  end
16
18
  end
17
19
 
@@ -28,8 +30,10 @@ describe Anvil::Task do
28
30
  dummy_task.class_eval { before :dummy_before, argument: 'value' }
29
31
  end
30
32
 
33
+ subject(:befores) { dummy_task.befores }
31
34
  it 'adds DummyBeforeTask to the before callbacks' do
32
- dummy_task.befores.should include([before_task, arguments])
35
+ befores.first.should be_an_instance_of Anvil::Task::Callback
36
+ befores.first.task.should be DummyBeforeTask
33
37
  end
34
38
  end
35
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: anvil-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fran Casas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-05 00:00:00.000000000 Z
12
+ date: 2014-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git
@@ -178,6 +178,7 @@ files:
178
178
  - lib/anvil/parser.rb
179
179
  - lib/anvil/rubygems.rb
180
180
  - lib/anvil/task.rb
181
+ - lib/anvil/task/callback.rb
181
182
  - lib/anvil/task/class_methods.rb
182
183
  - lib/anvil/task/naming.rb
183
184
  - lib/anvil/task/options.rb
@@ -200,6 +201,7 @@ files:
200
201
  - spec/lib/anvil/config_spec.rb
201
202
  - spec/lib/anvil/extensions_manager_spec.rb
202
203
  - spec/lib/anvil/parser_spec.rb
204
+ - spec/lib/anvil/task/callback_spec.rb
203
205
  - spec/lib/anvil/task/naming_spec.rb
204
206
  - spec/lib/anvil/task/options_spec.rb
205
207
  - spec/lib/anvil/task/projects_spec.rb
@@ -253,6 +255,7 @@ test_files:
253
255
  - spec/lib/anvil/config_spec.rb
254
256
  - spec/lib/anvil/extensions_manager_spec.rb
255
257
  - spec/lib/anvil/parser_spec.rb
258
+ - spec/lib/anvil/task/callback_spec.rb
256
259
  - spec/lib/anvil/task/naming_spec.rb
257
260
  - spec/lib/anvil/task/options_spec.rb
258
261
  - spec/lib/anvil/task/projects_spec.rb