Module: Marquery::Attributable::ClassMethods

Defined in:
lib/marquery/attributable.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, type: nil, default: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/marquery/attributable.rb', line 15

def attribute(name, type: nil, default: nil)
  validate_type!(type) if type

  name = name.to_sym
  attributes[name] = {type: type, default: deep_freeze(default)}
  attr_reader name

  alias_method("#{name}?", name) if type == :bool
end

#attributesObject



25
26
27
# File 'lib/marquery/attributable.rb', line 25

def attributes
  @attributes ||= {}
end