Class: Isono::Manifest
- Inherits:
-
Object
- Object
- Isono::Manifest
- Defined in:
- lib/isono/manifest.rb
Overview
Deals with .isono manifest file and its data.
Defined Under Namespace
Classes: ConfigStruct, ConfigStructBuilder
Instance Attribute Summary collapse
-
#app_root ⇒ Object
readonly
Returns the value of attribute app_root.
-
#node_modules ⇒ Object
readonly
Returns the value of attribute node_modules.
Class Method Summary collapse
-
.load_file(path) ⇒ Isono::Manifest
Loads .isono manifest file.
Instance Method Summary collapse
- #config(&blk) ⇒ Object
- #config_path(path = nil) ⇒ Object
-
#initialize(app_root = '.', &blk) ⇒ Manifest
constructor
A new instance of Manifest.
-
#load_config(path) ⇒ Object
load config file and merge up with the config tree.
-
#load_module(mod_class, *args) ⇒ Object
(also: #manager)
Regist a node module class to be initialized/terminated.
- #node_id ⇒ Object
- #node_instance_id(instance_id = nil) ⇒ Object
- #node_name(name = nil) ⇒ Object
Constructor Details
#initialize(app_root = '.', &blk) ⇒ Manifest
Returns a new instance of Manifest.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/isono/manifest.rb', line 28 def initialize(app_root='.', &blk) @node_modules = [] resolve_abs_app_root(app_root) @config = ConfigStruct.new @config.app_root = app_root instance_eval(&blk) if blk load_config(@config_path) if @config_path end |
Instance Attribute Details
#app_root ⇒ Object (readonly)
Returns the value of attribute app_root.
24 25 26 |
# File 'lib/isono/manifest.rb', line 24 def app_root @app_root end |
#node_modules ⇒ Object (readonly)
Returns the value of attribute node_modules.
24 25 26 |
# File 'lib/isono/manifest.rb', line 24 def node_modules @node_modules end |
Class Method Details
.load_file(path) ⇒ Isono::Manifest
Loads .isono manifest file
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/isono/manifest.rb', line 12 def self.load_file(path) buf = File.read(path) # use the parent directory as the application root. app_root = File.dirname(path) m = eval("#{self.to_s}.new('#{app_root}') {\n" + buf + "\n}", TOPLEVEL_BINDING, path) # use the manifest filename as the node name if not set. m.node_name(File.basename(path, '.isono')) if m.node_name.nil? m end |
Instance Method Details
#config(&blk) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/isono/manifest.rb', line 77 def config(&blk) if blk @config.instance_eval &blk end @config end |
#config_path(path = nil) ⇒ Object
72 73 74 75 |
# File 'lib/isono/manifest.rb', line 72 def config_path(path=nil) @config_path = path if path @config_path end |
#load_config(path) ⇒ Object
load config file and merge up with the config tree. it will not work when the config_path is nil or the file is missed
86 87 88 89 90 |
# File 'lib/isono/manifest.rb', line 86 def load_config(path) return unless File.exist?(path) buf = File.read(path) eval("#{buf}", binding, path) end |
#load_module(mod_class, *args) ⇒ Object Also known as: manager
Regist a node module class to be initialized/terminated.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/isono/manifest.rb', line 41 def load_module(mod_class, *args) unless mod_class.is_a?(Class) && mod_class < Isono::NodeModules::Base raise ArgumentError, "" end return if @node_modules.find{|i| i[0] == mod_class } sec_builder = mod_class.instance_variable_get(:@config_section_builder) if sec_builder.is_a? Proc sec_name = mod_class.instance_variable_get(:@config_section_name) #sec_builder.call(ConfigStructBuilder.new(@config.add_section(sec_name))) ConfigStructBuilder.new(@config.add_section(sec_name)).instance_eval &sec_builder end @node_modules << [mod_class, *args] end |
#node_id ⇒ Object
68 69 70 |
# File 'lib/isono/manifest.rb', line 68 def node_id "#{@node_name}.#{@node_instance_id}" end |
#node_instance_id(instance_id = nil) ⇒ Object
63 64 65 66 |
# File 'lib/isono/manifest.rb', line 63 def node_instance_id(instance_id=nil) @node_instance_id = instance_id.to_s if instance_id @node_instance_id end |
#node_name(name = nil) ⇒ Object
58 59 60 61 |
# File 'lib/isono/manifest.rb', line 58 def node_name(name=nil) @node_name = name.to_s if name @node_name end |