module Spyke::AttributeAssignment::ClassMethods

Public Instance Methods

attributes(*names) click to toggle source

By adding instance methods via an included module, they become overridable with “super”. thepugautomatic.com/2013/07/dsom/

# File lib/spyke/attribute_assignment.rb, line 16
def attributes(*names)
  unless instance_variable_defined?(:@spyke_instance_method_container)
    @spyke_instance_method_container = Module.new
    include @spyke_instance_method_container
  end

  @spyke_instance_method_container.module_eval do
    names.each do |name|
      define_method(name) do
        attribute(name)
      end

      define_method(:"#{name}=") do |value|
        set_attribute(name, value)
      end
    end
  end
end