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)


133
134
135
# File 'lib/omf-sfa/resource/gurn.rb', line 133

def custom?
  true
end

#dump(value) ⇒ Object



169
170
171
# File 'lib/omf-sfa/resource/gurn.rb', line 169

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



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

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



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

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)


137
138
139
# File 'lib/omf-sfa/resource/gurn.rb', line 137

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

#set(resource, value) ⇒ Object



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

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



182
183
184
# File 'lib/omf-sfa/resource/gurn.rb', line 182

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

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

Returns:

  • (Boolean)


141
142
143
# File 'lib/omf-sfa/resource/gurn.rb', line 141

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