class Polyseerio::Resource::Base

Base class for any resource.

Attributes

attributes[RW]
eid[RW]

Public Class Methods

new(attributes = {}) click to toggle source
# File lib/resource/base.rb, line 10
def initialize(attributes = {})
  @eid = if attributes.include? :eid
           attributes[:eid]
         else
           Polyseerio::SDK::Helper.resolve_eid(copts)
         end
  @attributes = attributes
end

Public Instance Methods

copts() click to toggle source

Returns the client options this class was constructed with.

# File lib/resource/base.rb, line 37
def copts
  self.class.copts
end
get(key, default = nil) click to toggle source

TODO: move towards this

# File lib/resource/base.rb, line 52
def get(key, default = nil)
  @attributes.fetch(key, default)
end
method_missing(name, *args) click to toggle source
# File lib/resource/base.rb, line 61
def method_missing(name, *args) # rubocop:disable all
  # Setter.
  if name =~ /^(\w+)=$/
    name = :"#{$1}" # rubocop:disable all

    @attributes[:"#{$1}"] = args[0] # rubocop:disable all
  end

  # Getter.
  @attributes.fetch(name, nil)
end
new?() click to toggle source

True if the resource is new (not yet saved).

# File lib/resource/base.rb, line 47
def new?
  id.nil?
end
override_properties(properties) click to toggle source

Set a property hash on the instance.

# File lib/resource/base.rb, line 20
def override_properties(properties)
  properties.each_with_object(self) do |(key, value), this|
    this.send(:"#{key}=", value)
  end
end
properties() click to toggle source

Returns a copy of class attributes.

# File lib/resource/base.rb, line 27
def properties
  attributes.clone
end
request() click to toggle source

Returns the client's request object.

# File lib/resource/base.rb, line 42
def request
  self.class.request
end
respond_to_missing?(method_name) click to toggle source
# File lib/resource/base.rb, line 73
def respond_to_missing?(method_name)
  !methods.include(method_name)
end
set(key, value) click to toggle source

TODO: move towards this

# File lib/resource/base.rb, line 57
def set(key, value)
  @attributes[key] = value
end
type() click to toggle source

Returns the type of the class.

# File lib/resource/base.rb, line 32
def type
  self.class.type
end