Class: Atheme::EntityBase

Inherits:
Object
  • Object
show all
Defined in:
lib/atheme/entity.rb

Direct Known Subclasses

Entity, User

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#tokenObject (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