Class: LHS::Record

Inherits:
Object
  • Object
show all
Includes:
Inspect, Pagination, AttributeAssignment, Batch, Chainable, Configuration, Create, CustomSetters, Destroy, Endpoints, Equality, Find, FindBy, First, Last, Mapping, Model, Relations, Request, RequestCycleCache, 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/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/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,
lib/lhs/concerns/record/request_cycle_cache/interceptor.rb,
lib/lhs/concerns/record/request_cycle_cache/request_cycle_thread_registry.rb

Defined Under Namespace

Modules: AttributeAssignment, Batch, Chainable, Configuration, Create, CustomSetters, Destroy, Endpoints, Equality, Find, FindBy, First, Last, Mapping, Model, Pagination, Relations, Request, RequestCycleCache, 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 Inspect

#inspect

Methods included from Equality

#==

Methods included from Chainable

#options

Constructor Details

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

Returns a new instance of Record.



77
78
79
80
81
82
# File 'lib/lhs/record.rb', line 77

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)



100
101
102
# File 'lib/lhs/record.rb', line 100

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

Class Method Details

.build(data = nil) ⇒ Object



88
89
90
# File 'lib/lhs/record.rb', line 88

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

Instance Method Details

#as_json(options = nil) ⇒ Object



84
85
86
# File 'lib/lhs/record.rb', line 84

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`.



94
95
96
# File 'lib/lhs/record.rb', line 94

def dup
  clone
end