cocina 0.1.3 → 0.2.0

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: a635ff56f1db7bce214b644516a9928a4945526c
4
- data.tar.gz: 5e9bd1f239c1117f61444f0a4a31c15901544379
3
+ metadata.gz: 8877bc986582498901f7827f0c64844ddaa727ad
4
+ data.tar.gz: 5f4bce67c538c8bddf0c5e8b826c4c29e092ac80
5
5
  SHA512:
6
- metadata.gz: 7d1ca609ce1fa3edfbb6e6ab4e592d948d6c5ae8e82837bac5aa667298d00b9a5a18f7978252defb052f7f955e3687616c80d160e6582b23986c611bbb9c3a52
7
- data.tar.gz: 2b364b05fb98210bee3601fd36bb3f8e30f73a0b264d02526716303a2ae51276dda1c6f245ea95826353ca33dc71437606c8ed85a963d7ed283d8bfeadfa9915
6
+ metadata.gz: e6c74d4072c1f47591719a6e16cb348d10c60159d44d7b7abfb1ef2937e781483b32056861b79317ba49a5f5926e817e2ea8c6b3cf98cd959e85bbdc04d9a7d5
7
+ data.tar.gz: 8f9718ae491e62c0153df3831e1dd1e87599dd3b9ec6b4ebafacc690dff3a809c8fffa213f0fab7d8898995d0448d2ff168c91df21f11467ff04a7f1f4abdef6
data/example/Cocinafile CHANGED
@@ -1,7 +1,9 @@
1
1
  instance 'web-ubuntu-1404' do
2
2
  depends 'app-ubuntu-1404'
3
+ actions :converge, :converge, :verify
3
4
  end
4
5
 
5
6
  instance 'app-ubuntu-1404' do
6
7
  depends 'db-ubuntu-1404'
8
+ actions :converge, :converge, :verify
7
9
  end
data/lib/cocina/cli.rb CHANGED
@@ -27,7 +27,7 @@ module Cocina
27
27
  prepare_dependencies
28
28
  converge_dependencies
29
29
 
30
- primary_instance.verify
30
+ primary_instance.run_actions
31
31
  cleanup
32
32
  end
33
33
 
@@ -48,7 +48,7 @@ module Cocina
48
48
  end
49
49
 
50
50
  def converge_dependency(dep)
51
- log_banner "Converging <#{dep}>"
51
+ log_banner "Processing Dependency: <#{dep}>"
52
52
  instance(dep).converge
53
53
  end
54
54
 
@@ -61,7 +61,6 @@ module Cocina
61
61
 
62
62
  def destroy_dependencies
63
63
  dependencies.each do |dep|
64
- logger.info "Destroying #{dep}"
65
64
  instance(dep).destroy
66
65
  end
67
66
  end
@@ -0,0 +1,42 @@
1
+ module Cocina
2
+ class Instance
3
+ class Action
4
+ UnknownAction = Class.new(StandardError)
5
+ ACTIONS = [:destroy, :create, :converge, :verify] unless defined? ACTIONS
6
+
7
+ attr_reader :name
8
+
9
+ def initialize(name)
10
+ @after = []
11
+ @before = []
12
+ @name = name
13
+ raise UnknownAction unless ACTIONS.include?(name)
14
+ yield self if block_given?
15
+ end
16
+
17
+ def before(cmd = nil)
18
+ return nil if create?
19
+ return @before if cmd.nil?
20
+ @before << cmd
21
+ end
22
+
23
+ def after(cmd = nil)
24
+ return nil if destroy?
25
+ return @after if cmd.nil?
26
+ @after << cmd
27
+ end
28
+
29
+ # Check if this action is a destroy action
30
+ # @return [Bool]
31
+ def create?
32
+ name == :create
33
+ end
34
+
35
+ # Check if this action is a destroy action
36
+ # @return [Bool]
37
+ def destroy?
38
+ name == :destroy
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,25 +1,69 @@
1
1
  require 'forwardable'
2
+ # require 'cocina/instance/action'
2
3
 
3
4
  module Cocina
4
5
  class Instance
5
- attr_reader :name, :dependencies
6
- attr_accessor :runner
7
-
8
6
  extend Forwardable
9
7
 
8
+ attr_reader :name, :dependencies, :actions
9
+ attr_accessor :runner
10
+
10
11
  def_delegators :@runner, :destroy, :create, :converge, :verify
11
12
 
12
13
  def initialize(name)
13
14
  @name = name
14
15
  @dependencies = []
16
+ @actions = default_actions
15
17
  end
16
18
 
19
+ # Define a dependency for the Instance
20
+ #
17
21
  def depends(dep)
18
22
  @dependencies << dep
19
23
  end
20
24
 
21
- def has_dependency?
25
+ # Check if the Instance has any defined dependencies
26
+ #
27
+ def dependencies?
22
28
  dependencies.empty? ? false : true
23
29
  end
30
+
31
+ # Set or return the list of actions
32
+ #
33
+ def actions(*list)
34
+ return @actions if list.empty?
35
+ @actions = list.flatten
36
+ end
37
+
38
+ # def action(name, &block)
39
+ # @actions << Action.new(name) do |action|
40
+ # action.instance_eval(&block) unless block.nil?
41
+ # end
42
+ # end
43
+
44
+ # Run all actions defined for the Instance
45
+ #
46
+ def run_actions
47
+ actions.each do |action|
48
+ # execute perform.before
49
+ send action
50
+ end
51
+ end
52
+
53
+ private
54
+
55
+ def default_actions
56
+ [:verify]
57
+ end
58
+
59
+ # Returns the current state of the Instance as recorded by the runner
60
+ #
61
+ def state
62
+ @runner.last_action
63
+ end
64
+
65
+ # def execute(*cmds)
66
+ # cmds.each {|cmd| @runner.remote_exec(cmd) }
67
+ # end
24
68
  end
25
69
  end
@@ -1,3 +1,3 @@
1
1
  module Cocina
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocina
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Raabe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-29 00:00:00.000000000 Z
11
+ date: 2015-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,6 +137,7 @@ files:
137
137
  - lib/cocina/cli.rb
138
138
  - lib/cocina/config.rb
139
139
  - lib/cocina/instance.rb
140
+ - lib/cocina/instance/action.rb
140
141
  - lib/cocina/version.rb
141
142
  homepage: https://github.com/brandocorp/cocina
142
143
  licenses: