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:, 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_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

#descriptionObject (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__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)


55
56
57
# File 'lib/odata_duty/property/single_prop.rb', line 55

def boolean?
  raw_type == EdmBool
end

#calling_method?Boolean

Returns:

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

Returns:

  • (Boolean)


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

def collection?; end

#computed?Boolean

Returns:

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



35
36
37
# File 'lib/odata_duty/property/single_prop.rb', line 35

def core_annotation_term
  CORE_ANNOTATION_TERMS[mutability]
end

#date?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/odata_duty/property/single_prop.rb', line 67

def date?
  raw_type == EdmDate
end

#datetime?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/odata_duty/property/single_prop.rb', line 71

def datetime?
  raw_type == EdmDateTimeOffset
end

#enum?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/odata_duty/property/single_prop.rb', line 75

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

#enum_membersObject



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

Returns:

  • (Boolean)


27
28
29
# File 'lib/odata_duty/property/single_prop.rb', line 27

def immutable?
  mutability == :immutable
end

#int?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/odata_duty/property/single_prop.rb', line 63

def int?
  raw_type == EdmInt64
end

#non_insertable?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/odata_duty/property/single_prop.rb', line 31

def non_insertable?
  mutability == :non_insertable
end

#nullable?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/odata_duty/property/single_prop.rb', line 51

def nullable?
  nullable
end

#scalar?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/odata_duty/property/single_prop.rb', line 83

def scalar?
  raw_type.scalar?
end

#settable_on_create?Boolean

Returns:

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

Returns:

  • (Boolean)


43
44
45
# File 'lib/odata_duty/property/single_prop.rb', line 43

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

#string?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/odata_duty/property/single_prop.rb', line 59

def string?
  raw_type == EdmString
end

#to_oas2Object



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_typeObject



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