Class: Atheme::EntityBase
- Inherits:
-
Object
- Object
- Atheme::EntityBase
show all
- Defined in:
- lib/atheme/entity.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(session, hash_or_token) {|_self| ... } ⇒ EntityBase
Returns a new instance of EntityBase.
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/atheme/entity.rb', line 5
def initialize(session, hash_or_token)
@session = session
if hash_or_token.kind_of?(Hash)
@updated = true
hash_or_token.each do |k, v|
self.instance_variable_set("@#{k}".to_sym, v)
define_singleton_method(k) { v }
end
else
@updated = false
@token = hash_or_token
end
yield self if block_given?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
21
22
23
24
25
|
# File 'lib/atheme/entity.rb', line 21
def method_missing(meth, *args, &block)
super if @updated || !fetchable?
do_fetch!
self.send(meth, *args, &block)
end
|
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
4
5
6
|
# File 'lib/atheme/entity.rb', line 4
def token
@token
end
|
Instance Method Details
#error? ⇒ Boolean
33
34
35
|
# File 'lib/atheme/entity.rb', line 33
def error?
false
end
|
#fetch! ⇒ Object
29
30
31
|
# File 'lib/atheme/entity.rb', line 29
def fetch!
raise "#{self} does not know how to update itself. Slap the developer!"
end
|
#success? ⇒ Boolean
37
38
39
|
# File 'lib/atheme/entity.rb', line 37
def success?
true
end
|
#to_ary ⇒ Object
27
|
# File 'lib/atheme/entity.rb', line 27
def to_ary; end
|