Module: Conjuration::Attributes::ClassMethods

Defined in:
lib/conjuration/concerns/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute(attribute_name, default: nil) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/conjuration/concerns/attributes.rb', line 42

def attribute(attribute_name, default: nil)
  define_method(attribute_name) do
    @attributes[attribute_name] ||= default
  end

  define_method("#{attribute_name}=") do |value|
    @attributes[attribute_name] = value
  end
end

#boolean_attribute(attribute_name) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/conjuration/concerns/attributes.rb', line 52

def boolean_attribute(attribute_name)
  attribute(attribute_name)

  define_method("#{attribute_name}?") do
    !!@attributes[attribute_name]
  end
end