Class: LoadPath
Instance Attribute Summary collapse
-
#_base ⇒ Object
Returns the value of attribute _base.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#file ⇒ Object
Returns the value of attribute file.
-
#path ⇒ Object
Returns the value of attribute path.
-
#priority ⇒ Object
Returns the value of attribute priority.
Instance Method Summary collapse
- #exec_condition(statement, condition) ⇒ Object
- #exec_statement(statement, condition) ⇒ Object
- #extname ⇒ Object
- #fullpath ⇒ Object
-
#initialize(base, file:, path:, **options) ⇒ LoadPath
constructor
A new instance of LoadPath.
- #load! ⇒ Object
- #load_path! ⇒ Object
- #should_load? ⇒ Boolean
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:, ** @_base = base @file = file @path = path @priority = .fetch :priority, 1/0.0 @conditions = .slice :if, :unless end |
Instance Attribute Details
#_base ⇒ Object
Returns the value of attribute _base.
2 3 4 |
# File 'lib/r_kit/core/loader/load_path.rb', line 2 def _base @_base end |
#conditions ⇒ Object
Returns the value of attribute conditions.
2 3 4 |
# File 'lib/r_kit/core/loader/load_path.rb', line 2 def conditions @conditions end |
#file ⇒ Object
Returns the value of attribute file.
2 3 4 |
# File 'lib/r_kit/core/loader/load_path.rb', line 2 def file @file end |
#path ⇒ Object
Returns the value of attribute path.
2 3 4 |
# File 'lib/r_kit/core/loader/load_path.rb', line 2 def path @path end |
#priority ⇒ Object
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 |
#extname ⇒ Object
16 17 18 |
# File 'lib/r_kit/core/loader/load_path.rb', line 16 def extname File.extname(file) end |
#fullpath ⇒ Object
20 21 22 23 |
# File 'lib/r_kit/core/loader/load_path.rb', line 20 def fullpath file.chomp! File.extname(file) File.(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. }. } end |
#should_load? ⇒ 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 |