class Rbvore::Resource

Attributes

Public Class Methods

attr_collections(hash) click to toggle source

attr_collections sets up an associated list of objects that can be parsed from the json

# File lib/rbvore/resource.rb, line 42
def self.attr_collections(hash)
  hash.each do |name, klass|
    define_link_getter(name)
    define_method("#{name}=") do |ary|
      instance_variable_set(
        "@#{name}",
        parse_collection(ary, klass),
      )
    end
  end
end
attr_objects(hash) click to toggle source

attr_objects sets up an associated object that can be parsed from json

# File lib/rbvore/resource.rb, line 28
def self.attr_objects(hash)
  hash.each do |name, klass|
    define_link_getter(name)
    define_method("#{name}=") do |obj|
      instance_variable_set(
        "@#{name}",
        parse_object(obj, klass),
      )
    end
  end
end
attr_timestamp_accessor(*attrs) click to toggle source
# File lib/rbvore/resource.rb, line 54
def self.attr_timestamp_accessor(*attrs)
  attrs.each do |name|
    attr_reader(name)
    define_method("#{name}=") { |value|
      instance_variable_set("@#{name}", parse_timestamp(value))
    }
  end
end

Public Instance Methods

_embedded=(hash) click to toggle source
# File lib/rbvore/resource.rb, line 87
def _embedded=(hash)
  set_attributes(hash)
end
inspect() click to toggle source
# File lib/rbvore/resource.rb, line 91
def inspect
  "#<#{self.class} #{[@id, @name || @display_name].join(" ")}>"
end
set_attribute(key, value) click to toggle source
# File lib/rbvore/resource.rb, line 63
def set_attribute(key, value)
  setter = "#{self.class.underscore(key)}="
  send(setter, value) if respond_to?(setter)
end
set_attributes(hash) click to toggle source
# File lib/rbvore/resource.rb, line 68
def set_attributes(hash) # rubocop:disable Naming/AccessorMethodName
  hash.each do |key, value|
    set_attribute(key, value)
  end
end