Class: RubyRest::Atom::SimpleProperty
- Inherits:
-
Object
- Object
- RubyRest::Atom::SimpleProperty
show all
- Defined in:
- lib/rubyrest/atom.rb
Instance Method Summary
collapse
-
#app ⇒ Object
-
#bind(object, options, value) ⇒ Object
-
#format(object, options, xml) ⇒ Object
-
#initialize(parent) ⇒ SimpleProperty
constructor
A new instance of SimpleProperty.
-
#object_value(object, options) ⇒ Object
-
#parse(object, options, xml) ⇒ Object
-
#tag(options) ⇒ Object
-
#value_from_model(options, object) ⇒ Object
-
#value_from_xml(options, xml) ⇒ Object
-
#xml_value(object, options) ⇒ Object
Constructor Details
Returns a new instance of SimpleProperty.
108
109
110
|
# File 'lib/rubyrest/atom.rb', line 108
def initialize( parent )
@parent = parent
end
|
Instance Method Details
#app ⇒ Object
113
114
115
|
# File 'lib/rubyrest/atom.rb', line 113
def app
@parent.app
end
|
#bind(object, options, value) ⇒ Object
132
133
134
|
# File 'lib/rubyrest/atom.rb', line 132
def bind( object, options, value )
object[ options[:property] ]=value
end
|
149
150
151
152
153
154
|
# File 'lib/rubyrest/atom.rb', line 149
def format( object, options, xml )
return if options[:bind] == :request
value = value_from_model( options, object )
new_element = xml.add_element( tag( options ) )
new_element.add_text( value.to_s ) if value != nil
end
|
#object_value(object, options) ⇒ Object
122
123
124
|
# File 'lib/rubyrest/atom.rb', line 122
def object_value( object, options )
object[ options[:property] ]
end
|
#parse(object, options, xml) ⇒ Object
136
137
138
139
|
# File 'lib/rubyrest/atom.rb', line 136
def parse( object, options, xml )
return if options[:bind] == :response
bind( object, options, value_from_xml( options, xml ) )
end
|
#tag(options) ⇒ Object
117
118
119
120
|
# File 'lib/rubyrest/atom.rb', line 117
def tag( options )
value = options[:tag]||options[:property]
return value.to_s
end
|
#value_from_model(options, object) ⇒ Object
145
146
147
|
# File 'lib/rubyrest/atom.rb', line 145
def value_from_model( options, object )
object_value( object, options ).to_s
end
|
#value_from_xml(options, xml) ⇒ Object
141
142
143
|
# File 'lib/rubyrest/atom.rb', line 141
def value_from_xml( options, xml )
xml_value( xml, options )
end
|
#xml_value(object, options) ⇒ Object
126
127
128
129
130
|
# File 'lib/rubyrest/atom.rb', line 126
def xml_value( object, options )
required = true
required = options[:required] if options[:required] != nil
return object.get_value( tag( options ), required )
end
|