Class: SolidQueueUi::WebAction
- Inherits:
-
Object
- Object
- SolidQueueUi::WebAction
- Defined in:
- lib/solid_queue_ui/web/action.rb
Constant Summary collapse
- RACK_SESSION =
"rack.session"
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#env ⇒ Object
Returns the value of attribute env.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #erb(content, options = {}) ⇒ Object
- #halt(res) ⇒ Object
-
#initialize(env, block) ⇒ WebAction
constructor
A new instance of WebAction.
- #json(payload) ⇒ Object
- #params ⇒ Object
- #redirect(location) ⇒ Object
- #render(engine, content, options = {}) ⇒ Object
- #request ⇒ Object
- #route_params ⇒ Object
- #session ⇒ Object
- #settings ⇒ Object
Constructor Details
#initialize(env, block) ⇒ WebAction
Returns a new instance of WebAction.
74 75 76 77 78 79 |
# File 'lib/solid_queue_ui/web/action.rb', line 74 def initialize(env, block) @_erb = false @env = env @block = block @files ||= {} end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
7 8 9 |
# File 'lib/solid_queue_ui/web/action.rb', line 7 def block @block end |
#env ⇒ Object
Returns the value of attribute env.
7 8 9 |
# File 'lib/solid_queue_ui/web/action.rb', line 7 def env @env end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/solid_queue_ui/web/action.rb', line 7 def type @type end |
Instance Method Details
#erb(content, options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/solid_queue_ui/web/action.rb', line 42 def erb(content, = {}) if content.is_a? Symbol unless respond_to?(:"_erb_#{content}") src = ERB.new(File.read("#{Web.settings.views}/#{content}.html.erb")).src WebAction.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def _erb_#{content} #{src} end RUBY end end if @_erb _erb(content, [:locals]) else @_erb = true content = _erb(content, [:locals]) _render { content } end end |
#halt(res) ⇒ Object
17 18 19 |
# File 'lib/solid_queue_ui/web/action.rb', line 17 def halt(res) throw :halt, [res, {Rack::CONTENT_TYPE => "text/plain"}, [res.to_s]] end |
#json(payload) ⇒ Object
70 71 72 |
# File 'lib/solid_queue_ui/web/action.rb', line 70 def json(payload) [200, {Rack::CONTENT_TYPE => "application/json", Rack::CACHE_CONTROL => "private, no-store"}, [SolidQueueUi.dump_json(payload)]] end |
#params ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/solid_queue_ui/web/action.rb', line 25 def params indifferent_hash = Hash.new { |hash, key| hash[key.to_s] if Symbol === key } indifferent_hash.merge! request.params route_params.each { |k, v| indifferent_hash[k.to_s] = v } indifferent_hash end |
#redirect(location) ⇒ Object
21 22 23 |
# File 'lib/solid_queue_ui/web/action.rb', line 21 def redirect(location) throw :halt, [302, {Web::LOCATION => "#{request.base_url}#{location}"}, []] end |
#render(engine, content, options = {}) ⇒ Object
64 65 66 67 68 |
# File 'lib/solid_queue_ui/web/action.rb', line 64 def render(engine, content, = {}) raise "Only erb templates are supported" if engine != :erb erb(content, ) end |
#request ⇒ Object
13 14 15 |
# File 'lib/solid_queue_ui/web/action.rb', line 13 def request @request ||= ::Rack::Request.new(env) end |
#route_params ⇒ Object
34 35 36 |
# File 'lib/solid_queue_ui/web/action.rb', line 34 def route_params env[WebRouter::ROUTE_PARAMS] end |
#session ⇒ Object
38 39 40 |
# File 'lib/solid_queue_ui/web/action.rb', line 38 def session env[RACK_SESSION] end |