Class: RPCoder::Function
- Inherits:
-
Object
- Object
- RPCoder::Function
- Defined in:
- lib/rpcoder/function.rb
Constant Summary collapse
- PARAMS_IN_URL_RE =
/:[\w\d]+/
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#method ⇒ Object
Returns the value of attribute method.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#return_type ⇒ Object
Returns the value of attribute return_type.
Instance Method Summary collapse
- #add_param(name, type, options = {}) ⇒ Object
- #add_return_type(name, type, options = {}) ⇒ Object
- #has_return_type? ⇒ Boolean
- #params ⇒ Object
- #path_parts ⇒ Object
- #query_params ⇒ Object
- #return_types ⇒ Object
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/rpcoder/function.rb', line 6 def description @description end |
#method ⇒ Object
Returns the value of attribute method.
6 7 8 |
# File 'lib/rpcoder/function.rb', line 6 def method @method end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/rpcoder/function.rb', line 6 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/rpcoder/function.rb', line 6 def path @path end |
#return_type ⇒ Object
Returns the value of attribute return_type.
6 7 8 |
# File 'lib/rpcoder/function.rb', line 6 def return_type @return_type end |
Instance Method Details
#add_param(name, type, options = {}) ⇒ Object
20 21 22 |
# File 'lib/rpcoder/function.rb', line 20 def add_param(name, type, = {}) params << Param.new(name, type, ) end |
#add_return_type(name, type, options = {}) ⇒ Object
42 43 44 |
# File 'lib/rpcoder/function.rb', line 42 def add_return_type(name, type, = {}) return_types << Param.new(name, type, ) end |
#has_return_type? ⇒ Boolean
16 17 18 |
# File 'lib/rpcoder/function.rb', line 16 def has_return_type? !return_types.empty? end |
#params ⇒ Object
8 9 10 |
# File 'lib/rpcoder/function.rb', line 8 def params @params ||= [] end |
#path_parts ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rpcoder/function.rb', line 24 def path_parts raise "path must starts with `/`: #{path}" unless path =~ /^\// path_strs = path.split(PARAMS_IN_URL_RE) params = path.scan(PARAMS_IN_URL_RE) parts = [] ([path_strs.size, params.size].max).times do |variable| parts << %Q{"#{path_strs.shift}"} parts << params.shift.sub(/^:/, '') rescue nil end parts end |
#query_params ⇒ Object
37 38 39 40 |
# File 'lib/rpcoder/function.rb', line 37 def query_params param_strs = path.scan(PARAMS_IN_URL_RE).map { |i| i.sub(/^:/, '') } params.select { |i| !param_strs.include?(i.name.to_s) } end |
#return_types ⇒ Object
12 13 14 |
# File 'lib/rpcoder/function.rb', line 12 def return_types @return_types ||= [] end |