Class: RKit::Core::Loader::LoadPath

Inherits:
Object
  • Object
show all
Defined in:
lib/r_kit/core/loader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, file:, path:) ⇒ LoadPath

Returns a new instance of LoadPath.



59
60
61
62
63
64
# File 'lib/r_kit/core/loader.rb', line 59

def initialize base, file:, path:;
  @_base = base

  @file = file
  @path = path
end

Instance Attribute Details

#_baseObject

Returns the value of attribute _base.



56
57
58
# File 'lib/r_kit/core/loader.rb', line 56

def _base
  @_base
end

#conditionsObject

Returns the value of attribute conditions.



56
57
58
# File 'lib/r_kit/core/loader.rb', line 56

def conditions
  @conditions
end

#fileObject

Returns the value of attribute file.



56
57
58
# File 'lib/r_kit/core/loader.rb', line 56

def file
  @file
end

#pathObject

Returns the value of attribute path.



56
57
58
# File 'lib/r_kit/core/loader.rb', line 56

def path
  @path
end

Instance Method Details

#exec_condition(statement, condition) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# File 'lib/r_kit/core/loader.rb', line 92

def exec_condition statement, condition
  condition = case condition
  when Proc
    condition.call _base::CONFIG
  when Symbol, String
    _base::CONFIG.send condition
  end

  exec_statement statement, condition
end

#exec_statement(statement, condition) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/r_kit/core/loader.rb', line 103

def exec_statement statement, condition
  case statement
  when :if
    !!condition
  when :unless
    !condition
  end
end

#extnameObject



67
68
69
# File 'lib/r_kit/core/loader.rb', line 67

def extname
  File.extname(file)
end

#fullpathObject



71
72
73
74
# File 'lib/r_kit/core/loader.rb', line 71

def fullpath
  file.chomp! File.extname(file)
  File.expand_path(path, file)
end

#load!Object



87
88
89
# File 'lib/r_kit/core/loader.rb', line 87

def load!
  load_path! if should_load?
end

#load_path!Object



83
84
85
# File 'lib/r_kit/core/loader.rb', line 83

def load_path!
  require fullpath
end

#should_load?Boolean

Returns:

  • (Boolean)


77
78
79
80
81
# File 'lib/r_kit/core/loader.rb', line 77

def should_load?
  conditions.inject(true) do |should_load, (statement, condition)|
    should_load && exec_condition(statement, condition)
  end
end