Class: Plat::Layout

Inherits:
Object
  • Object
show all
Includes:
Configuru::Configurable
Defined in:
lib/plat/role.rb,
lib/plat/role.rb,
lib/plat/layout.rb,
lib/plat/layout/aws.rb,
lib/plat/layout/aws.rb,
lib/plat/layout/configuration.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Layout

Returns a new instance of Layout.



6
7
8
9
# File 'lib/plat/layout.rb', line 6

def initialize(options={},&block)
  configure(options,&block)
  configuration.lock
end

Instance Method Details

#aws_optionsObject



14
15
16
17
18
19
20
# File 'lib/plat/layout/aws.rb', line 14

def aws_options
  @aws_options ||= 
  {
    access_key_id: configuration.aws_access_key_id,
    secret_access_key: configuration.aws_secret_access_key
  }
end

#aws_resource_name(role, id = 0) ⇒ Object



30
31
32
# File 'lib/plat/layout/aws.rb', line 30

def aws_resource_name(role,id=0)
  aws_role_name_prefix(role)+'-'+id.to_s
end

#aws_role_name_prefix(role) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/plat/layout/aws.rb', line 22

def aws_role_name_prefix(role)
  @aws_role_name_prefix ||= {}
  @aws_role_name_prefix[role] ||= 
    [ configuration.name_prefix, 
      configuration.app_name, 
      configuration.env, 
      role ].map(&:to_s).delete_if{|s| s==''}.join('-').gsub(/\s/,'_')
end

#convert_roles(roles_def) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/plat/role.rb', line 5

def convert_roles(roles_def)
  case roles_def
    when Hash then roles_def
    when Array 
      roles_def.inject({}) do |result,elem|
        result.merge! convert_roles(elem)
      end
    when IO, StringIO, Tempfile then YAML.load(roles_def)
    when String, Pathname
      output = {}
      File.open(roles_def,"r") { |f| output = YAML.load(f) }
      output
    else
      raise ArgumentError.new("Wrong class for 'roles' value: #{roles_def.class}")
  end
end

#inspectObject



11
12
13
# File 'lib/plat/layout.rb', line 11

def inspect
  "<#{self.class} #{configuration.to_s}>"
end

#rolesObject



27
28
29
30
31
32
33
# File 'lib/plat/role.rb', line 27

def roles
  @roles ||= begin
    configuration.roles.map do |role,options|
      [ role, Plat::Role.create(self,role,options) ]
    end.to_h
  end
end