Class: Canals::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/canals/environment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Environment

Returns a new instance of Environment.



8
9
10
11
12
13
14
# File 'lib/canals/environment.rb', line 8

def initialize(args)
  @args = validate?(args)
  @name = @args[:name]
  @user = @args[:user]
  @hostname = @args[:hostname]
  @pem = @args[:pem]
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



7
8
9
# File 'lib/canals/environment.rb', line 7

def hostname
  @hostname
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/canals/environment.rb', line 7

def name
  @name
end

#pemObject (readonly)

Returns the value of attribute pem.



7
8
9
# File 'lib/canals/environment.rb', line 7

def pem
  @pem
end

#userObject (readonly)

Returns the value of attribute user.



7
8
9
# File 'lib/canals/environment.rb', line 7

def user
  @user
end

Instance Method Details

#default=(val) ⇒ Object



22
23
24
# File 'lib/canals/environment.rb', line 22

def default=(val)
  @args[:default] = !!val
end

#is_default?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/canals/environment.rb', line 26

def is_default?
  !!@args[:default]
end

#to_hashObject



34
35
36
# File 'lib/canals/environment.rb', line 34

def to_hash
  Marshal.load(Marshal.dump(@args))
end

#to_yamlObject



30
31
32
# File 'lib/canals/environment.rb', line 30

def to_yaml
  Canals::Tools::YAML.to_yaml(@args)
end

#validate?(args) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



16
17
18
19
20
# File 'lib/canals/environment.rb', line 16

def validate?(args)
  vargs = args.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
  raise CanalEnvironmentError.new("Missing option: \"name\" in environment creation") if vargs[:name].nil?
  vargs
end