Class: OdataDuty::Property::SingleProp
- Inherits:
-
Object
- Object
- OdataDuty::Property::SingleProp
- Defined in:
- lib/odata_duty/property/single_prop.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#calling_method ⇒ Object
readonly
Returns the value of attribute calling_method.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#line__defined__at ⇒ Object
readonly
Returns the value of attribute line__defined__at.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#mutability ⇒ Object
readonly
Returns the value of attribute mutability.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nullable ⇒ Object
readonly
Returns the value of attribute nullable.
-
#raw_type ⇒ Object
readonly
Returns the value of attribute raw_type.
-
#set_type ⇒ Object
readonly
Returns the value of attribute set_type.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #boolean? ⇒ Boolean
- #calling_method? ⇒ Boolean
-
#collection? ⇒ Boolean
nil (falsy) rather than false: callers only consume truthiness.
- #computed? ⇒ Boolean
- #convert(value, context) ⇒ Object
- #core_annotation_term ⇒ Object
- #date? ⇒ Boolean
- #datetime? ⇒ Boolean
- #enum? ⇒ Boolean
- #enum_members ⇒ Object
- #filter_convert(value, context) ⇒ Object
- #immutable? ⇒ Boolean
-
#initialize(name, type, line__defined__at:, nullable:, method:, mutability:, description:) ⇒ SingleProp
constructor
A new instance of SingleProp.
- #int? ⇒ Boolean
- #non_insertable? ⇒ Boolean
- #nullable? ⇒ Boolean
- #scalar? ⇒ Boolean
- #settable_on_create? ⇒ Boolean
- #settable_on_update? ⇒ Boolean
- #string? ⇒ Boolean
- #to_oas2 ⇒ Object
- #to_oas2_type ⇒ Object
- #to_value(value, context) ⇒ Object
Constructor Details
#initialize(name, type, line__defined__at:, nullable:, method:, mutability:, description:) ⇒ SingleProp
Returns a new instance of SingleProp.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/odata_duty/property/single_prop.rb', line 10 def initialize(name, type, line__defined__at:, nullable:, method:, mutability:, description:) @line__defined__at = line__defined__at @name = name.to_sym @calling_method = method if method.respond_to?(:call) method = nil if method.respond_to?(:call) @method_name = (method || name).to_sym @nullable = nullable ? true : false @mutability = mutability @description = description load_type_instance_vars(type) end |
Instance Attribute Details
#calling_method ⇒ Object (readonly)
Returns the value of attribute calling_method.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def calling_method @calling_method end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def description @description end |
#line__defined__at ⇒ Object (readonly)
Returns the value of attribute line__defined__at.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def line__defined__at @line__defined__at end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def method_name @method_name end |
#mutability ⇒ Object (readonly)
Returns the value of attribute mutability.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def mutability @mutability end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def name @name end |
#nullable ⇒ Object (readonly)
Returns the value of attribute nullable.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def nullable @nullable end |
#raw_type ⇒ Object (readonly)
Returns the value of attribute raw_type.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def raw_type @raw_type end |
#set_type ⇒ Object (readonly)
Returns the value of attribute set_type.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def set_type @set_type end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/odata_duty/property/single_prop.rb', line 7 def type @type end |
Instance Method Details
#boolean? ⇒ Boolean
55 56 57 |
# File 'lib/odata_duty/property/single_prop.rb', line 55 def boolean? raw_type == EdmBool end |
#calling_method? ⇒ Boolean
47 48 49 |
# File 'lib/odata_duty/property/single_prop.rb', line 47 def calling_method? !calling_method.nil? end |
#collection? ⇒ Boolean
nil (falsy) rather than false: callers only consume truthiness
120 |
# File 'lib/odata_duty/property/single_prop.rb', line 120 def collection?; end |
#computed? ⇒ Boolean
23 24 25 |
# File 'lib/odata_duty/property/single_prop.rb', line 23 def computed? mutability == :computed end |
#convert(value, context) ⇒ Object
93 94 95 96 97 |
# File 'lib/odata_duty/property/single_prop.rb', line 93 def convert(value, context) return if value.nil? @set_type.to_value(value, context) end |
#core_annotation_term ⇒ Object
35 36 37 |
# File 'lib/odata_duty/property/single_prop.rb', line 35 def core_annotation_term CORE_ANNOTATION_TERMS[mutability] end |
#date? ⇒ Boolean
67 68 69 |
# File 'lib/odata_duty/property/single_prop.rb', line 67 def date? raw_type == EdmDate end |
#datetime? ⇒ Boolean
71 72 73 |
# File 'lib/odata_duty/property/single_prop.rb', line 71 def datetime? raw_type == EdmDateTimeOffset end |
#enum? ⇒ Boolean
75 76 77 |
# File 'lib/odata_duty/property/single_prop.rb', line 75 def enum? raw_type.respond_to?(:members) end |
#enum_members ⇒ Object
79 80 81 |
# File 'lib/odata_duty/property/single_prop.rb', line 79 def enum_members raw_type.members end |
#filter_convert(value, context) ⇒ Object
99 100 101 102 103 |
# File 'lib/odata_duty/property/single_prop.rb', line 99 def filter_convert(value, context) convert(value, context) rescue OdataDuty::InvalidValue raise InvalidFilterValue, "Invalid value #{value} for #{name}" end |
#immutable? ⇒ Boolean
27 28 29 |
# File 'lib/odata_duty/property/single_prop.rb', line 27 def immutable? mutability == :immutable end |
#int? ⇒ Boolean
63 64 65 |
# File 'lib/odata_duty/property/single_prop.rb', line 63 def int? raw_type == EdmInt64 end |
#non_insertable? ⇒ Boolean
31 32 33 |
# File 'lib/odata_duty/property/single_prop.rb', line 31 def non_insertable? mutability == :non_insertable end |
#nullable? ⇒ Boolean
51 52 53 |
# File 'lib/odata_duty/property/single_prop.rb', line 51 def nullable? nullable end |
#scalar? ⇒ Boolean
83 84 85 |
# File 'lib/odata_duty/property/single_prop.rb', line 83 def scalar? raw_type.scalar? end |
#settable_on_create? ⇒ Boolean
39 40 41 |
# File 'lib/odata_duty/property/single_prop.rb', line 39 def settable_on_create? !computed? && !non_insertable? end |
#settable_on_update? ⇒ Boolean
43 44 45 |
# File 'lib/odata_duty/property/single_prop.rb', line 43 def settable_on_update? !computed? && !immutable? end |
#string? ⇒ Boolean
59 60 61 |
# File 'lib/odata_duty/property/single_prop.rb', line 59 def string? raw_type == EdmString end |
#to_oas2 ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/odata_duty/property/single_prop.rb', line 105 def to_oas2 to_oas2_type.dup.tap do |oas2| oas2.merge!('readOnly' => true) if computed? oas2.merge!('x-nullable' => true) if nullable oas2.merge!('description' => description) if description end end |
#to_oas2_type ⇒ Object
113 114 115 116 117 |
# File 'lib/odata_duty/property/single_prop.rb', line 113 def to_oas2_type return raw_type.to_oas2(is_collection: false) if scalar? && !enum? { '$ref' => "#/definitions/#{raw_type.name}" } end |
#to_value(value, context) ⇒ Object
87 88 89 90 91 |
# File 'lib/odata_duty/property/single_prop.rb', line 87 def to_value(value, context) convert(value, context) rescue InvalidValue => e raise InvalidValue, "#{name} : #{e}" end |