Module: Weft::DSL::Attributes::ClassMethods

Defined in:
lib/weft/dsl/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, default: nil, **options) ⇒ Object

Declare a wire attribute. Accepts optional default: and type: kwargs. attribute :status, default: "active", type: :string



16
17
18
19
20
# File 'lib/weft/dsl/attributes.rb', line 16

def attribute(name, default: nil, **options)
  meta = { default: default }
  meta[:type] = options[:type] if options.key?(:type)
  own_attributes[name] = meta
end

#attributesObject

Returns all declared attributes (own + inherited), preserving declaration order.



23
24
25
26
27
28
29
# File 'lib/weft/dsl/attributes.rb', line 23

def attributes
  if superclass.respond_to?(:attributes)
    superclass.attributes.merge(own_attributes)
  else
    own_attributes.dup
  end
end