Class: VMC::KNIFE::ApplicationEnvironment
- Inherits:
-
Object
- Object
- VMC::KNIFE::ApplicationEnvironment
- Defined in:
- lib/vmc_knife/vmc_knife.rb
Overview
Read/Write the application environment. a list of strings where the first ‘=’ character separate the key and values.
Instance Attribute Summary collapse
-
#application ⇒ Object
Returns the value of attribute application.
-
#wrapped ⇒ Object
Returns the value of attribute wrapped.
Instance Method Summary collapse
- #append(name, value) ⇒ Object
- #del(name) ⇒ Object
- #get(name) ⇒ Object
-
#initialize(data, application) ⇒ ApplicationEnvironment
constructor
A new instance of ApplicationEnvironment.
-
#set(name, value) ⇒ Object
Sets a variable.
Constructor Details
#initialize(data, application) ⇒ ApplicationEnvironment
Returns a new instance of ApplicationEnvironment.
232 233 234 235 |
# File 'lib/vmc_knife/vmc_knife.rb', line 232 def initialize(data, application) @wrapped = data @application = application end |
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
231 232 233 |
# File 'lib/vmc_knife/vmc_knife.rb', line 231 def application @application end |
#wrapped ⇒ Object
Returns the value of attribute wrapped.
231 232 233 |
# File 'lib/vmc_knife/vmc_knife.rb', line 231 def wrapped @wrapped end |
Instance Method Details
#append(name, value) ⇒ Object
267 268 269 |
# File 'lib/vmc_knife/vmc_knife.rb', line 267 def append(name,value) @wrapped << "#{name}=#{value}" end |
#del(name) ⇒ Object
264 265 266 |
# File 'lib/vmc_knife/vmc_knife.rb', line 264 def del(name) @wrapped.keep_if {|v| v =~ /^#{name}=/; $0.nil?} end |
#get(name) ⇒ Object
254 255 256 257 258 259 260 261 262 263 |
# File 'lib/vmc_knife/vmc_knife.rb', line 254 def get(name) @wrapped.each do |e| /^([\w]*)=(.*)$/ =~ e if ($1 == name) #puts "#{k}=name{v}" return $2 end end return nil end |
#set(name, value) ⇒ Object
Sets a variable. Replaces other environment variables with the same name if there is such a thing.
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/vmc_knife/vmc_knife.rb', line 238 def set(name,value) foundit = false @wrapped.map! do |item| /^([\w]*)=(.*)$/ =~ item #puts "#{name} 1=#{$1} and 2=#{$2}" if ($1 == name) #puts "updating #{$1}" foundit = true "#{$1}=#{value}" else item end end #puts "appending #{name}=#{value}" unless foundit append(name,value) unless foundit end |