Class: LHS::Record

Inherits:
Object
  • Object
show all
Includes:
Inspect, IsHref, Pagination, AttributeAssignment, Batch, Chainable, Configuration, Create, CustomSetters, Destroy, Endpoints, Equality, Find, FindBy, First, HrefFor, Last, Mapping, Merge, Model, Provider, Relations, Request, Scope, Tracing
Defined in:
lib/lhs/record.rb,
lib/lhs/concerns/record/find.rb,
lib/lhs/concerns/record/last.rb,
lib/lhs/concerns/record/batch.rb,
lib/lhs/concerns/record/first.rb,
lib/lhs/concerns/record/merge.rb,
lib/lhs/concerns/record/model.rb,
lib/lhs/concerns/record/scope.rb,
lib/lhs/concerns/record/create.rb,
lib/lhs/concerns/record/destroy.rb,
lib/lhs/concerns/record/find_by.rb,
lib/lhs/concerns/record/mapping.rb,
lib/lhs/concerns/record/request.rb,
lib/lhs/concerns/record/tracing.rb,
lib/lhs/concerns/record/equality.rb,
lib/lhs/concerns/record/href_for.rb,
lib/lhs/concerns/record/provider.rb,
lib/lhs/concerns/record/chainable.rb,
lib/lhs/concerns/record/endpoints.rb,
lib/lhs/concerns/record/relations.rb,
lib/lhs/concerns/record/pagination.rb,
lib/lhs/concerns/record/configuration.rb,
lib/lhs/concerns/record/custom_setters.rb,
lib/lhs/concerns/record/attribute_assignment.rb

Defined Under Namespace

Modules: AttributeAssignment, Batch, Chainable, Configuration, Create, CustomSetters, Destroy, Endpoints, Equality, Find, FindBy, First, HrefFor, Last, Mapping, Merge, Model, Pagination, Provider, Relations, Request, Scope, Tracing

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AttributeAssignment

#assign_attributes

Methods included from Model

#persisted?, #to_model

Methods included from Merge

#deep_merge, #deep_merge!, #merge, #merge!

Methods included from Inspect

#inspect

Methods included from Equality

#==

Methods included from Chainable

#options

Constructor Details

#initialize(data = nil, apply_customer_setters = true) ⇒ Record


79
80
81
82
83
84
# File 'lib/lhs/record.rb', line 79

def initialize(data = nil, apply_customer_setters = true)
  data ||= LHS::Data.new({}, nil, self.class)
  data = LHS::Data.new(data, nil, self.class) unless data.is_a?(LHS::Data)
  define_singleton_method(:_data) { data }
  apply_custom_setters! if apply_customer_setters
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)


102
103
104
# File 'lib/lhs/record.rb', line 102

def method_missing(name, *args, &block)
  _data.send(name, *args, &block)
end

Class Method Details

.build(data = nil) ⇒ Object


90
91
92
# File 'lib/lhs/record.rb', line 90

def self.build(data = nil)
  new(data)
end

Instance Method Details

#as_json(options = nil) ⇒ Object


86
87
88
# File 'lib/lhs/record.rb', line 86

def as_json(options = nil)
  _data.as_json(options)
end

#dupObject

Override Object#dup because it doesn't support copying any singleton methods, which leads to missing `_data` method when you execute `dup`.


96
97
98
# File 'lib/lhs/record.rb', line 96

def dup
  clone
end