Class: Chapp::AppConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/chapp/app_config.rb

Constant Summary collapse

DEFAULT_RECIPE =

TODO: Define allowed characters (.)

"default"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAppConfig

Returns a new instance of AppConfig.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/chapp/app_config.rb', line 62

def initialize
  @name_space = Hash.new
  @name = nil
  @used_apps = Array.new
  @cloud = 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

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



12
13
14
# File 'lib/chapp/app_config.rb', line 12

def dependencies
  @dependencies
end

#used_appsObject (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.name_space app_hash["name_space"]
  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 |app_id|
    app.uses app_id
  end

  app.cloud app_hash["cloud"]

  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

#cloud(cloud = nil) ⇒ Object



146
147
148
# File 'lib/chapp/app_config.rb', line 146

def cloud cloud=nil
  set_or_return :cloud, cloud
end

#cookbook(cookbook = nil) ⇒ Object



110
111
112
# File 'lib/chapp/app_config.rb', line 110

def cookbook cookbook=nil
  set_or_return_with_default :cookbook, @name, cookbook
end

#depends(cookbook, version_constraint) ⇒ Object



122
123
124
# File 'lib/chapp/app_config.rb', line 122

def depends cookbook, version_constraint
  @dependencies.store cookbook, version_constraint
end

#environment(environment = nil) ⇒ Object



154
155
156
# File 'lib/chapp/app_config.rb', line 154

def environment environment=nil
  set_or_return :environment, environment
end

#environment_nameObject



102
103
104
# File 'lib/chapp/app_config.rb', line 102

def environment_name
  "chapp_#{id}"
end

#idObject



86
87
88
89
90
# File 'lib/chapp/app_config.rb', line 86

def id
  hash = name_space.clone
  hash["name"] = name
  hash.sort_by{|k,v| k.to_s}.map{|k,v| "#{k}_#{v}"}.join("_")
end

#id_hashObject



92
93
94
95
96
# File 'lib/chapp/app_config.rb', line 92

def id_hash
  hash = name_space.clone
  hash["name"] = name
  hash
end

#name(name = nil) ⇒ Object



82
83
84
# File 'lib/chapp/app_config.rb', line 82

def name name=nil
  set_or_return :name, name
end

#name_space(name_space = nil) ⇒ Object



78
79
80
# File 'lib/chapp/app_config.rb', line 78

def name_space name_space=nil
  set_or_return :name_space, name_space
end

#node(node = nil) ⇒ Object



142
143
144
# File 'lib/chapp/app_config.rb', line 142

def node node=nil
  set_or_return :node, node
end

#post_run_list(*recipes) ⇒ Object



134
135
136
137
138
139
140
# File 'lib/chapp/app_config.rb', line 134

def post_run_list *recipes
  if recipes.length > 0
    @post_run_list = recipes
  else
    @post_run_list
  end
end

#pre_run_list(*recipes) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/chapp/app_config.rb', line 126

def pre_run_list *recipes
  if recipes.length > 0
    @pre_run_list = recipes
  else
    @pre_run_list
  end
end

#recipe(recipe = nil) ⇒ Object



114
115
116
# File 'lib/chapp/app_config.rb', line 114

def recipe recipe=nil
  set_or_return_with_default :recipe, DEFAULT_RECIPE, recipe
end

#role_nameObject



98
99
100
# File 'lib/chapp/app_config.rb', line 98

def role_name
  "chapp_#{id}"
end

#run_list(run_list = nil) ⇒ Object



150
151
152
# File 'lib/chapp/app_config.rb', line 150

def run_list run_list=nil
  set_or_return :run_list, run_list
end

#to_hashObject



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/chapp/app_config.rb', line 158

def to_hash
  hash = Hash.new

  hash.store "name_space", name_space
  hash.store "name", name
  hash.store "used_apps", used_apps

  hash.store "cloud", cloud

  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



118
119
120
# File 'lib/chapp/app_config.rb', line 118

def type type=nil
  set_or_return_with_default :type, cookbook, type
end

#uses(app_id) ⇒ Object



106
107
108
# File 'lib/chapp/app_config.rb', line 106

def uses app_id
  @used_apps << app_id
end