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
- DEFAULT_OPTIONS =
{ :public_dir => 'public', :always_update => false, :always_compress => false, :js_compression => {}, :css_compression => {}, :environment => :development, :add_default_packages => true }.freeze
- VERSION =
'0.3.0'
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_package(output_file, source_files) ⇒ Object
- .configure(options = {}) ⇒ Object
- .production? ⇒ Boolean
- .update_packages ⇒ Object
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Pack
constructor
A new instance of Pack.
Constructor Details
#initialize(app, options = {}) ⇒ Pack
Returns a new instance of Pack.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rack/pack.rb', line 62 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.
21 22 23 |
# File 'lib/rack/pack.rb', line 21 def environment @environment end |
.options ⇒ Object
Returns the value of attribute options.
21 22 23 |
# File 'lib/rack/pack.rb', line 21 def @options end |
.packages ⇒ Object
Returns the value of attribute packages.
21 22 23 |
# File 'lib/rack/pack.rb', line 21 def packages @packages end |
Class Method Details
.add_package(output_file, source_files) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/rack/pack.rb', line 45 def add_package(output_file, source_files) if source_files.nil? packages.delete(output_file) else public_output_file = ::File.join(self.[: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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rack/pack.rb', line 23 def configure( = {}) self.packages = {} self. = DEFAULT_OPTIONS.dup self..each_key do |key| self.[key] = .delete(key) if .key?(key) end unless self.[:add_default_packages] == false add_package 'javascripts/application.js', '{vendor,app,.}/javascripts/*.js' add_package 'stylesheets/application.css', '{vendor,app,.}/stylesheets/*.css' end .each do |to_file, from_files| add_package(to_file, from_files) end end |
.production? ⇒ Boolean
41 42 43 |
# File 'lib/rack/pack.rb', line 41 def production? self.environment.to_s == 'production' end |
Instance Method Details
#call(env) ⇒ Object
78 79 80 81 |
# File 'lib/rack/pack.rb', line 78 def call(env) update_packages unless skip_update? @app.call(env) end |