Class: DataMapper::Property::GURN

Inherits:
String
  • Object
show all
Defined in:
lib/omf-sfa/resource/gurn.rb

Instance Method Summary collapse

Instance Method Details

#custom?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/omf-sfa/resource/gurn.rb', line 135

def custom?
  true
end

#dump(value) ⇒ Object



171
172
173
# File 'lib/omf-sfa/resource/gurn.rb', line 171

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



153
154
155
156
157
158
159
160
161
# File 'lib/omf-sfa/resource/gurn.rb', line 153

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



163
164
165
166
167
168
169
# File 'lib/omf-sfa/resource/gurn.rb', line 163

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

Returns:

  • (Boolean)


139
140
141
# File 'lib/omf-sfa/resource/gurn.rb', line 139

def primitive?(value)
  value.kind_of?(OMF::SFA::Resource::GURN)
end

#set(resource, value) ⇒ Object



189
190
191
192
# File 'lib/omf-sfa/resource/gurn.rb', line 189

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

Parameters:

  • value (Hash, #to_mash, #to_s)

    value to be typecast

Returns:

  • (GURN)

    GURN constructed from value



184
185
186
# File 'lib/omf-sfa/resource/gurn.rb', line 184

def typecast_to_primitive(value)
  raise "BUG: Shouldn't be called anymore"
end

#valid?(value, negated = false) ⇒ Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/omf-sfa/resource/gurn.rb', line 143

def valid?(value, negated = false)
  super || primitive?(value) #|| value.kind_of?(::String)
end