Class: TelestreamCloud::Base
- Inherits:
-
Object
- Object
- TelestreamCloud::Base
show all
- Extended by:
- Forwardable
- Includes:
- Builders, Finders, Router
- Defined in:
- lib/telestream_cloud/base.rb
Constant Summary
Constants included
from Router
Router::VAR_PATTERN
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Finders
included
Methods included from Builders
#create, #create!, included
Methods included from Router
included, #replace_pattern_with_self_variables
Constructor Details
#initialize(attributes = {}) ⇒ Base
Returns a new instance of Base.
12
13
14
15
|
# File 'lib/telestream_cloud/base.rb', line 12
def initialize(attributes = {})
clear_attributes
load(attributes)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *arguments) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/telestream_cloud/base.rb', line 94
def method_missing(method_symbol, *arguments)
method_name = method_symbol.to_s
if method_name =~ /(=|\?)$/
case $1
when '='
attributes[$`] = arguments.first
@changed_attributes[$`] = arguments.first
when '?'
!! attributes[$`]
end
else
return attributes[method_name] if attributes.include?(method_name)
super
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5
6
7
|
# File 'lib/telestream_cloud/base.rb', line 5
def attributes
@attributes
end
|
#errors ⇒ Object
Returns the value of attribute errors.
5
6
7
|
# File 'lib/telestream_cloud/base.rb', line 5
def errors
@errors
end
|
Class Method Details
.sti_name ⇒ Object
18
19
20
|
# File 'lib/telestream_cloud/base.rb', line 18
def sti_name
"#{name.split('::').last}"
end
|
Instance Method Details
#changed? ⇒ Boolean
23
24
25
|
# File 'lib/telestream_cloud/base.rb', line 23
def changed?
!@changed_attributes.empty?
end
|
#id ⇒ Object
31
32
33
|
# File 'lib/telestream_cloud/base.rb', line 31
def id
attributes['id']
end
|
#id=(id) ⇒ Object
35
36
37
|
# File 'lib/telestream_cloud/base.rb', line 35
def id=(id)
attributes['id'] = id
end
|
#inspect ⇒ Object
44
45
46
47
|
# File 'lib/telestream_cloud/base.rb', line 44
def inspect
attributes_as_nice_string = self.attributes.map {|k,v| "#{k}: #{v.inspect}"}.compact.join(", ")
"#<#{self.class} #{attributes_as_nice_string}>"
end
|
#new? ⇒ Boolean
27
28
29
|
# File 'lib/telestream_cloud/base.rb', line 27
def new?
id.nil?
end
|
#reload ⇒ Object
39
40
41
42
|
# File 'lib/telestream_cloud/base.rb', line 39
def reload
perform_reload
self
end
|
#to_json(*args) ⇒ Object
49
50
51
|
# File 'lib/telestream_cloud/base.rb', line 49
def to_json(*args)
MultiJson.encode(self.attributes)
end
|