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 +4 -4
- data/example/Cocinafile +2 -0
- data/lib/cocina/cli.rb +2 -3
- data/lib/cocina/instance/action.rb +42 -0
- data/lib/cocina/instance.rb +48 -4
- data/lib/cocina/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8877bc986582498901f7827f0c64844ddaa727ad
|
4
|
+
data.tar.gz: 5f4bce67c538c8bddf0c5e8b826c4c29e092ac80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6c74d4072c1f47591719a6e16cb348d10c60159d44d7b7abfb1ef2937e781483b32056861b79317ba49a5f5926e817e2ea8c6b3cf98cd959e85bbdc04d9a7d5
|
7
|
+
data.tar.gz: 8f9718ae491e62c0153df3831e1dd1e87599dd3b9ec6b4ebafacc690dff3a809c8fffa213f0fab7d8898995d0448d2ff168c91df21f11467ff04a7f1f4abdef6
|
data/example/Cocinafile
CHANGED
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.
|
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 "
|
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
|
data/lib/cocina/instance.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/cocina/version.rb
CHANGED
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.
|
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-
|
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:
|