Class: RPCoder::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/rpcoder/function.rb

Constant Summary collapse

PARAMS_IN_URL_RE =
/:[\w\d]+/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/rpcoder/function.rb', line 6

def description
  @description
end

#methodObject

Returns the value of attribute method.



6
7
8
# File 'lib/rpcoder/function.rb', line 6

def method
  @method
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/rpcoder/function.rb', line 6

def name
  @name
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/rpcoder/function.rb', line 6

def path
  @path
end

#return_typeObject

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, options = {})
  params << Param.new(name, type, options)
end

#add_return_type(name, type, options = {}) ⇒ Object



42
43
44
# File 'lib/rpcoder/function.rb', line 42

def add_return_type(name, type, options = {})
  return_types << Param.new(name, type, options)
end

#has_return_type?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rpcoder/function.rb', line 16

def has_return_type?
  !return_types.empty?
end

#paramsObject



8
9
10
# File 'lib/rpcoder/function.rb', line 8

def params
  @params ||= []
end

#path_partsObject



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_paramsObject



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_typesObject



12
13
14
# File 'lib/rpcoder/function.rb', line 12

def return_types
  @return_types ||= []
end