Class: RelaxDB::ViewObject

Inherits:
Object
  • Object
show all
Defined in:
lib/relaxdb/view_object.rb

Overview

An immuntable object typically used to display the results of a view

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ ViewObject

Returns a new instance of ViewObject.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/relaxdb/view_object.rb', line 6

def initialize(hash)
  hash.each do |k, v|

    if k.to_s =~ /_at$/
      v = Time.parse(v).utc rescue v
    end

    instance_variable_set("@#{k}", v)
    meta_class.instance_eval do
      define_method(k.to_sym) do
        instance_variable_get("@#{k}".to_sym)
      end
    end      
  end
end

Class Method Details

.create(obj) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/relaxdb/view_object.rb', line 22

def self.create(obj)
  if obj.instance_of? Array
    obj.inject([]) { |arr, o| arr << ViewObject.new(o) }
  elsif obj.instance_of? Hash
    ViewObject.new(obj)
  else
    obj
  end
end