Class: Akashi::Base
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/akashi/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(id) ⇒ Base
Returns a new instance of Base.
10
11
12
|
# File 'lib/akashi/base.rb', line 10
def initialize(id)
@object = self.class.base_class.new(id)
end
|
Class Method Details
.all ⇒ Object
15
16
17
|
# File 'lib/akashi/base.rb', line 15
def all
collection.map { |object| new(object.id) }
end
|
.base_class ⇒ Object
45
46
47
|
# File 'lib/akashi/base.rb', line 45
def base_class
@base_class ||= "::AWS::#{service_class}::#{object_class}".constantize
end
|
.collection ⇒ Object
41
42
43
|
# File 'lib/akashi/base.rb', line 41
def collection
Akashi::Aws.send(service_class.underscore).send(object_class.underscore.pluralize)
end
|
.find(id) ⇒ Object
25
26
27
28
29
|
# File 'lib/akashi/base.rb', line 25
def find(id)
instances = where(id: id)
fail "#{id} does not exist" if instances.empty?
instances.first
end
|
.find_by(conditions = {}) ⇒ Object
31
32
33
34
35
|
# File 'lib/akashi/base.rb', line 31
def find_by(conditions = {})
instances = where(conditions)
fail "#{conditions} does not exist" if instances.empty?
instances.first
end
|
.object_class ⇒ Object
37
38
39
|
# File 'lib/akashi/base.rb', line 37
def object_class
@object_class ||= self.to_s.demodulize
end
|
.where(conditions = {}) ⇒ Object
19
20
21
22
23
|
# File 'lib/akashi/base.rb', line 19
def where(conditions = {})
all.select do |instance|
conditions.all? { |k, v| instance.send(k.intern) == v }
end
end
|