Module: Peto::RailsControllerHelper
- Defined in:
- lib/peto/rails/rails_controller_helper.rb
Instance Method Summary collapse
- #call_procedure_response(response_type, *args) ⇒ Object
- #call_subaction(procedure, hash_args) ⇒ Object
- #contract ⇒ Object
- #error(error_name, *messages) ⇒ Object
- #hash_to_args(procedure, hash_args) ⇒ Object
-
#index ⇒ Object
subaction.
- #parse_caller(at) ⇒ Object
- #peto_class ⇒ Object
-
#procedure_name ⇒ Object
respond.
- #respond(*args) ⇒ Object
- #valid_args?(procedure, args) ⇒ Boolean
Instance Method Details
#call_procedure_response(response_type, *args) ⇒ Object
30 31 32 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 30 def call_procedure_response(response_type, *args) peto_class.send(:"#{procedure_name}_#{response_type}", *args) end |
#call_subaction(procedure, hash_args) ⇒ Object
57 58 59 60 61 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 57 def call_subaction(procedure, hash_args) args = hash_to_args(procedure, hash_args) valid_args?(procedure, *args) # raise error send(procedure, *args) end |
#contract ⇒ Object
7 8 9 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 7 def contract self.class.to_s.sub("Controller", "") end |
#error(error_name, *messages) ⇒ Object
38 39 40 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 38 def error(error_name, *) render(:json => call_procedure_response(:"error_#{error_name}", .join(","))) end |
#hash_to_args(procedure, hash_args) ⇒ Object
53 54 55 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 53 def hash_to_args(procedure, hash_args) peto_class.send(:"#{procedure}_hash_to_args", hash_args) end |
#index ⇒ Object
subaction
45 46 47 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 45 def index call_subaction(params[:procedure], params[:args]) end |
#parse_caller(at) ⇒ Object
15 16 17 18 19 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 15 def parse_caller(at) if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at {:file => $1, :line => $2.to_i, :method => $3.to_sym} end end |
#peto_class ⇒ Object
11 12 13 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 11 def peto_class "Peto::#{contract.to_s.camelize}".constantize end |
#procedure_name ⇒ Object
respond
24 25 26 27 28 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 24 def procedure_name parse_caller(caller[(0..caller.length).zip(caller).find {|index,at| parse_caller(at)[:method] == :call_subaction }.first - 1])[:method] end |
#respond(*args) ⇒ Object
34 35 36 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 34 def respond(*args) render(:json => call_procedure_response(:response, *args).to_json) end |
#valid_args?(procedure, args) ⇒ Boolean
49 50 51 |
# File 'lib/peto/rails/rails_controller_helper.rb', line 49 def valid_args?(procedure, args) peto_class.send(:"#{procedure}_valid?", args) end |