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.
-
#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:) ⇒ 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:) ⇒ SingleProp
Returns a new instance of SingleProp.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/odata_duty/property/single_prop.rb', line 10 def initialize(name, type, line__defined__at:, nullable:, method:, mutability:) @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 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 |
#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
53 54 55 |
# File 'lib/odata_duty/property/single_prop.rb', line 53 def boolean? raw_type == EdmBool end |
#calling_method? ⇒ Boolean
45 46 47 |
# File 'lib/odata_duty/property/single_prop.rb', line 45 def calling_method? !calling_method.nil? end |
#collection? ⇒ Boolean
nil (falsy) rather than false: callers only consume truthiness
117 |
# File 'lib/odata_duty/property/single_prop.rb', line 117 def collection?; end |
#computed? ⇒ Boolean
21 22 23 |
# File 'lib/odata_duty/property/single_prop.rb', line 21 def computed? mutability == :computed end |
#convert(value, context) ⇒ Object
91 92 93 94 95 |
# File 'lib/odata_duty/property/single_prop.rb', line 91 def convert(value, context) return if value.nil? @set_type.to_value(value, context) end |
#core_annotation_term ⇒ Object
33 34 35 |
# File 'lib/odata_duty/property/single_prop.rb', line 33 def core_annotation_term CORE_ANNOTATION_TERMS[mutability] end |
#date? ⇒ Boolean
65 66 67 |
# File 'lib/odata_duty/property/single_prop.rb', line 65 def date? raw_type == EdmDate end |
#datetime? ⇒ Boolean
69 70 71 |
# File 'lib/odata_duty/property/single_prop.rb', line 69 def datetime? raw_type == EdmDateTimeOffset end |
#enum? ⇒ Boolean
73 74 75 |
# File 'lib/odata_duty/property/single_prop.rb', line 73 def enum? raw_type.respond_to?(:members) end |
#enum_members ⇒ Object
77 78 79 |
# File 'lib/odata_duty/property/single_prop.rb', line 77 def enum_members raw_type.members end |
#filter_convert(value, context) ⇒ Object
97 98 99 100 101 |
# File 'lib/odata_duty/property/single_prop.rb', line 97 def filter_convert(value, context) convert(value, context) rescue OdataDuty::InvalidValue raise InvalidFilterValue, "Invalid value #{value} for #{name}" end |
#immutable? ⇒ Boolean
25 26 27 |
# File 'lib/odata_duty/property/single_prop.rb', line 25 def immutable? mutability == :immutable end |
#int? ⇒ Boolean
61 62 63 |
# File 'lib/odata_duty/property/single_prop.rb', line 61 def int? raw_type == EdmInt64 end |
#non_insertable? ⇒ Boolean
29 30 31 |
# File 'lib/odata_duty/property/single_prop.rb', line 29 def non_insertable? mutability == :non_insertable end |
#nullable? ⇒ Boolean
49 50 51 |
# File 'lib/odata_duty/property/single_prop.rb', line 49 def nullable? nullable end |
#scalar? ⇒ Boolean
81 82 83 |
# File 'lib/odata_duty/property/single_prop.rb', line 81 def scalar? raw_type.scalar? end |
#settable_on_create? ⇒ Boolean
37 38 39 |
# File 'lib/odata_duty/property/single_prop.rb', line 37 def settable_on_create? !computed? && !non_insertable? end |
#settable_on_update? ⇒ Boolean
41 42 43 |
# File 'lib/odata_duty/property/single_prop.rb', line 41 def settable_on_update? !computed? && !immutable? end |
#string? ⇒ Boolean
57 58 59 |
# File 'lib/odata_duty/property/single_prop.rb', line 57 def string? raw_type == EdmString end |
#to_oas2 ⇒ Object
103 104 105 106 107 108 |
# File 'lib/odata_duty/property/single_prop.rb', line 103 def to_oas2 to_oas2_type.dup.tap do |oas2| oas2.merge!('readOnly' => true) if computed? oas2.merge!('x-nullable' => true) if nullable end end |
#to_oas2_type ⇒ Object
110 111 112 113 114 |
# File 'lib/odata_duty/property/single_prop.rb', line 110 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
85 86 87 88 89 |
# File 'lib/odata_duty/property/single_prop.rb', line 85 def to_value(value, context) convert(value, context) rescue InvalidValue => e raise InvalidValue, "#{name} : #{e}" end |