class Constructable::Attribute

Constants

ATTRIBUTES

Public Class Methods

new(name, options = {}) click to toggle source
# File lib/constructable/attribute.rb, line 6
def initialize(name, options = {})
  @name = name
  ATTRIBUTES.each do |attribute|
    self.send(:"#{attribute}=", options[attribute])
  end
end

Public Instance Methods

accessible=(boolean) click to toggle source
# File lib/constructable/attribute.rb, line 13
def accessible=(boolean)
  if boolean
    self.readable = true
    self.writable = true
  end
end
attr_writer_symbol() click to toggle source
# File lib/constructable/attribute.rb, line 24
def attr_writer_symbol
  (self.name.to_s + '=').to_sym
end
ivar_symbol() click to toggle source
# File lib/constructable/attribute.rb, line 20
def ivar_symbol
  ('@' + self.name.to_s).to_sym
end
process(value) click to toggle source
# File lib/constructable/attribute.rb, line 28
def process(value)
  unless value.nil?
    self.converter ? converter.(value) : value
  else
    raise AttributeError, ":#{self.name} is a required attribute" if self.required
    self.default.call if self.default
  end
end