Class: Grouik::Loader
- Inherits:
-
Object
- Object
- Grouik::Loader
- 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
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
- #basedir ⇒ Pathname
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#ignores ⇒ Object
Returns the value of attribute ignores.
- #paths ⇒ Array<Pathname>
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
Instance Method Summary collapse
- #attempts_maxcount ⇒ Fixnum
-
#format(options = {}) ⇒ String
Format using a formatter.
-
#initialize {|_self| ... } ⇒ Loader
constructor
A new instance of Loader.
- #load_all ⇒ self
-
#loadables ⇒ Array<Grouik::Loadable>
Get loadables.
- #loaded? ⇒ Boolean
-
#register ⇒ self
Register paths.
Methods included from Concerns::Helpable
Constructor Details
#initialize {|_self| ... } ⇒ Loader
Returns a new instance of Loader.
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
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
23 24 25 |
# File 'src/lib/grouik/loader.rb', line 23 def attempts @attempts end |
#basedir ⇒ Pathname
85 86 87 |
# File 'src/lib/grouik/loader.rb', line 85 def basedir @basedir end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
24 25 26 |
# File 'src/lib/grouik/loader.rb', line 24 def errors @errors end |
#ignores ⇒ Object
Returns the value of attribute ignores.
20 21 22 |
# File 'src/lib/grouik/loader.rb', line 20 def ignores @ignores end |
#paths ⇒ Array<Pathname>
56 57 58 |
# File 'src/lib/grouik/loader.rb', line 56 def paths @paths end |
#stats ⇒ Object (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_maxcount ⇒ 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
113 114 115 |
# File 'src/lib/grouik/loader.rb', line 113 def format( = {}) Grouik.get(:formatter).format(load_all.loadables, ).to_s end |
#load_all ⇒ 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 |
#loadables ⇒ Array<Grouik::Loadable>
Get loadables
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
117 118 119 |
# File 'src/lib/grouik/loader.rb', line 117 def loaded? self.loadables.size == @loadeds.size end |
#register ⇒ self
Register paths
63 64 65 66 67 |
# File 'src/lib/grouik/loader.rb', line 63 def register helpers.get(:loader).register_paths(basedir, @paths) self end |