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) {|_self| ... } ⇒ EntityBase
constructor
A new instance of EntityBase.
- #method_missing(meth, *args, &block) ⇒ Object
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 (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
27 28 29 |
# File 'lib/atheme/entity.rb', line 27 def fetch! raise "#{self} does not know how to update itself. Slap the developer!" end |