Class: Lina::ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- Lina::ApplicationController
- Defined in:
- app/controllers/lina/application_controller.rb
Class Method Summary collapse
- ._actions ⇒ Object
- .action_block(name) ⇒ Object
- .action_methods ⇒ Object
- .action_schema(name) ⇒ Object
-
.api_action_instances ⇒ Object
返回所有实例.
-
.api_actions ⇒ Object
所有支持的 API 列表.
- .define_action(name, schema = {}, &block) ⇒ Object
Instance Method Summary collapse
Class Method Details
._actions ⇒ Object
60 61 62 |
# File 'app/controllers/lina/application_controller.rb', line 60 def _actions @actions ||= {} end |
.action_block(name) ⇒ Object
56 57 58 |
# File 'app/controllers/lina/application_controller.rb', line 56 def action_block(name) _actions[name.to_sym] && _actions[name.to_sym][:block] end |
.action_methods ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/lina/application_controller.rb', line 32 def action_methods @@action_methods = begin methods = (api_actions + public_instance_methods(true) - internal_methods + public_instance_methods(false)).uniq.map { |x| x.to_s } - hidden_actions.to_a Set.new(methods.reject { |method| method =~ /_one_time_conditions/ }) end end |
.action_schema(name) ⇒ Object
52 53 54 |
# File 'app/controllers/lina/application_controller.rb', line 52 def action_schema(name) _actions[name.to_sym] && _actions[name.to_sym][:schema] end |
.api_action_instances ⇒ Object
返回所有实例
48 49 50 |
# File 'app/controllers/lina/application_controller.rb', line 48 def api_action_instances _actions end |
.api_actions ⇒ Object
所有支持的 API 列表
43 44 45 |
# File 'app/controllers/lina/application_controller.rb', line 43 def api_actions _actions.keys end |
.define_action(name, schema = {}, &block) ⇒ Object
27 28 29 30 |
# File 'app/controllers/lina/application_controller.rb', line 27 def define_action(name, schema={}, &block) Lina::Validator.api_spec_check(Lina::Schema.argument, schema) _actions[name] = { schema: schema, block: block } end |
Instance Method Details
#send_action(method_name, *args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'app/controllers/lina/application_controller.rb', line 4 def send_action(method_name, *args) block = self.class.action_block(method_name) schema = self.class.action_schema(method_name) if block Lina::Validator.params_check(schema[:params], params) ret = self.instance_exec(*args, &block) default_render unless performed? Lina::Validator.return_check(schema[:return], response.body) ret else super end end |