Class: Opushon::Parameter Private
- Inherits:
-
Object
- Object
- Opushon::Parameter
- Defined in:
- lib/opushon/parameter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The content of headers, query string and body params MUST be described with
the keys below. When a key is missing, its default value is assigned.
Instance Attribute Summary collapse
- #description ⇒ Object readonly private
- #example ⇒ Object readonly private
- #max ⇒ Object readonly private
- #maxlen ⇒ Object readonly private
- #min ⇒ Object readonly private
- #minlen ⇒ Object readonly private
- #nullifiable ⇒ Object readonly private
- #pattern ⇒ Object readonly private
- #restricted_values ⇒ Object readonly private
- #title ⇒ Object readonly private
- #type ⇒ Object readonly private
Class Method Summary collapse
- .load(hash) ⇒ Object private
Instance Method Summary collapse
-
#initialize(title: '', description: '', type: 'string', nullifiable: true, restricted_values: nil, example: nil, minlen: nil, maxlen: nil, pattern: nil, min: nil, max: nil) ⇒ Parameter
constructor
private
A new instance of Parameter.
- #to_h ⇒ Object private
Constructor Details
#initialize(title: '', description: '', type: 'string', nullifiable: true, restricted_values: nil, example: nil, minlen: nil, maxlen: nil, pattern: nil, min: nil, max: nil) ⇒ Parameter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Parameter.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/opushon/parameter.rb', line 43 def initialize(title: '', description: '', type: 'string', nullifiable: true, restricted_values: nil, example: nil, minlen: nil, maxlen: nil, pattern: nil, min: nil, max: nil) raise ArgumentError, "title #{title.inspect}" unless title.is_a?(String) raise ArgumentError, "description #{description.inspect}" unless description.is_a?(String) raise ArgumentError, "type #{type.inspect}" unless type.is_a?(String) raise ArgumentError, "nullifiable #{nullifiable.inspect}" unless [false, true].include?(nullifiable) unless restricted_values.nil? raise ArgumentError, "restricted_values #{restricted_values.inspect}" unless restricted_values.is_a?(Array) end unless example.nil? raise ArgumentError, "example #{example.inspect}" unless example.is_a?(BasicObject) end unless minlen.nil? raise ArgumentError, "minlen #{minlen.inspect}" unless minlen.is_a?(Integer) end unless maxlen.nil? raise ArgumentError, "maxlen #{maxlen.inspect}" unless maxlen.is_a?(Integer) end unless pattern.nil? raise ArgumentError, "pattern #{pattern.inspect}" unless pattern.is_a?(String) end unless min.nil? raise ArgumentError, "min #{min.inspect}" unless min.is_a?(Integer) end unless max.nil? raise ArgumentError, "max #{max.inspect}" unless max.is_a?(Integer) end @title = title @description = description @type = type @nullifiable = nullifiable @restricted_values = restricted_values.map { |restricted_value| RestrictedValue.load(restricted_value) } unless restricted_values.nil? @example = example @minlen = minlen @maxlen = maxlen @pattern = Regexp.new(pattern) unless pattern.nil? @min = min @max = max end |
Instance Attribute Details
#description ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def description @description end |
#example ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def example @example end |
#max ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def max @max end |
#maxlen ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def maxlen @maxlen end |
#min ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def min @min end |
#minlen ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def minlen @minlen end |
#nullifiable ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def nullifiable @nullifiable end |
#pattern ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def pattern @pattern end |
#restricted_values ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def restricted_values @restricted_values end |
#title ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def title @title end |
#type ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
41 42 43 |
# File 'lib/opushon/parameter.rb', line 41 def type @type end |
Class Method Details
.load(hash) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/opushon/parameter.rb', line 9 def self.load(hash) raise ArgumentError, "hash #{hash.inspect}" unless hash.is_a?(Hash) title = hash.fetch('title', nil) description = hash.fetch('description', nil) type = hash.fetch('type', nil) nullifiable = hash.fetch('nullifiable', nil) restricted_values = hash.fetch('restricted_values', nil) example = hash.fetch('example', nil) minlen = hash.fetch('minlen', nil) maxlen = hash.fetch('maxlen', nil) pattern = hash.fetch('pattern', nil) min = hash.fetch('min', nil) max = hash.fetch('max', nil) hash = { title: title, description: description, type: type, nullifiable: nullifiable, restricted_values: restricted_values, example: example, minlen: minlen, maxlen: maxlen, pattern: pattern, min: min, max: max }.compact new(**hash) end |
Instance Method Details
#to_h ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
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 |
# File 'lib/opushon/parameter.rb', line 90 def to_h h = { title: title, description: description, type: type, nullifiable: nullifiable, restricted_values: maybe_to_a_of_h(restricted_values), example: example } if type.eql?('string') return h.merge( minlen: minlen, maxlen: maxlen, pattern: pattern&.to_s ) end if type.eql?('number') return h.merge( min: min, max: max ) end h end |