Module: Creatable

Defined in:
lib/creatable.rb,
lib/creatable/version.rb,
lib/creatable/instance_methods.rb

Overview

Main module you include in your class

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

VERSION =

VERSION

'2.1.0'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(object) ⇒ Void

Override to load the ClassMethods

Parameters:

  • object (Object)

Returns:

  • (Void)


9
10
11
# File 'lib/creatable.rb', line 9

def self.included(object)
  object.extend InstanceMethods
end

Instance Method Details

#attribute_namesArray

Returns the names of the attributes.

Returns:

  • (Array)

    list of names of the attributes



21
22
23
# File 'lib/creatable.rb', line 21

def attribute_names
  self.class.attributes.map { |a| a[:name] }
end

#attributesHash

Returns the hash of built attributes

Returns:

  • (Hash)

    the name, type, and kind_of built attributes.



15
16
17
# File 'lib/creatable.rb', line 15

def attributes
  self.class.attributes
end

#to_parametersHash

Returns the settings of all attributes.

Returns:

  • (Hash)

    k/v pairs of the current class attributes



27
28
29
30
31
32
33
# File 'lib/creatable.rb', line 27

def to_parameters
  h = {}
  attribute_names.each do |name|
    h.store name, instance_variable_get("@#{name}")
  end
  h
end