Class: Kaigara::Package
- Inherits:
-
Object
- Object
- Kaigara::Package
- Defined in:
- app/models/sysops/package.rb
Defined Under Namespace
Classes: MetadataNotFound
Constant Summary collapse
- METADATA_FILE_NAME =
The base project files and directories
'metadata.rb'
- VAGRANT_FILE_NAME =
'Vagrantfile'
- OPERATIONS_DIR_NAME =
'operations'
- RESOURCES_DIR_NAME =
'resources'
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#name ⇒ Object
Returns the value of attribute name.
-
#operations_dir ⇒ Object
Returns the value of attribute operations_dir.
-
#script_path ⇒ Object
metadata.rb path.
-
#version ⇒ Object
Returns the value of attribute version.
-
#work_dir ⇒ Object
Project directory.
Instance Method Summary collapse
- #execute_operation!(path) ⇒ Object
- #full_name ⇒ Object
-
#initialize(path = '.') ⇒ Package
constructor
A new instance of Package.
-
#load! ⇒ Object
Read and execute metadata.rb.
-
#operation_name(name) ⇒ Object
Create an empty operation in ./operations.
-
#run!(operations) ⇒ Object
Execute operations in the operations directory one by one.
Constructor Details
#initialize(path = '.') ⇒ Package
Returns a new instance of Package.
25 26 27 28 29 30 31 32 |
# File 'app/models/sysops/package.rb', line 25 def initialize(path = '.') @options = {} @work_dir = path ? File.(path) : '.' @operations_dir = File.join(@work_dir, OPERATIONS_DIR_NAME) @script_path = File.(File.join(@work_dir, METADATA_FILE_NAME)) @spec = Spec.new(self) end |
Instance Attribute Details
#dependencies ⇒ Object
Returns the value of attribute dependencies.
19 20 21 |
# File 'app/models/sysops/package.rb', line 19 def dependencies @dependencies end |
#name ⇒ Object
Returns the value of attribute name.
21 22 23 |
# File 'app/models/sysops/package.rb', line 21 def name @name end |
#operations_dir ⇒ Object
Returns the value of attribute operations_dir.
18 19 20 |
# File 'app/models/sysops/package.rb', line 18 def operations_dir @operations_dir end |
#script_path ⇒ Object
metadata.rb path
16 17 18 |
# File 'app/models/sysops/package.rb', line 16 def script_path @script_path end |
#version ⇒ Object
Returns the value of attribute version.
20 21 22 |
# File 'app/models/sysops/package.rb', line 20 def version @version end |
#work_dir ⇒ Object
Project directory
13 14 15 |
# File 'app/models/sysops/package.rb', line 13 def work_dir @work_dir end |
Instance Method Details
#execute_operation!(path) ⇒ Object
60 61 62 63 64 65 |
# File 'app/models/sysops/package.rb', line 60 def execute_operation!(path) context = Operation.new path context.work_dir = @work_dir context.environment = @spec.environment context.apply! end |
#full_name ⇒ Object
34 35 36 |
# File 'app/models/sysops/package.rb', line 34 def full_name @full_name ||= [name, version].compact.join("/") end |
#load! ⇒ Object
Read and execute metadata.rb
39 40 41 42 43 |
# File 'app/models/sysops/package.rb', line 39 def load! raise MetadataNotFound.new unless File.exist?(@script_path) script = File.read(@script_path) @spec.instance_eval(script) end |
#operation_name(name) ⇒ Object
Create an empty operation in ./operations
46 47 48 49 |
# File 'app/models/sysops/package.rb', line 46 def operation_name(name) ts = DateTime.now.strftime('%Y%m%d%H%M%S') return "%s_%s.rb" % [ts, name] end |
#run!(operations) ⇒ Object
Execute operations in the operations directory one by one
52 53 54 55 56 57 58 |
# File 'app/models/sysops/package.rb', line 52 def run!(operations) Dir[File.join(@operations_dir, '*.rb')].sort.each do |x| if operations.empty? or operations.find { |op| x.include?(op) } execute_operation!(x) end end end |