Class: ApiDocGeneration::ViewHelper
- Inherits:
-
Object
- Object
- ApiDocGeneration::ViewHelper
- Defined in:
- lib/api_doc_generation/view_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#action_identifer(controller_name, action_name) ⇒ Object
Helper #######################.
- #controller_identifer(controller_name) ⇒ Object
- #format_other_param(param) ⇒ Object
- #format_param(param) ⇒ Object
- #format_response_param(param) ⇒ Object
-
#initialize(args) ⇒ ViewHelper
constructor
=> 1, :b => 2.
- #obj_binding ⇒ Object
Constructor Details
#initialize(args) ⇒ ViewHelper
=> 1, :b => 2
10 11 12 13 14 |
# File 'lib/api_doc_generation/view_helper.rb', line 10 def initialize(args) args.each do |key, val| self.instance_variable_set("@#{key}", val) end end |
Class Method Details
.render(template, args = {}) ⇒ Object
4 5 6 |
# File 'lib/api_doc_generation/view_helper.rb', line 4 def self.render(template, args = {}) template.result(self.new(args).obj_binding) end |
Instance Method Details
#action_identifer(controller_name, action_name) ⇒ Object
Helper #######################
24 25 26 |
# File 'lib/api_doc_generation/view_helper.rb', line 24 def action_identifer(controller_name, action_name) "action-#{Digest::MD5.hexdigest(controller_name)}-#{action_name}" end |
#controller_identifer(controller_name) ⇒ Object
29 30 31 |
# File 'lib/api_doc_generation/view_helper.rb', line 29 def controller_identifer(controller_name) "controller-#{Digest::MD5.hexdigest(controller_name)}" end |
#format_other_param(param) ⇒ Object
80 81 82 |
# File 'lib/api_doc_generation/view_helper.rb', line 80 def format_other_param(param) end |
#format_param(param) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/api_doc_generation/view_helper.rb', line 34 def format_param(param) return unless param[:val].to_s =~ /^\s*$/ case param[:name] when 'app_uname' param[:type] = 'String' param[:val] = 'app的唯一标识名,表明调用此api是在哪个app下' when 'access_token' param[:type] = 'String' param[:val] = '请求的唯一标识,用于识别用户,用户登陆返回或是使用refresh_token换取' when 'refresh_token' param[:type] = 'String' param[:val] = '用户登陆时返回,使用此token来取得新的access_token' when 'page' param[:type] = 'Integer' param[:val] = '返回所有数据中的第几页' when 'perpage' param[:type] = 'Integer' param[:val] = '返回数据每页多少条' end end |
#format_response_param(param) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/api_doc_generation/view_helper.rb', line 57 def format_response_param(param) return unless param[:val].to_s =~ /^\s*$/ case param[:name] when 'current_page' param[:type] = 'Integer' param[:val] = '当前返回数据是第几页' when 'perpage' param[:type] = 'Integer' param[:val] = '每页返回的数据量' when 'count' param[:type] = 'Integer' param[:val] = '数据总数量' when 'items' param[:type] = 'Array' param[:val] = '数组中存放当前页的数据' when 'total_pages' param[:type] = 'Integer' param[:val] = '数据的总页数' end end |
#obj_binding ⇒ Object
17 18 19 |
# File 'lib/api_doc_generation/view_helper.rb', line 17 def obj_binding binding end |