Class: Chanko::Loader::ClassicLoader
- Inherits:
-
Object
- Object
- Chanko::Loader::ClassicLoader
- Defined in:
- lib/chanko/loader.rb
Class Method Summary collapse
- .cache ⇒ Object
- .eager_load_units! ⇒ Object
- .load(name) ⇒ Object
- .load_from_cache(name) ⇒ Object
- .prepare_eager_load ⇒ Object
- .ruleout_unit_files_from_rails_eager_loading ⇒ Object
- .save_to_cache(name, unit) ⇒ Object
Instance Method Summary collapse
- #add_autoload_path ⇒ Object
- #autoload_path ⇒ Object
- #constantize ⇒ Object
-
#initialize(name) ⇒ ClassicLoader
constructor
A new instance of ClassicLoader.
- #load ⇒ Object
- #load_from_cache ⇒ Object
- #load_from_file_and_store_to_cache ⇒ Object
Constructor Details
#initialize(name) ⇒ ClassicLoader
Returns a new instance of ClassicLoader.
109 110 111 |
# File 'lib/chanko/loader.rb', line 109 def initialize(name) @name = name end |
Class Method Details
.cache ⇒ Object
75 76 77 |
# File 'lib/chanko/loader.rb', line 75 def self.cache @cache ||= {} end |
.eager_load_units! ⇒ Object
79 80 81 82 83 |
# File 'lib/chanko/loader.rb', line 79 def self.eager_load_units! Pathname.glob("#{Chanko::Config.units_directory_path}/*").select(&:directory?).each do |path| Chanko::Loader::ClassicLoader.load(path.basename.to_s.to_sym) end end |
.load(name) ⇒ Object
97 98 99 |
# File 'lib/chanko/loader.rb', line 97 def self.load(name) self.new(name).load end |
.load_from_cache(name) ⇒ Object
101 102 103 |
# File 'lib/chanko/loader.rb', line 101 def self.load_from_cache(name) self.cache[name] end |
.prepare_eager_load ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/chanko/loader.rb', line 85 def self.prepare_eager_load raise MissingEagarLoadSettingError if Rails.configuration.eager_load.nil? if Rails.configuration.eager_load ruleout_unit_files_from_rails_eager_loading end end |
.ruleout_unit_files_from_rails_eager_loading ⇒ Object
93 94 95 |
# File 'lib/chanko/loader.rb', line 93 def self.ruleout_unit_files_from_rails_eager_loading Rails.configuration.eager_load_paths.delete(Chanko::Config.units_directory_path) end |
.save_to_cache(name, unit) ⇒ Object
105 106 107 |
# File 'lib/chanko/loader.rb', line 105 def self.save_to_cache(name, unit) self.cache[name] = unit end |
Instance Method Details
#add_autoload_path ⇒ Object
135 136 137 138 |
# File 'lib/chanko/loader.rb', line 135 def add_autoload_path ActiveSupport::Dependencies.autoload_paths << autoload_path ActiveSupport::Dependencies.autoload_paths.uniq! end |
#autoload_path ⇒ Object
140 141 142 |
# File 'lib/chanko/loader.rb', line 140 def autoload_path "#{Config.units_directory_path }/#{@name}" end |
#constantize ⇒ Object
144 145 146 |
# File 'lib/chanko/loader.rb', line 144 def constantize @name.to_s.camelize.constantize end |
#load ⇒ Object
113 114 115 116 117 118 |
# File 'lib/chanko/loader.rb', line 113 def load load_from_cache.then do |unit| next unit unless unit.nil? load_from_file_and_store_to_cache end end |
#load_from_cache ⇒ Object
131 132 133 |
# File 'lib/chanko/loader.rb', line 131 def load_from_cache self.class.load_from_cache(@name) end |
#load_from_file_and_store_to_cache ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/chanko/loader.rb', line 120 def load_from_file_and_store_to_cache add_autoload_path constantize.tap do |unit| self.class.save_to_cache(@name, unit) end rescue Exception => exception ExceptionHandler.handle(exception) self.class.save_to_cache(@name, false) false end |