Class: RPCoder::Param

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

Direct Known Subclasses

Type::Field

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, options = {}) ⇒ Param

Returns a new instance of Param.



8
9
10
11
12
# File 'lib/rpcoder/param.rb', line 8

def initialize(name, type, options = {})
  @name = name
  @type = type
  @options = options
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/rpcoder/param.rb', line 7

def name
  @name
end

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/rpcoder/param.rb', line 7

def options
  @options
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/rpcoder/param.rb', line 7

def type
  @type
end

Class Method Details

.original_typesObject



3
4
5
# File 'lib/rpcoder/param.rb', line 3

def self.original_types
  [:int, :String, :Boolean, :Array]
end

Instance Method Details

#array?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/rpcoder/param.rb', line 14

def array?
  options[:array?]
end

#array_or_typeObject



18
19
20
21
22
23
24
# File 'lib/rpcoder/param.rb', line 18

def array_or_type
  if array?
    "Array"
  else
    type
  end
end

#array_paramObject



30
31
32
# File 'lib/rpcoder/param.rb', line 30

def array_param
  Param.new(name, options[:array_type])
end

#element_accessor(elem = 'elem', options = {}) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rpcoder/param.rb', line 43

def element_accessor(elem = 'elem', options = {})
  if options[:object?]
    "object['#{elem}']"
  else
    elem
  end
end

#instance_creator(elem = 'elem', options = {}) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/rpcoder/param.rb', line 34

def instance_creator(elem = 'elem', options = {})
  elem = element_accessor(elem, options)
  if original_type?
    elem
  else
    "new #{type}(#{elem})"
  end
end

#original_type?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rpcoder/param.rb', line 26

def original_type?
  Param.original_types.include?(type.to_sym)
end