Class: Raml::Parameter::AbstractParameter
- Inherits:
-
Raml::PropertiesNode
- Object
- Node
- Raml::PropertiesNode
- Raml::Parameter::AbstractParameter
- Includes:
- Documentable, Merge, Raml::Parent
- Defined in:
- lib/raml/node/parameter/abstract_parameter.rb
Direct Known Subclasses
Header, BaseUriParameter, FormParameter, QueryParameter, UriParameter
Constant Summary collapse
- VALID_TYPES =
%w(string number integer date boolean file)
Instance Attribute Summary collapse
-
#default ⇒ String, ...
The default value.
-
#enum ⇒ Array<String>?
The possible values.
-
#example ⇒ String, ...
An example of the value.
-
#max_length ⇒ Integer?
The maximum value length.
-
#maximum ⇒ Numeric?
The maximum value length.
-
#min_length ⇒ Integer?
The minimum value length.
-
#minimum ⇒ Numeric?
The minimum value length.
-
#pattern ⇒ Regexp?
A regular expression the value must match.
-
#repeat ⇒ Boolean
Whether the parameter can be repeated.
-
#required ⇒ Boolean
Whether the parameter is required.
-
#type ⇒ String
The value type.
-
#types ⇒ Hash<String, Raml::Parameter::AbstractParameter>
readonly
If the parameter supports multiple types, the type alternatives, keyed by the type.
Attributes included from Raml::Parent
Attributes included from Documentable
Attributes inherited from Raml::PropertiesNode
Attributes inherited from Node
Instance Method Summary collapse
-
#has_multiple_types? ⇒ Boolean
True if the parameter supports multiple type alternatives, false otherwise.
-
#initialize(name, parameter_data, parent) ⇒ AbstractParameter
constructor
A new instance of AbstractParameter.
- #merge(other) ⇒ Object
Methods included from Merge
Methods inherited from Raml::PropertiesNode
#_regexp_property, #non_scalar_properties, #scalar_properties
Constructor Details
#initialize(name, parameter_data, parent) ⇒ AbstractParameter
Returns a new instance of AbstractParameter.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 65 def initialize(name, parameter_data, parent) if parameter_data.is_a? Array @name = name @children ||= [] parameter_data.each do |parameter| @children << self.class.new(name, parameter, self) end elsif parameter_data.is_a? Hash super end end |
Instance Attribute Details
#default ⇒ String, ...
Returns the default value.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 38
|
#enum ⇒ Array<String>?
Returns the possible values. Only valid for parameters of type “string”.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 16
|
#example ⇒ String, ...
Returns an example of the value.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 35
|
#max_length ⇒ Integer?
Returns the maximum value length. Only valid for parameters of type “string”.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 26
|
#maximum ⇒ Numeric?
Returns the maximum value length. Only valid for parameters of type “number” or “integer”.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 32
|
#min_length ⇒ Integer?
Returns the minimum value length. Only valid for parameters of type “string”.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 23
|
#minimum ⇒ Numeric?
Returns the minimum value length. Only valid for parameters of type “number” or “integer”.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 29
|
#pattern ⇒ Regexp?
Returns a regular expression the value must match. Only valid for parameters of type “string”.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 19
|
#repeat ⇒ Boolean
Returns whether the parameter can be repeated.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 44
|
#required ⇒ Boolean
Returns whether the parameter is required.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 41
|
#type ⇒ String
Returns the value type. One of: “string”, “number”, “integer”, “date”, “boolean”, or “file”.
|
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 12
|
#types ⇒ Hash<String, Raml::Parameter::AbstractParameter> (readonly)
Returns if the parameter supports multiple types, the type alternatives, keyed by the type.
51 52 53 |
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 51 scalar_property :type , :enum , :pattern , :min_length , :max_length , :minimum , :maximum , :example , :repeat , :required , :default |
Instance Method Details
#has_multiple_types? ⇒ Boolean
Returns true if the parameter supports multiple type alternatives, false otherwise.
78 79 80 |
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 78 def has_multiple_types? not children.empty? end |
#merge(other) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/raml/node/parameter/abstract_parameter.rb', line 83 def merge(other) raise MergeError, "#{self.class} names don't match." if name != other.name case [ has_multiple_types?, other.has_multiple_types? ] when [ true , true ] match, no_match = other.types.values.partition { |param| types.include? param.type } # Merge parameters with the same type. match = Hash[ match.map { |param| [ param.type, param ] } ] types.each { |type, param| param.merge match[type] if match[type] } # Add parameters with no matching type. @children.concat no_match when [ true , false ] if types[other.type] types[other.type].merge other else @children << other end when [ false, true ] if other.types[self.type] self.merge other.types[self.type] @children << self.clone @children.concat other.types.values.reject { |type| self.type == type.type } reset else @children << self.clone @children.concat other.types.values reset end when [ false, false ] super end self end |