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.



50
51
52
53
54
55
# File 'lib/r_kit/core/loader.rb', line 50

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

  @file = file
  @path = path
end

Instance Attribute Details

#_baseObject

Returns the value of attribute _base.



47
48
49
# File 'lib/r_kit/core/loader.rb', line 47

def _base
  @_base
end

#conditionsObject

Returns the value of attribute conditions.



47
48
49
# File 'lib/r_kit/core/loader.rb', line 47

def conditions
  @conditions
end

#fileObject

Returns the value of attribute file.



47
48
49
# File 'lib/r_kit/core/loader.rb', line 47

def file
  @file
end

#pathObject

Returns the value of attribute path.



47
48
49
# File 'lib/r_kit/core/loader.rb', line 47

def path
  @path
end

Instance Method Details

#exec_condition(statement, condition) ⇒ Object



83
84
85
86
87
88
89
90
91
92
# File 'lib/r_kit/core/loader.rb', line 83

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



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

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

#extnameObject



58
59
60
# File 'lib/r_kit/core/loader.rb', line 58

def extname
  File.extname(file)
end

#fullpathObject



62
63
64
65
# File 'lib/r_kit/core/loader.rb', line 62

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

#load!Object



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

def load!
  load_path! if should_load?
end

#load_path!Object



74
75
76
# File 'lib/r_kit/core/loader.rb', line 74

def load_path!
  require fullpath
end

#should_load?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
# File 'lib/r_kit/core/loader.rb', line 68

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