Class: Tumblargh::Resource::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tumblargh/resource/base.rb

Direct Known Subclasses

Blog, Dialogue, Note, Photo, Post, Tag, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Base

Returns a new instance of Base.



9
10
11
# File 'lib/tumblargh/resource/base.rb', line 9

def initialize(attrs={})
  self.attributes = attrs
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_symbol, *arguments) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tumblargh/resource/base.rb', line 19

def method_missing(method_symbol, *arguments)
  method_name = method_symbol.to_s

  if method_name =~ /(=|\?)$/
    case $1
    when "="
      attributes[$`] = arguments.first
    when "?"
      attributes[$`]
    end
  else
    return attributes[method_name] if attributes.include?(method_name)

    # propagating renderer context
    return context.send(method_symbol, *arguments) unless context.nil?
  end
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



13
14
15
# File 'lib/tumblargh/resource/base.rb', line 13

def attributes
  @attributes
end

#contextObject

Needed by renderer for context propagation



7
8
9
# File 'lib/tumblargh/resource/base.rb', line 7

def context
  @context
end