module LazyLazer::InstanceMethods

The methods to extend the instance with.

Public Class Methods

new(attributes = {}) click to toggle source

Create a new instance of the class from a set of source attributes. @param attributes [Hash] the model attributes @return [void] @raise RequiredAttribute if an attribute marked as required wasn't found

# File lib/lazy_lazer.rb, line 76
def initialize(attributes = {})
  @_lazer_model = InternalModel.new(self.class.instance_variable_get(:@_lazer_metadata), self)
  @_lazer_model.merge!(attributes)
  @_lazer_model.verify_required!
end

Public Instance Methods

==(other) click to toggle source

Equality check, performed using required keys. @param other [Object] the other object @return [Boolean]

Calls superclass method
# File lib/lazy_lazer.rb, line 85
def ==(other)
  return false if self.class != other.class
  return super if @_lazer_model.required_properties.empty?
  @_lazer_model.required_properties.each do |key_name|
    return false if read_attribute(key_name) != other.read_attribute(key_name)
  end
  true
end
[](key_name) click to toggle source

Return the value of the attribute, returning nil if not found. @param key_name [Symbol] the attribute name @return [Object] the returned value

# File lib/lazy_lazer.rb, line 97
def [](key_name)
  read_attribute(key_name)
rescue MissingAttribute
  nil
end
assign_attributes(new_attributes) click to toggle source

Update multiple attributes at once. @param new_attributes [Hash<Symbol, Object>] the new attributes @return [self] the updated object

# File lib/lazy_lazer.rb, line 106
def assign_attributes(new_attributes)
  new_attributes.each { |key, value| write_attribute(key, value) }
  self
end
Also aliased as: attributes=
attributes=(new_attributes)
Alias for: assign_attributes
reload() click to toggle source

Reload the object. Calls {#lazer_reload}, then merges the results into the internal store. Also clears out the internal cache. @return [self] the updated object

# File lib/lazy_lazer.rb, line 115
def reload
  new_attributes = lazer_reload.to_h
  @_lazer_model.merge!(new_attributes)
  self
end

Private Instance Methods

lazer_reload() click to toggle source

@abstract Provides reloading behaviour for lazy loading. @return [Hash] the result of reloading the hash

# File lib/lazy_lazer.rb, line 125
def lazer_reload
  {}
end