Module: Composable::Core::AttributeDSL

Extended by:
ActiveSupport::Concern
Includes:
InheritableAttributes
Defined in:
lib/composable/core/attribute_dsl.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attributesObject



30
31
32
# File 'lib/composable/core/attribute_dsl.rb', line 30

def attributes
  self.class.attributes
end

#initialize(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/composable/core/attribute_dsl.rb', line 14

def initialize(options = {})
  unless options.respond_to?(:has_key?)
    raise ArgumentError, "When assigning attributes, you must pass a hash" \
                         " as an argument, #{options.class} passed."
  end

  attributes.each do |attribute|
    # Try a `string` key if `symbol` key does not exist
    value = options.delete(attribute.to_sym)
    value = options.delete(attribute.to_s) if value.nil?
    send("#{attribute}=", value) unless value.nil?
  end

  @rest = options
end

#paramsObject



34
35
36
37
38
# File 'lib/composable/core/attribute_dsl.rb', line 34

def params
  attributes.each_with_object({}) do |attribute, hash|
    hash[attribute] = send(attribute)
  end
end

#restObject



40
41
42
# File 'lib/composable/core/attribute_dsl.rb', line 40

def rest
  @rest
end