Class: RhoGallery::Base

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

Direct Known Subclasses

Consumer, Group

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Base

Returns a new instance of Base.



3
4
5
6
# File 'lib/rhogallery/base.rb', line 3

def initialize(data = {})
  @attributes = data
  @errors = String.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_sym, *arguments, &block) ⇒ Object (protected)



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/rhogallery/base.rb', line 63

def method_missing(method_sym, *arguments, &block)
  @attributes = RhoGallery.prepare_hash(@attributes)
  if method_sym.to_s.slice("=")
    att = method_sym.to_s.split("=").first.strip
    if @attributes[att.to_sym]
      @attributes[att.to_sym] = arguments.to_s
    else
      super
    end
  else
    att = @attributes[method_sym]
    if att
      att
    else
      super
    end
  end
end

Instance Method Details

#errorsObject



12
13
14
# File 'lib/rhogallery/base.rb', line 12

def errors
  @errors.strip
end

#idObject



8
9
10
# File 'lib/rhogallery/base.rb', line 8

def id
  @attributes[:id]
end