Module: CasualAPI::Action
- Defined in:
- lib/action.rb
Class Method Summary collapse
Instance Method Summary collapse
- #content_type ⇒ Object
- #content_type=(type) ⇒ Object
- #file?(file) ⇒ Boolean
- #invalid_parameter(*params) ⇒ Object
- #redirect ⇒ Object
- #redirect_to(url) ⇒ Object
- #session ⇒ Object
- #session=(value) ⇒ Object
- #session_clear ⇒ Object
- #status_code ⇒ Object
- #status_code=(code) ⇒ Object
- #tempfile(file) ⇒ Object
- #tempfiles ⇒ Object
Class Method Details
.extended(obj) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/action.rb', line 3 def self.extended obj obj.instance_variable_set(:@redirect, nil) obj.instance_variable_set(:@session, {}) obj.instance_variable_set(:@content_type, nil) obj.instance_variable_set(:@status_code, 200) obj.instance_variable_set(:@tempfiles, []) end |
.fire(action, params, session) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/action.rb', line 43 def self.fire(action, params, session) obj = Object obj.extend Action obj.extend BodyWriter obj.content_type = action[:content_type] || :txt obj.session = session ps = action[:action].parameters.map{|_, name| {name => params[name]} }.inject({}, :merge) execute(obj, ps, action) obj.tempfiles.each{|f| f.close } obj end |
.is_file?(param) ⇒ Boolean
57 58 59 |
# File 'lib/action.rb', line 57 def self.is_file? param param.is_a?(Hash) && param[:tempfile] && param[:tempfile].is_a?(Tempfile) end |
Instance Method Details
#content_type ⇒ Object
35 |
# File 'lib/action.rb', line 35 def content_type; @content_type; end |
#content_type=(type) ⇒ Object
38 |
# File 'lib/action.rb', line 38 def content_type=(type); @content_type = type; end |
#file?(file) ⇒ Boolean
16 17 18 |
# File 'lib/action.rb', line 16 def file? file Action.is_file? file end |
#invalid_parameter(*params) ⇒ Object
11 12 13 14 |
# File 'lib/action.rb', line 11 def invalid_parameter *params raise InvalidParameterError, "Invalid parameter(s): #{params.map{|p|p.to_s}.join(',')}" end |
#redirect ⇒ Object
40 |
# File 'lib/action.rb', line 40 def redirect; @redirect; end |
#redirect_to(url) ⇒ Object
24 25 26 |
# File 'lib/action.rb', line 24 def redirect_to url @redirect = url end |
#session ⇒ Object
33 |
# File 'lib/action.rb', line 33 def session; @session; end |
#session=(value) ⇒ Object
34 |
# File 'lib/action.rb', line 34 def session=(value); @session = value; end |
#session_clear ⇒ Object
28 29 30 31 |
# File 'lib/action.rb', line 28 def session_clear session.clear @session = nil end |
#status_code ⇒ Object
37 |
# File 'lib/action.rb', line 37 def status_code; @status_code; end |
#status_code=(code) ⇒ Object
39 |
# File 'lib/action.rb', line 39 def status_code=(code); @status_code = code; end |
#tempfile(file) ⇒ Object
20 21 22 |
# File 'lib/action.rb', line 20 def tempfile file Action.tempfile self, file end |
#tempfiles ⇒ Object
36 |
# File 'lib/action.rb', line 36 def tempfiles; @tempfiles; end |