Class: FrOData::Property
- Inherits:
-
Object
- Object
- FrOData::Property
- 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.
Direct Known Subclasses
FrOData::Properties::Binary, FrOData::Properties::Boolean, FrOData::Properties::Collection, FrOData::Properties::Complex, FrOData::Properties::DateTime, FrOData::Properties::Decimal, FrOData::Properties::Enum, FrOData::Properties::Float, FrOData::Properties::Geography::Base, FrOData::Properties::Guid, FrOData::Properties::Integer, FrOData::Properties::String, FrOData::Properties::Time
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The property’s name.
-
#options ⇒ Object
readonly
The property’s options.
-
#value ⇒ Object
The property’s value.
Class Method Summary collapse
-
.from_xml(property_xml, options = {}) ⇒ FrOData::Property
Creates a new property instance from an XML element.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Provides for value-based equality checking.
-
#allows_nil? ⇒ Boolean
Whether the property permits a nil value.
-
#concurrency_mode ⇒ String
The configured concurrency mode for the property.
-
#initialize(name, value, options = {}) ⇒ Property
constructor
Default intialization for a property with a name, value and options.
-
#json_value ⇒ *
Value to be used in JSON.
-
#strict? ⇒ Boolean
Whether the property uses strict validation.
-
#to_xml(xml_builder) ⇒ Object
Returns the XML representation of the property to the supplied XML builder.
-
#type ⇒ Object
Abstract implementation, should return property type, based on FrOData::Service metadata in proper implementation.
-
#url_value ⇒ String
Value to be used in URLs.
-
#xml_value ⇒ String
Value to be used in XML.
Constructor Details
permalink #initialize(name, value, options = {}) ⇒ Property
Default intialization for a property with a name, value and options.
18 19 20 21 22 |
# File 'lib/frodata/property.rb', line 18 def initialize(name, value, = {}) @name = name.to_s @value = value.nil? ? nil : value.to_s @options = .merge() end |
Instance Attribute Details
permalink #name ⇒ Object (readonly)
The property’s name
8 9 10 |
# File 'lib/frodata/property.rb', line 8 def name @name end |
permalink #options ⇒ Object (readonly)
The property’s options
12 13 14 |
# File 'lib/frodata/property.rb', line 12 def @options end |
permalink #value ⇒ Object
The property’s value
10 11 12 |
# File 'lib/frodata/property.rb', line 10 def value @value end |
Class Method Details
permalink .from_xml(property_xml, options = {}) ⇒ FrOData::Property
Creates a new property instance from an XML element
102 103 104 105 106 107 108 109 110 |
# File 'lib/frodata/property.rb', line 102 def self.from_xml(property_xml, = {}) if property_xml.attributes['null'].andand.value == 'true' content = nil else content = property_xml.content end new(property_xml.name, content, ) end |
Instance Method Details
permalink #==(other) ⇒ Boolean
Provides for value-based equality checking.
34 35 36 |
# File 'lib/frodata/property.rb', line 34 def ==(other) self.value == other.value end |
permalink #allows_nil? ⇒ Boolean
Whether the property permits a nil value. (Default=true)
41 42 43 |
# File 'lib/frodata/property.rb', line 41 def allows_nil? [:allows_nil] end |
permalink #concurrency_mode ⇒ String
The configured concurrency mode for the property.
60 61 62 |
# File 'lib/frodata/property.rb', line 60 def concurrency_mode @concurrency_mode ||= [:concurrency_mode] end |
permalink #json_value ⇒ *
Value to be used in JSON.
72 73 74 |
# File 'lib/frodata/property.rb', line 72 def json_value value end |
permalink #strict? ⇒ Boolean
Whether the property uses strict validation. (Default=false)
48 49 50 51 52 53 54 55 56 |
# File 'lib/frodata/property.rb', line 48 def strict? if .key? :strict [:strict] elsif service service.[:strict] else true end end |
permalink #to_xml(xml_builder) ⇒ Object
Returns the XML representation of the property to the supplied XML builder.
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 |
permalink #type ⇒ Object
Abstract implementation, should return property type, based on FrOData::Service metadata in proper implementation.
27 28 29 |
# File 'lib/frodata/property.rb', line 27 def type raise NotImplementedError end |
permalink #url_value ⇒ String
Value to be used in URLs.
78 79 80 |
# File 'lib/frodata/property.rb', line 78 def url_value @value end |
permalink #xml_value ⇒ String
Value to be used in XML.
66 67 68 |
# File 'lib/frodata/property.rb', line 66 def xml_value @value end |