Class: DataMapper::Property::GURN
- Inherits:
-
String
- Object
- String
- DataMapper::Property::GURN
- Defined in:
- lib/omf-sfa/resource/gurn.rb
Instance Method Summary collapse
- #custom? ⇒ Boolean
- #dump(value) ⇒ Object
-
#load(value) ⇒ Object
We don’t want this to be called, but the Model::Property calls this one first before calling #set! on this instance again with the value returned here.
- #load2(value, context_class) ⇒ Object
- #primitive?(value) ⇒ Boolean
- #set(resource, value) ⇒ Object
-
#typecast_to_primitive(value) ⇒ GURN
private
Typecasts an arbitrary value to a GURN.
- #valid?(value, negated = false) ⇒ Boolean
Instance Method Details
#custom? ⇒ Boolean
121 122 123 |
# File 'lib/omf-sfa/resource/gurn.rb', line 121 def custom? true end |
#dump(value) ⇒ Object
157 158 159 |
# File 'lib/omf-sfa/resource/gurn.rb', line 157 def dump(value) value.to_s unless value.nil? end |
#load(value) ⇒ Object
We don’t want this to be called, but the Model::Property calls this one first before calling #set! on this instance again with the value returned here. Hopefully this is the only place this happens. Therefore, we just return value unchanged and take care of casting in load2
139 140 141 142 143 144 145 146 147 |
# File 'lib/omf-sfa/resource/gurn.rb', line 139 def load(value) if value if value.start_with?('urn') return OMF::SFA::Resource::GURN.create(value) end raise "BUG: Shouldn't be called anymore (#{value})" end nil end |
#load2(value, context_class) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/omf-sfa/resource/gurn.rb', line 149 def load2(value, context_class) if value #puts "LOAD #{value}||#{value.class}||#{context.inspect}" return OMF::SFA::Resource::GURN.create(value, context_class) end nil end |
#primitive?(value) ⇒ Boolean
125 126 127 |
# File 'lib/omf-sfa/resource/gurn.rb', line 125 def primitive?(value) value.kind_of?(OMF::SFA::Resource::GURN) end |
#set(resource, value) ⇒ Object
175 176 177 178 |
# File 'lib/omf-sfa/resource/gurn.rb', line 175 def set(resource, value) #puts ">>> SET: #{resource}" set!(resource, load2(value, resource.class)) end |
#typecast_to_primitive(value) ⇒ GURN
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Typecasts an arbitrary value to a GURN
170 171 172 |
# File 'lib/omf-sfa/resource/gurn.rb', line 170 def typecast_to_primitive(value) raise "BUG: Shouldn't be called anymore" end |
#valid?(value, negated = false) ⇒ Boolean
129 130 131 |
# File 'lib/omf-sfa/resource/gurn.rb', line 129 def valid?(value, negated = false) super || primitive?(value) #|| value.kind_of?(::String) end |