Class: Rack::Pack
- Inherits:
-
Object
- Object
- Rack::Pack
- Defined in:
- lib/rack/pack.rb,
lib/rack/pack/package.rb,
lib/rack/pack/version.rb,
lib/rack/pack/javascript.rb,
lib/rack/pack/stylesheet.rb
Defined Under Namespace
Classes: Javascript, Package, Stylesheet
Constant Summary collapse
- VERSION =
'0.3.2'
Class Attribute Summary collapse
-
.environment ⇒ Object
Returns the value of attribute environment.
-
.options ⇒ Object
Returns the value of attribute options.
-
.packages ⇒ Object
Returns the value of attribute packages.
Class Method Summary collapse
-
.add_default_packages ⇒ Object
Adds the default Packages, which essentially look in the ‘vendor`, `app`, and current directories for javascripts & stylesheets and packages them into `javascripts/application.js` & `stylesheets/application.css`.
-
.add_package(output_file, source_files) ⇒ Object
Adds a new Package for Rack::Pack to update.
-
.configure(options = {}) ⇒ Object
Sets up Rack::Pack, optionally adding packages.
-
.production? ⇒ Boolean
Determines if we’re running in a production environment.
-
.update_packages ⇒ Object
Loops through each added Package and updates them when stale.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Pack
constructor
Interface for creating the Rack::Pack middleware.
Constructor Details
#initialize(app, options = {}) ⇒ Pack
Interface for creating the Rack::Pack middleware.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rack/pack.rb', line 93 def initialize(app, = {}) @app = app Pack.configure() # Set environment based on Application environment if defined?(RAILS_ENV) Pack.environment = RAILS_ENV # Rails 2 elsif defined?(Rails) && defined?(Rails.env) Pack.environment = Rails.env # Rails 3 elsif defined?(app.settings) && defined?(app.settings.environment) Pack.environment = app.settings.environment # Sinatra elsif ENV.key?('RACK_ENV') Pack.environment = ENV['RACK_ENV'] end end |
Class Attribute Details
.environment ⇒ Object
Returns the value of attribute environment.
11 12 13 |
# File 'lib/rack/pack.rb', line 11 def environment @environment end |
.options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/rack/pack.rb', line 11 def @options end |
.packages ⇒ Object
Returns the value of attribute packages.
11 12 13 |
# File 'lib/rack/pack.rb', line 11 def packages @packages end |
Class Method Details
.add_default_packages ⇒ Object
Adds the default Packages, which essentially look in the ‘vendor`, `app`, and current directories for javascripts & stylesheets and packages them into `javascripts/application.js` & `stylesheets/application.css`
77 78 79 80 |
# File 'lib/rack/pack.rb', line 77 def add_default_packages add_package 'javascripts/application.js', '{vendor,app,.}/javascripts/*.js' add_package 'stylesheets/application.css', '{vendor,app,.}/stylesheets/*.css' end |
.add_package(output_file, source_files) ⇒ Object
Adds a new Package for Rack::Pack to update. The Package class is determined based on the filename.
64 65 66 67 68 69 70 71 72 |
# File 'lib/rack/pack.rb', line 64 def add_package(output_file, source_files) if source_files.nil? packages.delete(output_file) else public_output_file = ::File.join([:public_dir], output_file.to_s) package_class = Package[output_file] packages[output_file] = package_class.new(public_output_file, source_files) end end |
.configure(options = {}) ⇒ Object
Sets up Rack::Pack, optionally adding packages.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rack/pack.rb', line 39 def configure( = {}) self..each_key do |key| self.[key] = .delete(key) if .key?(key) end self.environment = .delete(:environment) if .key?(:environment) add_default_packages if self.[:add_default_packages] .each do |to_file, from_files| add_package(to_file, from_files) end end |
.production? ⇒ Boolean
Determines if we’re running in a production environment.
54 55 56 |
# File 'lib/rack/pack.rb', line 54 def production? self.environment.to_s == 'production' end |
Instance Method Details
#call(env) ⇒ Object
109 110 111 112 |
# File 'lib/rack/pack.rb', line 109 def call(env) update_packages unless skip_update? @app.call(env) end |