module Commutator::Model::Attributes::ClassMethods

Public Instance Methods

attribute(*attr_names) click to toggle source
# File lib/commutator/model/attributes.rb, line 44
def attribute(*attr_names)
  options = attr_names.extract_options!

  attr_names.each do |attr_name|
    attribute_names << attr_name

    # Skip reader and writer methods entirely
    next if options[:accessor] == false

    define_writer(attr_name, options) unless options[:writer] == false
    attr_reader attr_name unless options[:reader] == false
  end
end
attribute_names() click to toggle source
# File lib/commutator/model/attributes.rb, line 58
def attribute_names
  @attribute_names ||= Set.new
end

Private Instance Methods

define_writer(attr_name, options) click to toggle source
# File lib/commutator/model/attributes.rb, line 64
def define_writer(attr_name, options)
  define_method "#{attr_name}=" do |value|
    instance_variable_set("@#{attr_name}", convert_type(value, options))
  end
end