class MtgApi::Config

the configured properties of an entity

Attributes

attributes[RW]

the stored properties of this config

name[RW]

the stored properties of this config

properties[RW]

the stored properties of this config

setters[RW]

the stored properties of this config

Public Class Methods

new(clazz) click to toggle source

store the class name and initialize empty lists

# File lib/mtg_api/config.rb, line 10
def initialize(clazz)
  self.name = clazz.name
  self.attributes = []
  self.properties = []
  self.setters = {}
end

Public Instance Methods

accessors() click to toggle source

the list of attributes to build attr_accessors for

# File lib/mtg_api/config.rb, line 18
def accessors
  attributes + properties - setters.keys
end
attribute(*attributes) click to toggle source

add to the attributes list (queryable)

# File lib/mtg_api/config.rb, line 23
def attribute(*attributes)
  self.attributes += attributes
end
endpoint() click to toggle source

the endpoint to send to the api for the entity

# File lib/mtg_api/config.rb, line 28
def endpoint
  @endpoint ||= '/' + response_key
end
full_config() click to toggle source

the full list of attributes set

# File lib/mtg_api/config.rb, line 33
def full_config
  (attributes + properties + setters.keys).uniq
end
property(*properties) click to toggle source

add to the properties list (unqueryable)

# File lib/mtg_api/config.rb, line 38
def property(*properties)
  self.properties += properties
end
response_key() click to toggle source

the key in the response for the api

# File lib/mtg_api/config.rb, line 43
def response_key
  @response_key ||= name.downcase.split('::').last + 's'
end
setter(attribute, clazz = nil, &block) click to toggle source

build a setter that can map the return value from the api

# File lib/mtg_api/config.rb, line 48
def setter(attribute, clazz = nil, &block)
  setters[attribute] = proc do |value|
    value = clazz.nil? ? block.call(value) : clazz.new(value)
    instance_variable_set(:"@#{attribute}", value)
  end
end