class Particle::Model

Base class for domain models

Public Class Methods

attribute_reader(*keys) click to toggle source

Define accessor methods for attributes.

Will load the attributes from the cloud if not already done

# File lib/particle/model.rb, line 30
def self.attribute_reader(*keys)
  keys.each do |key|
    define_method key do
      attributes[key]
    end
  end
end
new(client, attributes) click to toggle source
# File lib/particle/model.rb, line 5
def initialize(client, attributes)
  @client = client
  @attributes =
    if attributes.is_a?(String) || attributes.is_a?(Integer)
      { id: attributes }
    else
      # Consider attributes loaded when passed in through constructor
      @loaded = true
      attributes
    end
end

Public Instance Methods

attributes() click to toggle source

Hash of all attributes returned by the cloud

# File lib/particle/model.rb, line 39
def attributes
  get_attributes unless @loaded
  @attributes
end
get_attributes() click to toggle source

Load the model attributes with the correct API call in subclasses

# File lib/particle/model.rb, line 45
def get_attributes
  raise "Implement in subclasses and set @loaded = true"
end
id() click to toggle source

Accessor for the id

# File lib/particle/model.rb, line 23
def id
  @attributes[:id]
end
inspect() click to toggle source

Display the attributes when inspecting the object in the console

# File lib/particle/model.rb, line 18
def inspect
  "#<#{self.class} #{@attributes}>"
end