Module: Her::Model

Extended by:
ActiveSupport::Concern
Includes:
Introspection, ORM, Paths, Relationships
Included in:
Base
Defined in:
lib/her/model.rb,
lib/her/model/orm.rb,
lib/her/model/base.rb,
lib/her/model/http.rb,
lib/her/model/hooks.rb,
lib/her/model/paths.rb,
lib/her/model/introspection.rb,
lib/her/model/relationships.rb,
lib/her/model/orm/find_methods.rb,
lib/her/model/orm/save_methods.rb,
lib/her/model/orm/error_methods.rb,
lib/her/model/orm/create_methods.rb,
lib/her/model/orm/update_methods.rb,
lib/her/model/orm/destroy_methods.rb,
lib/her/model/orm/relation_mapper.rb,
lib/her/model/orm/fields_definition.rb,
lib/her/model/orm/comparison_methods.rb,
lib/her/model/orm/persistance_methods.rb,
lib/her/model/orm/serialization_methods.rb

Overview

This module is the main element of Her. After creating a Her::API object, include this module in your models to get a few magic methods defined in them.

Examples:

class User
  include Her::Model
end

@user = User.new(:name => "Rémi")
@user.save

Defined Under Namespace

Modules: Base, HTTP, Hooks, Introspection, ORM, Paths, Relationships

Instance Attribute Summary

Attributes included from ORM

#data, #errors, #metadata

Instance Method Summary collapse

Methods included from Relationships

#get_relationship, #has_relationship?

Methods included from Paths

#request_path

Methods included from Introspection

#inspect

Methods included from ORM

#assign_data, #convert_types, #get_data, #has_data?, #id, #initialize, initialize_collection, #method_missing, #respond_to?, use_setter_methods

Methods included from ORM::SerializationMethods

#hash, #to_params

Methods included from ORM::PersistanceMethods

#destroyed?, #new?, #persisted?

Methods included from ORM::ComparisonMethods

#==, #eql?

Methods included from ORM::ErrorMethods

#invalid?, #valid?

Methods included from ORM::UpdateMethods

#update_attribute, #update_attributes, #update_attributes!

Methods included from ORM::SaveMethods

#create_or_update, #save, #save!

Methods included from ORM::DestroyMethods

#delete, #destroy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Her::Model::ORM

Instance Method Details

#[](attribute_name) ⇒ Object

Returns

  • the value of the attribute_nane attribute if it’s in orm data

  • the resource/collection corrsponding to attribute_name if it’s a relationship



64
65
66
67
# File 'lib/her/model.rb', line 64

def [](attribute_name)
  get_data(attribute_name) ||
  get_relationship(attribute_name)
end

#has_key?(attribute_name) ⇒ Boolean

Returns true if attribute_name is

  • in orm data

  • a relationship

Returns:

  • (Boolean)


56
57
58
59
# File 'lib/her/model.rb', line 56

def has_key?(attribute_name)
  has_data?(attribute_name) ||
  has_relationship?(attribute_name)
end