Class: Kamaze::Project::Helper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/kamaze/project/helper.rb

Overview

Provides access to helper classes

Defined Under Namespace

Classes: Inflector, Project

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHelper (protected)

Returns a new instance of Helper.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kamaze/project/helper.rb', line 42

def initialize
  @items = {
    inflector: proc do
      require "#{self.class.ns}/inflector"

      Inflector.new
    end.call
  }

  super
end

Class Attribute Details

.nsObject (readonly)

Returns the value of attribute ns.



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

def ns
  @ns
end

Instance Attribute Details

#itemsObject (readonly, protected)

Returns the value of attribute items.



40
41
42
# File 'lib/kamaze/project/helper.rb', line 40

def items
  @items
end

Instance Method Details

#get(name) ⇒ Object

Parameters:

  • name (String|Symbol)

Returns:

Raises:

  • (NotImplementedError)


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kamaze/project/helper.rb', line 26

def get(name)
  name = name.to_sym

  return items[name] if items[name]

  begin
    @items[name] = inflector.resolve("#{self.class.ns}/#{name}").new
  rescue LoadError
    raise NotImplementedError, "helper not loadable: #{name}"
  end
end

#inflectorSys::Proc::Helper::Inflector (protected)

Returns:

  • (Sys::Proc::Helper::Inflector)


60
61
62
# File 'lib/kamaze/project/helper.rb', line 60

def inflector
  to_h.fetch(:inflector)
end

#to_hHash (protected)

Returns:

  • (Hash)


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

def to_h
  items
end