Class: LoadPath

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of LoadPath.



5
6
7
8
9
10
11
12
13
# File 'lib/r_kit/core/loader/load_path.rb', line 5

def initialize base, file:, path:, **options
  @_base = base

  @file = file
  @path = path

  @priority = options.fetch :priority, 1/0.0
  @conditions = options.slice :if, :unless
end

Instance Attribute Details

#_baseObject

Returns the value of attribute _base.



2
3
4
# File 'lib/r_kit/core/loader/load_path.rb', line 2

def _base
  @_base
end

#conditionsObject

Returns the value of attribute conditions.



2
3
4
# File 'lib/r_kit/core/loader/load_path.rb', line 2

def conditions
  @conditions
end

#fileObject

Returns the value of attribute file.



2
3
4
# File 'lib/r_kit/core/loader/load_path.rb', line 2

def file
  @file
end

#pathObject

Returns the value of attribute path.



2
3
4
# File 'lib/r_kit/core/loader/load_path.rb', line 2

def path
  @path
end

#priorityObject

Returns the value of attribute priority.



2
3
4
# File 'lib/r_kit/core/loader/load_path.rb', line 2

def priority
  @priority
end

Instance Method Details

#exec_condition(statement, condition) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/r_kit/core/loader/load_path.rb', line 47

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



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

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

#extnameObject



16
17
18
# File 'lib/r_kit/core/loader/load_path.rb', line 16

def extname
  File.extname(file)
end

#fullpathObject



20
21
22
23
# File 'lib/r_kit/core/loader/load_path.rb', line 20

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

#load!Object



42
43
44
# File 'lib/r_kit/core/loader/load_path.rb', line 42

def load!
  load_path! if should_load?
end

#load_path!Object



32
33
34
35
36
37
38
39
40
# File 'lib/r_kit/core/loader/load_path.rb', line 32

def load_path!
  require fullpath
rescue NameError => e
  warn %Q{
WARNING - An error occur during `RKit' initialization
The file #{ fullpath } could not be loaded.
Ruby stack says: #{ e.message }.
  }
end

#should_load?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/r_kit/core/loader/load_path.rb', line 26

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