Class: OData::Property

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

Overview

OData::Property represents an abstract property, defining the basic interface and required methods, with some default implementations. All supported property types should be implemented under the OData::Properties namespace.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value, options = {}) ⇒ Property

Default intialization for a property with a name, value and options.

Parameters:

  • name (to_s)
  • value (to_s, nil)
  • options (Hash) (defaults to: {})


16
17
18
19
20
# File 'lib/odata/property.rb', line 16

def initialize(name, value, options = {})
  @name = name.to_s
  @value = value.nil? ? nil : value.to_s
  @options = default_options.merge(options)
end

Instance Attribute Details

#nameObject (readonly)

The property’s name



8
9
10
# File 'lib/odata/property.rb', line 8

def name
  @name
end

#valueObject

The property’s value



10
11
12
# File 'lib/odata/property.rb', line 10

def value
  @value
end

Instance Method Details

#==(other) ⇒ Boolean

Provides for value-based equality checking.

Parameters:

  • other (value)

    object for comparison

Returns:

  • (Boolean)


32
33
34
# File 'lib/odata/property.rb', line 32

def ==(other)
  self.value == other.value
end

#allows_nil?Boolean

Whether the property permits a nil value.

Returns:

  • (Boolean)


38
39
40
# File 'lib/odata/property.rb', line 38

def allows_nil?
  @allows_nil ||= options[:allows_nil]
end

#concurrency_modeString

The configured concurrency mode for the property.

Returns:

  • (String)


44
45
46
# File 'lib/odata/property.rb', line 44

def concurrency_mode
  @concurrecy_mode ||= options[:concurrency_mode]
end

#to_xml(xml_builder) ⇒ Object

Returns the XML representation of the property to the supplied XML builder.

Parameters:

  • xml_builder (Nokogiri::XML::Builder)


63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/odata/property.rb', line 63

def to_xml(xml_builder)
  attributes = {
      'metadata:type' => type,
  }

  if value.nil?
    attributes['metadata:null'] = 'true'
    xml_builder['data'].send(name.to_sym, attributes)
  else
    xml_builder['data'].send(name.to_sym, attributes, xml_value)
  end
end

#typeObject

Abstract implementation, should return property type, based on OData::Service metadata in proper implementation.

Raises:

  • NotImplementedError



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

def type
  raise NotImplementedError
end

#url_valueString

Value to be used in URLs.

Returns:

  • (String)


56
57
58
# File 'lib/odata/property.rb', line 56

def url_value
  value
end

#xml_valueString

Value to be used in XML.

Returns:

  • (String)


50
51
52
# File 'lib/odata/property.rb', line 50

def xml_value
  value
end