Class: Chapp::AppConfig
- Inherits:
-
Object
- Object
- Chapp::AppConfig
- Defined in:
- lib/chapp/app_config.rb
Constant Summary collapse
- DEFAULT_RECIPE =
TODO: Define allowed characters (.)
"default"
Instance Attribute Summary collapse
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
-
#used_apps ⇒ Object
readonly
Returns the value of attribute used_apps.
Class Method Summary collapse
Instance Method Summary collapse
- #cookbook(cookbook = nil) ⇒ Object
- #depends(cookbook, version_constraint) ⇒ Object
- #environment(environment = nil) ⇒ Object
- #environment_name ⇒ Object
- #group(group = nil) ⇒ Object
- #id ⇒ Object
-
#initialize ⇒ AppConfig
constructor
A new instance of AppConfig.
- #name(name = nil) ⇒ Object
- #node(node = nil) ⇒ Object
- #post_run_list(*recipes) ⇒ Object
- #pre_run_list(*recipes) ⇒ Object
- #recipe(recipe = nil) ⇒ Object
- #role_name ⇒ Object
- #run_list(run_list = nil) ⇒ Object
- #to_hash ⇒ Object
- #type(type = nil) ⇒ Object
- #uses(type, app) ⇒ Object
Constructor Details
#initialize ⇒ AppConfig
Returns a new instance of AppConfig.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/chapp/app_config.rb', line 62 def initialize @group = nil @name = nil @used_apps = Hash.new @dependencies = Hash.new @pre_run_list = Array.new @post_run_list = Array.new @environment = nil @node = Chef::Node::Attribute.new({}, {}, {}, {}).default @run_list = nil @type = nil @recipe = nil @cookbook = nil end |
Instance Attribute Details
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
12 13 14 |
# File 'lib/chapp/app_config.rb', line 12 def dependencies @dependencies end |
#used_apps ⇒ Object (readonly)
Returns the value of attribute used_apps.
11 12 13 |
# File 'lib/chapp/app_config.rb', line 11 def used_apps @used_apps end |
Class Method Details
.from_file(app_file) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/chapp/app_config.rb', line 14 def self.from_file app_file appString = IO.read app_file app = AppConfig.new app.instance_eval appString app end |
.from_hash(app_hash) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/chapp/app_config.rb', line 23 def self.from_hash app_hash app = AppConfig.new app.group app_hash["group"] app.name app_hash["name"] app.pre_run_list app_hash["pre_run_list"] app.post_run_list app_hash["post_run_list"] app.run_list app_hash["run_list"] app_hash["dependencies"].each do |cookbook, version_constraint| app.depends cookbook, version_constraint end app_hash["used_apps"].each do |type, app_ids| app_ids.each do |app_id| app.uses type, app_id end end app.node Chef::Node::Attribute.new({}, app_hash["node"], {}, {}).default app.environment app_hash["environment"] if app_hash.include? "type" app.type app_hash["type"] end if app_hash.include? "recipe" app.recipe app_hash["recipe"] end if app_hash.include? "cookbook" app.cookbook app_hash["cookbook"] end app end |
Instance Method Details
#cookbook(cookbook = nil) ⇒ Object
106 107 108 |
# File 'lib/chapp/app_config.rb', line 106 def cookbook cookbook=nil set_or_return_with_default :cookbook, @name, cookbook end |
#depends(cookbook, version_constraint) ⇒ Object
118 119 120 |
# File 'lib/chapp/app_config.rb', line 118 def depends cookbook, version_constraint @dependencies.store cookbook, version_constraint end |
#environment(environment = nil) ⇒ Object
146 147 148 |
# File 'lib/chapp/app_config.rb', line 146 def environment environment=nil set_or_return :environment, environment end |
#environment_name ⇒ Object
93 94 95 |
# File 'lib/chapp/app_config.rb', line 93 def environment_name "chapp_#{id}" end |
#group(group = nil) ⇒ Object
77 78 79 |
# File 'lib/chapp/app_config.rb', line 77 def group group=nil set_or_return :group, group end |
#id ⇒ Object
85 86 87 |
# File 'lib/chapp/app_config.rb', line 85 def id "#{group}_#{name}" end |
#name(name = nil) ⇒ Object
81 82 83 |
# File 'lib/chapp/app_config.rb', line 81 def name name=nil set_or_return :name, name end |
#node(node = nil) ⇒ Object
138 139 140 |
# File 'lib/chapp/app_config.rb', line 138 def node node=nil set_or_return :node, node end |
#post_run_list(*recipes) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/chapp/app_config.rb', line 130 def post_run_list *recipes if recipes.length > 0 @post_run_list = recipes else @post_run_list end end |
#pre_run_list(*recipes) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/chapp/app_config.rb', line 122 def pre_run_list *recipes if recipes.length > 0 @pre_run_list = recipes else @pre_run_list end end |
#recipe(recipe = nil) ⇒ Object
110 111 112 |
# File 'lib/chapp/app_config.rb', line 110 def recipe recipe=nil set_or_return_with_default :recipe, DEFAULT_RECIPE, recipe end |
#role_name ⇒ Object
89 90 91 |
# File 'lib/chapp/app_config.rb', line 89 def role_name "chapp_#{id}" end |
#run_list(run_list = nil) ⇒ Object
142 143 144 |
# File 'lib/chapp/app_config.rb', line 142 def run_list run_list=nil set_or_return :run_list, run_list end |
#to_hash ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/chapp/app_config.rb', line 150 def to_hash hash = Hash.new hash.store "group", group hash.store "name", name hash.store "used_apps", used_apps hash.store "pre_run_list", pre_run_list hash.store "post_run_list", post_run_list hash.store "dependencies", dependencies hash.store "node", node.to_hash hash.store "environment", environment if @type hash.store "type", type end if @recipe hash.store "recipe", recipe end if @cookbook hash.store "cookbook", cookbook end hash end |
#type(type = nil) ⇒ Object
114 115 116 |
# File 'lib/chapp/app_config.rb', line 114 def type type=nil set_or_return_with_default :type, cookbook, type end |
#uses(type, app) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/chapp/app_config.rb', line 97 def uses type, app unless @used_apps.has_key? type @used_apps[type] = Array.new end @used_apps[type].push app end |