Class: Grouik::Loader

Inherits:
Object
  • Object
show all
Includes:
Concerns::Helpable
Defined in:
src/lib/grouik/loader.rb

Overview

Main class loader

loads files during Grouik::Loader#load_all

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Helpable

#helpers

Constructor Details

#initialize {|_self| ... } ⇒ Loader

Returns a new instance of Loader.

Yields:

  • (_self)

Yield Parameters:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'src/lib/grouik/loader.rb', line 29

def initialize
  self.basedir = '.'
  self.ignores = []

  @loadeds   = []
  @errors    = {}
  @loadables = []
  @attempts  = 0
  @stats     = nil

  return self unless block_given?

  yield self
  register
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



23
24
25
# File 'src/lib/grouik/loader.rb', line 23

def attempts
  @attempts
end

#basedirPathname

Returns:

  • (Pathname)


85
86
87
# File 'src/lib/grouik/loader.rb', line 85

def basedir
  @basedir
end

#errorsObject (readonly)

Returns the value of attribute errors.



24
25
26
# File 'src/lib/grouik/loader.rb', line 24

def errors
  @errors
end

#ignoresObject

Returns the value of attribute ignores.



20
21
22
# File 'src/lib/grouik/loader.rb', line 20

def ignores
  @ignores
end

#pathsArray<Pathname>

Returns:

  • (Array<Pathname>)


56
57
58
# File 'src/lib/grouik/loader.rb', line 56

def paths
  @paths
end

#statsObject (readonly)

Returns the value of attribute stats.



25
26
27
# File 'src/lib/grouik/loader.rb', line 25

def stats
  @stats
end

Instance Method Details

#attempts_maxcountFixnum

Returns:

  • (Fixnum)


122
123
124
# File 'src/lib/grouik/loader.rb', line 122

def attempts_maxcount
  (self.loadables.size**2) + 1
end

#format(options = {}) ⇒ String

Format using a formatter

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (String)


113
114
115
# File 'src/lib/grouik/loader.rb', line 113

def format(options = {})
  Grouik.get(:formatter).format(load_all.loadables, options).to_s
end

#load_allself

Returns:

  • (self)


92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'src/lib/grouik/loader.rb', line 92

def load_all
  return @loadeds.clone unless @loadeds.empty?

  loadables = self.loadables
  @loadeds  = []
  @errors   = {}

  @stats = Benchmark.measure do
    loop do
      loadables = process_loadables(loadables)
      break if loadables.nil? or (loadables and loadables.empty?)
    end
  end
  @loadeds.compact
  self
end

#loadablesArray<Grouik::Loadable>

Get loadables

Returns:



72
73
74
75
76
77
78
79
80
81
82
# File 'src/lib/grouik/loader.rb', line 72

def loadables
  if @loadables.empty?
    self.basedir do
      @loadables = helpers.get(:loader)
                          .collect_loadables(paths)
                          .ignores(ignores)
    end
  end

  @loadables.clone
end

#loaded?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'src/lib/grouik/loader.rb', line 117

def loaded?
  self.loadables.size == @loadeds.size
end

#registerself

Register paths

Returns:

  • (self)


63
64
65
66
67
# File 'src/lib/grouik/loader.rb', line 63

def register
  helpers.get(:loader).register_paths(basedir, @paths)

  self
end