Method: Her::Model::Parse::ClassMethods#root_element

Defined in:
lib/her/model/parse.rb

#root_element(value = nil) ⇒ Object

Return or change the value of ‘root_element`. Always defaults to the base name of the class.

Examples:

class User
  include Her::Model
  parse_root_in_json true
  root_element :huh
end

user = User.find(1) # { :huh => { :id => 1, :name => "Tobias" } }
user.name # => "Tobias"


133
134
135
136
137
138
139
140
141
142
143
# File 'lib/her/model/parse.rb', line 133

def root_element(value = nil)
  if value.nil?
    if json_api_format?
      @_her_root_element ||= self.name.split("::").last.pluralize.underscore.to_sym
    else
      @_her_root_element ||= self.name.split("::").last.underscore.to_sym
    end
  else
    @_her_root_element = value.to_sym
  end
end