Module: Gamifier::Model::ClassMethods

Included in:
Gamifier::Model
Defined in:
lib/gamifier/model.rb

Instance Method Summary collapse

Instance Method Details

#containerObject

Returns the container to use when submitting data. E.g. when submitting user attributes as user=xxx, the container is ‘user’. Basically, this is the underscored class name.



200
201
202
# File 'lib/gamifier/model.rb', line 200

def container
  Gamifier.underscore(name)
end

#mutable_attributes(*values) ⇒ Object

Define the attributes that will be sent when creating or updating a model.



185
186
187
# File 'lib/gamifier/model.rb', line 185

def mutable_attributes *values
  store_or_get("@mutable_attributes", values)
end

#path(value = nil) ⇒ Object

Sets or retrieve the path to use to access the resource on the remote server. By default the path will be the pluralized container name (naive pluralization: container+s).



169
170
171
172
173
174
175
# File 'lib/gamifier/model.rb', line 169

def path(value = nil)
  if value.nil?
    @path ||= container+"s"
  else
    @path = value
  end
end

#reset!Object



162
163
164
# File 'lib/gamifier/model.rb', line 162

def reset!
  @path = nil
end

#special_attributes(*values) ⇒ Object

Declare attributes that must be submitted outside the default container.



179
180
181
# File 'lib/gamifier/model.rb', line 179

def special_attributes *values
  store_or_get("@special_attributes", values)
end

#store_or_get(variable, values) ⇒ Object



189
190
191
192
193
194
195
196
# File 'lib/gamifier/model.rb', line 189

def store_or_get(variable, values)
  if values.empty?
    v = instance_variable_get(variable)
    v ||= []
  else
    instance_variable_set(variable, values.map{|v| v.to_sym})
  end
end