Class: Atheme::EntityBase
- Inherits:
-
Object
- Object
- Atheme::EntityBase
- Defined in:
- lib/atheme/entity.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #fetch! ⇒ Object
-
#initialize(session, hash_or_token) ⇒ EntityBase
constructor
A new instance of EntityBase.
- #method_missing(meth, *args, &block) ⇒ Object
Constructor Details
#initialize(session, hash_or_token) ⇒ EntityBase
Returns a new instance of EntityBase.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# 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 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
19 20 21 22 23 |
# File 'lib/atheme/entity.rb', line 19 def method_missing(meth, *args, &block) super if @updated || !fetchable? do_fetch! self.send(meth, *args, &block) end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/atheme/entity.rb', line 4 def token @token end |
Instance Method Details
#fetch! ⇒ Object
25 26 27 |
# File 'lib/atheme/entity.rb', line 25 def fetch! raise "#{self} does not know how to update itself. Slap the developer!" end |