Class: ActiveAws::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_aws/base.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**params) {|_self| ... } ⇒ Base

Returns a new instance of Base.

Yields:

  • (_self)

Yield Parameters:



33
34
35
36
37
38
39
# File 'lib/active_aws/base.rb', line 33

def initialize( **params )
  self.class.attributes.each do |k|
    method = "#{k}="
    self.send(method, params[k]) if params[k].present?
  end
  yield( self ) if block_given?
end

Class Attribute Details

.attributesObject

Returns the value of attribute attributes.



10
11
12
# File 'lib/active_aws/base.rb', line 10

def attributes
  @attributes
end

.root_configureObject (readonly)

Returns the value of attribute root_configure.



11
12
13
# File 'lib/active_aws/base.rb', line 11

def root_configure
  @root_configure
end

Class Method Details

.configureObject



28
29
30
# File 'lib/active_aws/base.rb', line 28

def configure
  Base.root_configure
end

.inherited(klass) ⇒ Object



13
14
15
# File 'lib/active_aws/base.rb', line 13

def inherited( klass )
  klass.attributes = @attributes
end

.load_config!(args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/active_aws/base.rb', line 17

def load_config!( args )
  @config = if args.is_a? Hash
    args
  elsif File.file?( args.to_s )
    YAML.load_file( args.to_s )
  else
    raise ArgumentError
  end
  @root_configure = Configure.new( **@config.symbolize_keys )
end

Instance Method Details

#nameObject



41
42
43
44
45
# File 'lib/active_aws/base.rb', line 41

def name
  name_tag = tags.detect{|t| t[:key].to_s == "Name"}
  return nil unless name_tag
  name_tag[:value]
end

#to_hObject



47
48
49
50
51
52
# File 'lib/active_aws/base.rb', line 47

def to_h
  self.class.attributes.reduce({}) do |acc,k|
    acc[k] = self.send( k )
    acc
  end
end