Module Her::Model::Parse::ClassMethods
In: lib/her/model/parse.rb

Methods

Public Instance methods

Extract an array from the request data

@example

  # with parse_root_in_json true, :format => :active_model_serializers
  class User
    include Her::Model
    parse_root_in_json true, :format => :active_model_serializers
  end

  users = User.all # { :users => [ { :id => 1, :name => "Tobias" } ] }
  users.first.name # => "Tobias"

  # without parse_root_in_json
  class User
    include Her::Model
  end

  users = User.all # [ { :id => 1, :name => "Tobias" } ]
  users.first.name # => "Tobias"

@private

Return or change the value of `include_root_in_json`

@example

  class User
    include Her::Model
    include_root_in_json true
  end

Parse data before assigning it to a resource, based on `parse_root_in_json`.

@param [Hash] data @private

Return or change the value of `parse_root_in_json`

@example

  class User
    include Her::Model
    parse_root_in_json true
  end

  class User
    include Her::Model
    parse_root_in_json true, format: :active_model_serializers
  end

  class User
    include Her::Model
    parse_root_in_json true, format: :json_api
  end

Return or change the value of `request_new_object_on_build`

@example

  class User
    include Her::Model
    request_new_object_on_build true
  end

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

@example

  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"

[Validate]