Class: Chanko::Loader
- Inherits:
-
Object
- Object
- Chanko::Loader
- Defined in:
- lib/chanko/loader.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_autoload_path ⇒ Object
- #autoload_path ⇒ Object
- #cache ⇒ Object
- #constantize ⇒ Object
- #directory_path ⇒ Object
-
#initialize(name) ⇒ Loader
constructor
A new instance of Loader.
- #load ⇒ Object
- #load_from_cache ⇒ Object
- #load_from_file ⇒ Object
- #loaded? ⇒ Boolean
Constructor Details
#initialize(name) ⇒ Loader
Returns a new instance of Loader.
15 16 17 |
# File 'lib/chanko/loader.rb', line 15 def initialize(name) @name = name end |
Class Method Details
.cache ⇒ Object
10 11 12 |
# File 'lib/chanko/loader.rb', line 10 def cache @cache ||= {} end |
.load(unit_name) ⇒ Object
6 7 8 |
# File 'lib/chanko/loader.rb', line 6 def load(unit_name) new(unit_name).load end |
Instance Method Details
#add_autoload_path ⇒ Object
44 45 46 47 |
# File 'lib/chanko/loader.rb', line 44 def add_autoload_path ActiveSupport::Dependencies.autoload_paths << autoload_path ActiveSupport::Dependencies.autoload_paths.uniq! end |
#autoload_path ⇒ Object
49 50 51 |
# File 'lib/chanko/loader.rb', line 49 def autoload_path Rails.root.join("#{directory_path}/#@name").to_s end |
#cache ⇒ Object
61 62 63 |
# File 'lib/chanko/loader.rb', line 61 def cache self.class.cache end |
#constantize ⇒ Object
57 58 59 |
# File 'lib/chanko/loader.rb', line 57 def constantize @name.to_s.camelize.constantize end |
#directory_path ⇒ Object
53 54 55 |
# File 'lib/chanko/loader.rb', line 53 def directory_path Config.units_directory_path end |
#load ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/chanko/loader.rb', line 19 def load if loaded? load_from_cache else load_from_file end end |
#load_from_cache ⇒ Object
31 32 33 |
# File 'lib/chanko/loader.rb', line 31 def load_from_cache cache[@name] end |
#load_from_file ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/chanko/loader.rb', line 35 def load_from_file add_autoload_path cache[@name] = constantize rescue Exception => exception ExceptionHandler.handle(exception) cache[@name] = false nil end |
#loaded? ⇒ Boolean
27 28 29 |
# File 'lib/chanko/loader.rb', line 27 def loaded? cache[@name] != nil end |