Module: Jaso::Attributable

Defined in:
lib/jaso/attributable.rb

Defined Under Namespace

Modules: ClassMethods, PrependMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
# File 'lib/jaso/attributable.rb', line 4

def self.included(base)
  base.extend(ClassMethods)
  base.prepend(PrependMethods)
end

Instance Method Details

#__assign_attributesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jaso/attributable.rb', line 31

def __assign_attributes
  self.class.__attributes.each do |name, options|
    input = @__inputs[name]
    default = options[:default]
    transform = options[:transform]

    __attributes[name] = if @__inputs.key?(name)
      transform.is_a?(Proc) ? transform.call(input) : input
    else
      default.is_a?(Proc) ? default.call : default
    end
  end
end

#__attributesObject



27
28
29
# File 'lib/jaso/attributable.rb', line 27

def __attributes
  @__attributes ||= {}
end