Class: Xing::DevAssets::RackApp
- Inherits:
-
Object
- Object
- Xing::DevAssets::RackApp
- Defined in:
- lib/xing/dev-assets/rack_app.rb
Instance Attribute Summary collapse
-
#backend_port ⇒ Object
Returns the value of attribute backend_port.
- #backend_url ⇒ Object
-
#builder ⇒ Object
Returns the value of attribute builder.
- #env ⇒ Object
- #logger ⇒ Object
- #out_stream ⇒ Object
-
#root_path ⇒ Object
Returns the value of attribute root_path.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #cookies ⇒ Object
- #disable_caching ⇒ Object
- #goto_redirect ⇒ Object
-
#log_root ⇒ Object
Should be override by client app.
- #logging ⇒ Object
- #logpath_for_env ⇒ Object
- #report_startup ⇒ Object
- #setup_middleware ⇒ Object
- #shortcut_livereload ⇒ Object
- #static_assets ⇒ Object
- #stub_application ⇒ Object
Instance Attribute Details
#backend_port ⇒ Object
Returns the value of attribute backend_port.
18 19 20 |
# File 'lib/xing/dev-assets/rack_app.rb', line 18 def backend_port @backend_port end |
#backend_url ⇒ Object
37 38 39 |
# File 'lib/xing/dev-assets/rack_app.rb', line 37 def backend_url @backend_url ||= ENV["XING_BACKEND_URL"] || ENV["LRD_BACKEND_URL"] || "http://localhost:#{backend_port}/" end |
#builder ⇒ Object
Returns the value of attribute builder.
18 19 20 |
# File 'lib/xing/dev-assets/rack_app.rb', line 18 def builder @builder end |
#env ⇒ Object
41 42 43 |
# File 'lib/xing/dev-assets/rack_app.rb', line 41 def env @env ||= ENV['RAILS_ENV'] || 'development' end |
#logger ⇒ Object
45 46 47 |
# File 'lib/xing/dev-assets/rack_app.rb', line 45 def logger @logger ||= Logger.new(logpath_for_env) end |
#out_stream ⇒ Object
33 34 35 |
# File 'lib/xing/dev-assets/rack_app.rb', line 33 def out_stream @out_stream ||= $stdout end |
#root_path ⇒ Object
Returns the value of attribute root_path.
18 19 20 |
# File 'lib/xing/dev-assets/rack_app.rb', line 18 def root_path @root_path end |
Class Method Details
.build(root_path, backend_port) {|rack_app| ... } ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/xing/dev-assets/rack_app.rb', line 10 def self.build(root_path, backend_port) rack_app = new rack_app.root_path = root_path rack_app.backend_port = backend_port yield rack_app if block_given? rack_app.build end |
Instance Method Details
#build ⇒ Object
109 110 111 112 113 114 115 116 |
# File 'lib/xing/dev-assets/rack_app.rb', line 109 def build report_startup setup_middleware stub_application builder end |
#cookies ⇒ Object
60 61 62 63 |
# File 'lib/xing/dev-assets/rack_app.rb', line 60 def builder.use CookieSetter, "lrdBackendUrl", backend_url builder.use CookieSetter, "xingBackendUrl", backend_url end |
#disable_caching ⇒ Object
65 66 67 |
# File 'lib/xing/dev-assets/rack_app.rb', line 65 def disable_caching builder.use StripIncomingCacheHeaders end |
#goto_redirect ⇒ Object
56 57 58 |
# File 'lib/xing/dev-assets/rack_app.rb', line 56 def goto_redirect builder.use GotoParam end |
#log_root ⇒ Object
Should be override by client app. Ironically, override with exactly this definition will usually work. (because this will log into a dir in the gem, but copied into subclass will be relative to that file and therefore into the project)
25 26 27 |
# File 'lib/xing/dev-assets/rack_app.rb', line 25 def log_root File.("../../log", __FILE__) end |
#logging ⇒ Object
69 70 71 |
# File 'lib/xing/dev-assets/rack_app.rb', line 69 def logging builder.use Rack::CommonLogger, logger end |
#logpath_for_env ⇒ Object
29 30 31 |
# File 'lib/xing/dev-assets/rack_app.rb', line 29 def logpath_for_env File.join( log_root, "#{env}_static.log") end |
#report_startup ⇒ Object
49 50 51 52 53 54 |
# File 'lib/xing/dev-assets/rack_app.rb', line 49 def report_startup out_stream.puts "Setting up static app:" out_stream.puts " serving files from #{root_path}" out_stream.puts " using #{backend_url} for API" out_stream.puts " logging to #{logpath_for_env}" end |
#setup_middleware ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/xing/dev-assets/rack_app.rb', line 96 def setup_middleware goto_redirect disable_caching logging shortcut_livereload static_assets end |
#shortcut_livereload ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/xing/dev-assets/rack_app.rb', line 73 def shortcut_livereload if env != "development" builder.map "/assets/livereload.js" do run EmptyFile.new end end end |
#static_assets ⇒ Object
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/xing/dev-assets/rack_app.rb', line 81 def static_assets builder.use Rack::Static, { :urls => [""], :root => root_path, :index => "index.html", :header_rules => { :all => {"Cache-Control" => "no-cache, max-age=0" } #no caching development assets } } end |
#stub_application ⇒ Object
92 93 94 |
# File 'lib/xing/dev-assets/rack_app.rb', line 92 def stub_application builder.run proc{ [500, {}, ["Something went wrong"]] } end |