Class: AWSConfig::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_config/profile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, entries) ⇒ Profile

Returns a new instance of Profile.



5
6
7
8
# File 'lib/aws_config/profile.rb', line 5

def initialize(name, entries)
  @name    = name.to_s
  @entries = entries
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(id, *args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/aws_config/profile.rb', line 39

def method_missing(id, *args)
  if has_key?(id)
    self[id]
  elsif source_profile?
    if entries["source_profile"].respond_to?(id)
      entries["source_profile"].send(id, args)
    else
      super
    end
  else
    super
  end
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



3
4
5
# File 'lib/aws_config/profile.rb', line 3

def entries
  @entries
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/aws_config/profile.rb', line 3

def name
  @name
end

Instance Method Details

#[](key) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/aws_config/profile.rb', line 10

def [](key)
  key = key.to_s
  if entries.has_key?(key)
    entries[key]
  elsif source_profile?
    entries["source_profile"][key]
  else
    nil
  end
end

#[]=(key, value) ⇒ Object



21
22
23
24
# File 'lib/aws_config/profile.rb', line 21

def []=(key, value)
  key = key.to_s
  entries[key] = value
end

#config_hashObject



53
54
55
56
57
58
59
# File 'lib/aws_config/profile.rb', line 53

def config_hash
  {
    access_key_id:      self["aws_access_key_id"],
    secret_access_key:  self["aws_secret_access_key"],
    region:             self["region"]
  }
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/aws_config/profile.rb', line 26

def has_key?(key)
  key = key.to_s
  entries.has_key?(key)
end

#merge!(other) ⇒ Object



61
62
63
64
# File 'lib/aws_config/profile.rb', line 61

def merge!(other)
  @entries = Parser.from_hash(entries.merge(other.entries))
  self
end

#respond_to?(id, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/aws_config/profile.rb', line 35

def respond_to?(id, include_all = false)
  has_key?(id) || super
end

#source_profile?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/aws_config/profile.rb', line 31

def source_profile?
  entries.key?("source_profile") && entries["source_profile"].is_a?(Profile)
end