Module: Aerogel
- Defined in:
- lib/aerogel/core/reloader.rb,
lib/aerogel/core/core.rb,
lib/aerogel/core/config.rb,
lib/aerogel/core/errors.rb,
lib/aerogel/core/version.rb
Overview
Middleware which checks and reloads modified files.
Defined Under Namespace
Modules: Assets, Config, Db, Errors, Helpers, Render, Routes Classes: Application, Reloader
Constant Summary collapse
- VERSION =
'1.3.0'
Class Attribute Summary collapse
-
.application_path ⇒ Object
Returns the value of attribute application_path.
-
.core_path ⇒ Object
Returns the value of attribute core_path.
Class Method Summary collapse
-
.config ⇒ Object
Returns Aerogel application’s config object.
-
.get_resource(type, filename, environment = nil) ⇒ Object
Returns filename of the most recent resource file of specified type.
-
.get_resource_list(type, wildcard, environment = nil) ⇒ Object
Returns list of filenames of resources of specified type, environment sub-folders included, filtered by wildcard mask.
-
.get_resource_paths(type) ⇒ Object
Returns list of paths for specified resource type.
-
.on_load(&block) ⇒ Object
Registers on-load callback.
-
.on_load_callbacks ⇒ Object
Returns registered on-load callbacks.
-
.register_path(path, type = nil) ⇒ Object
Registers a new path for all resource loaders.
-
.registered_paths(type = nil) ⇒ Object
Returns registered paths.
-
.require_into(mod_class, filename) ⇒ Object
Requires file, loads into context of a module/class.
-
.require_resources(type, wildcard, environment = nil) ⇒ Object
Require resources specified by type and wildcard.
-
.require_resources_reverse(type, wildcard, environment = nil) ⇒ Object
Require resources specified by type and wildcard in reverse order.
-
.version ⇒ Object
Returns module version.
Class Attribute Details
.application_path ⇒ Object
Returns the value of attribute application_path.
4 5 6 |
# File 'lib/aerogel/core/core.rb', line 4 def application_path @application_path end |
.core_path ⇒ Object
Returns the value of attribute core_path.
4 5 6 |
# File 'lib/aerogel/core/core.rb', line 4 def core_path @core_path end |
Class Method Details
.config ⇒ Object
Returns Aerogel application’s config object.
9 10 11 |
# File 'lib/aerogel/core/config.rb', line 9 def self.config @config ||= Configurator.new end |
.get_resource(type, filename, environment = nil) ⇒ Object
Returns filename of the most recent resource file of specified type.
64 65 66 |
# File 'lib/aerogel/core/core.rb', line 64 def self.get_resource( type, filename, environment = nil ) get_resource_list( type, filename, environment ).last end |
.get_resource_list(type, wildcard, environment = nil) ⇒ Object
Returns list of filenames of resources of specified type, environment sub-folders included, filtered by wildcard mask.
The resources are searched in following order:
path1 + wildcard
path1 + environment + wildcard
path2 + wildcard
path2 + environment + wildcard
etc
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/aerogel/core/core.rb', line 51 def self.get_resource_list( type, wildcard, environment = nil ) get_resource_paths( type ).map do |path| paths = Dir.glob( File.join( path, wildcard ) ) if environment paths << Dir.glob( File.join( path, environment.to_s, wildcard ) ) end # puts "Aerogel::get_resource_list: type=#{type} environment=#{environment} path=#{path}: #{paths}" paths end.flatten end |
.get_resource_paths(type) ⇒ Object
Returns list of paths for specified resource type.
35 36 37 38 39 |
# File 'lib/aerogel/core/core.rb', line 35 def self.get_resource_paths( type ) registered_paths( type ).map do |p| p[:type].nil? ? File.join( p[:path], type.to_s ) : p[:path] end end |
.on_load(&block) ⇒ Object
Registers on-load callback.
110 111 112 113 |
# File 'lib/aerogel/core/core.rb', line 110 def self.on_load( &block ) @on_load_callbacks ||= [] @on_load_callbacks << block end |
.on_load_callbacks ⇒ Object
Returns registered on-load callbacks.
104 105 106 |
# File 'lib/aerogel/core/core.rb', line 104 def self.on_load_callbacks @on_load_callbacks || [] end |
.register_path(path, type = nil) ⇒ Object
Registers a new path for all resource loaders.
If type is not specified, then resource paths are formed by appending type to the given path.
If type is specified, given path is cosidered a final path for this resource type, and for this resource type only.
21 22 23 24 |
# File 'lib/aerogel/core/core.rb', line 21 def self.register_path( path, type = nil ) @registered_paths ||= [] @registered_paths << { path: File.( path ), type: type } end |
.registered_paths(type = nil) ⇒ Object
Returns registered paths. If type is specified, only resource paths containing this type are returned.
29 30 31 |
# File 'lib/aerogel/core/core.rb', line 29 def self.registered_paths( type = nil ) @registered_paths.select{|p| type.nil? || p[:type].nil? || p[:type] == type } end |
.require_into(mod_class, filename) ⇒ Object
Requires file, loads into context of a module/class.
98 99 100 |
# File 'lib/aerogel/core/core.rb', line 98 def self.require_into( mod_class, filename ) mod_class.class_eval File.read(filename), filename end |
.require_resources(type, wildcard, environment = nil) ⇒ Object
Require resources specified by type and wildcard.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/aerogel/core/core.rb', line 70 def self.require_resources( type, wildcard, environment = nil ) files_to_require = Aerogel.get_resource_list( type, wildcard, environment ) files_to_require.each do |filename| # begin require filename # rescue => e # raise e # "Failed to load resource '#{filename}': #{e}" # end end true end |
.require_resources_reverse(type, wildcard, environment = nil) ⇒ Object
Require resources specified by type and wildcard in reverse order.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/aerogel/core/core.rb', line 84 def self.require_resources_reverse( type, wildcard, environment = nil ) files_to_require = Aerogel.get_resource_list( type, wildcard, environment ).reverse files_to_require.each do |filename| # begin require filename # rescue => e # raise e # "Failed to load resource '#{filename}': #{e}" # end end true end |
.version ⇒ Object
Returns module version.
9 10 11 |
# File 'lib/aerogel/core/core.rb', line 9 def self.version Aerogel::VERSION end |