Module: PollEverywhere::Serializable::ClassMethods

Defined in:
lib/polleverywhere/serializable.rb

Instance Method Summary collapse

Instance Method Details

#from_hash(hash) ⇒ Object

Instanciate a class from a hash


157
158
159
# File 'lib/polleverywhere/serializable.rb', line 157

def from_hash(hash)
  new.from_hash(hash)
end

#prop(name, &block) ⇒ Object

Define a property at the class level


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/polleverywhere/serializable.rb', line 135

def prop(name, &block)
  # Setup instance methods on the class that give us a short cut to the prop values
  class_eval %{
    def #{name}=(val)
      value_set[:#{name}] = val
    end

    def #{name}
      value_set[:#{name}]
    end}
  
  prop_set[name].instance_eval(&block) if block
  # Return the property we just created so we can chain calls
  prop_set[name]
end

#prop_setObject

A property set that inherits superclass property sets.


152
153
154
# File 'lib/polleverywhere/serializable.rb', line 152

def prop_set
  @prop_set ||= Property::Set.new.merge superclass_prop_set
end

#root_key(name = nil) ⇒ Object

Set or get the root key of the model


130
131
132
# File 'lib/polleverywhere/serializable.rb', line 130

def root_key(name=nil)
  name ? @root_key = name.to_sym : @root_key
end