Class: Lina::ApplicationController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- 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
66 67 68 |
# File 'app/controllers/lina/application_controller.rb', line 66 def _actions @actions ||= {} end |
.action_block(name) ⇒ Object
62 63 64 |
# File 'app/controllers/lina/application_controller.rb', line 62 def action_block(name) _actions[name.to_sym] && _actions[name.to_sym][:block] end |
.action_methods ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/lina/application_controller.rb', line 38 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
58 59 60 |
# File 'app/controllers/lina/application_controller.rb', line 58 def action_schema(name) _actions[name.to_sym] && _actions[name.to_sym][:schema] end |
.api_action_instances ⇒ Object
返回所有实例
54 55 56 |
# File 'app/controllers/lina/application_controller.rb', line 54 def api_action_instances _actions end |
.api_actions ⇒ Object
所有支持的 API 列表
49 50 51 |
# File 'app/controllers/lina/application_controller.rb', line 49 def api_actions _actions.keys end |
.define_action(name, schema = {}, &block) ⇒ Object
33 34 35 36 |
# File 'app/controllers/lina/application_controller.rb', line 33 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, &_convert_to_lambda(&block)) default_render unless performed? Lina::Validator.return_check(schema[:return], response.body) ret else super end end |