Class: FrOData::Property

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

Overview

FrOData::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 FrOData::Properties namespace.

Instance Attribute Summary collapse

Class Method 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: {})
[View source] [View on GitHub]

18
19
20
21
22
# File 'lib/frodata/property.rb', line 18

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

[View on GitHub]

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

def name
  @name
end

#optionsObject (readonly)

The property’s options

[View on GitHub]

12
13
14
# File 'lib/frodata/property.rb', line 12

def options
  @options
end

#valueObject

The property’s value

[View on GitHub]

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

def value
  @value
end

Class Method Details

.from_xml(property_xml, options = {}) ⇒ FrOData::Property

Creates a new property instance from an XML element

Parameters:

  • property_xml (Nokogiri::XML::Element)
  • options (Hash) (defaults to: {})

Returns:

[View source] [View on GitHub]

102
103
104
105
106
107
108
109
110
# File 'lib/frodata/property.rb', line 102

def self.from_xml(property_xml, options = {})
  if property_xml.attributes['null'].andand.value == 'true'
    content = nil
  else
    content = property_xml.content
  end

  new(property_xml.name, content, options)
end

Instance Method Details

#==(other) ⇒ Boolean

Provides for value-based equality checking.

Parameters:

  • other (value)

    object for comparison

Returns:

  • (Boolean)
[View source] [View on GitHub]

34
35
36
# File 'lib/frodata/property.rb', line 34

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

#allows_nil?Boolean

Whether the property permits a nil value. (Default=true)

Returns:

  • (Boolean)
[View source] [View on GitHub]

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

def allows_nil?
  options[:allows_nil]
end

#concurrency_modeString

The configured concurrency mode for the property.

Returns:

  • (String)
[View source] [View on GitHub]

60
61
62
# File 'lib/frodata/property.rb', line 60

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

#json_value*

Value to be used in JSON.

Returns:

  • (*)
[View source] [View on GitHub]

72
73
74
# File 'lib/frodata/property.rb', line 72

def json_value
  value
end

#strict?Boolean

Whether the property uses strict validation. (Default=false)

Returns:

  • (Boolean)
[View source] [View on GitHub]

48
49
50
51
52
53
54
55
56
# File 'lib/frodata/property.rb', line 48

def strict?
  if options.key? :strict
    options[:strict]
  elsif service
    service.options[:strict]
  else
    true
  end
end

#to_xml(xml_builder) ⇒ Object

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

Parameters:

  • xml_builder (Nokogiri::XML::Builder)
[View source] [View on GitHub]

85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/frodata/property.rb', line 85

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 FrOData::Service metadata in proper implementation.

Raises:

  • NotImplementedError

[View source] [View on GitHub]

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

def type
  raise NotImplementedError
end

#url_valueString

Value to be used in URLs.

Returns:

  • (String)
[View source] [View on GitHub]

78
79
80
# File 'lib/frodata/property.rb', line 78

def url_value
  @value
end

#xml_valueString

Value to be used in XML.

Returns:

  • (String)
[View source] [View on GitHub]

66
67
68
# File 'lib/frodata/property.rb', line 66

def xml_value
  @value
end