Class: OdataDuty::Property::SingleProp

Inherits:
Object
  • Object
show all
Defined in:
lib/odata_duty/property/single_prop.rb

Direct Known Subclasses

CollectionProp

Instance Attribute Summary collapse

Instance Method Summary collapse

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_methodObject (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__atObject (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_nameObject (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

#mutabilityObject (readonly)

Returns the value of attribute mutability.



7
8
9
# File 'lib/odata_duty/property/single_prop.rb', line 7

def mutability
  @mutability
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/odata_duty/property/single_prop.rb', line 7

def name
  @name
end

#nullableObject (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_typeObject (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_typeObject (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

#typeObject (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

Returns:

  • (Boolean)


53
54
55
# File 'lib/odata_duty/property/single_prop.rb', line 53

def boolean?
  raw_type == EdmBool
end

#calling_method?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


117
# File 'lib/odata_duty/property/single_prop.rb', line 117

def collection?; end

#computed?Boolean

Returns:

  • (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_termObject



33
34
35
# File 'lib/odata_duty/property/single_prop.rb', line 33

def core_annotation_term
  CORE_ANNOTATION_TERMS[mutability]
end

#date?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/odata_duty/property/single_prop.rb', line 65

def date?
  raw_type == EdmDate
end

#datetime?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/odata_duty/property/single_prop.rb', line 69

def datetime?
  raw_type == EdmDateTimeOffset
end

#enum?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/odata_duty/property/single_prop.rb', line 73

def enum?
  raw_type.respond_to?(:members)
end

#enum_membersObject



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

Returns:

  • (Boolean)


25
26
27
# File 'lib/odata_duty/property/single_prop.rb', line 25

def immutable?
  mutability == :immutable
end

#int?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/odata_duty/property/single_prop.rb', line 61

def int?
  raw_type == EdmInt64
end

#non_insertable?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/odata_duty/property/single_prop.rb', line 29

def non_insertable?
  mutability == :non_insertable
end

#nullable?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/odata_duty/property/single_prop.rb', line 49

def nullable?
  nullable
end

#scalar?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/odata_duty/property/single_prop.rb', line 81

def scalar?
  raw_type.scalar?
end

#settable_on_create?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


41
42
43
# File 'lib/odata_duty/property/single_prop.rb', line 41

def settable_on_update?
  !computed? && !immutable?
end

#string?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/odata_duty/property/single_prop.rb', line 57

def string?
  raw_type == EdmString
end

#to_oas2Object



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_typeObject



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