module Composable::Core::AttributeDSL

Public Class Methods

new(options = {}) click to toggle source
# 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.fetch(attribute.to_sym, options[attribute.to_s])
    send("#{attribute}=", value) unless value.nil?
  end
end

Public Instance Methods

attributes() click to toggle source
# File lib/composable/core/attribute_dsl.rb, line 27
def attributes
  self.class.attributes
end
params() click to toggle source
# File lib/composable/core/attribute_dsl.rb, line 31
def params
  attributes.each_with_object({}) do |attribute, hash|
    hash[attribute] = send(attribute)
  end
end