Class: Kamaze::Project::Config Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/kamaze/project/config.rb

Overview

This class is abstract.

Subclass and override #defaults to implement

Generic config(urator) class

Direct Known Subclasses

Helper::Project::Config

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



19
20
21
# File 'lib/kamaze/project/config.rb', line 19

def initialize
  @attributes = Kamaze::Project::Struct.new(defaults)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/kamaze/project/config.rb', line 40

def method_missing(method, *args, &block)
  if respond_to_missing?(method)
    @attributes.public_send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#attributesKamaze::Project::Struct (readonly)



17
18
19
# File 'lib/kamaze/project/config.rb', line 17

def attributes
  @attributes
end

Instance Method Details

#configure(configurable) ⇒ Object

Configure an object (manipulating its properties)

Parameters:

Returns:



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

def configure(configurable)
  to_h.each do |k, v|
    configurable.__send__("#{k}=", v)
  end

  configurable
end

#defaultsHash

Returns:

  • (Hash)


55
56
57
# File 'lib/kamaze/project/config.rb', line 55

def defaults
  {}
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/kamaze/project/config.rb', line 48

def respond_to_missing?(method, include_private = false)
  return true if attributes.respond_to?(method, include_private)

  super(method, include_private)
end

#to_hHash

Returns:

  • (Hash)


36
37
38
# File 'lib/kamaze/project/config.rb', line 36

def to_h
  attributes.to_h
end