Module: PDC::Resource::Identity

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/pdc/resource/identity.rb

Overview

handles id, primary_key and uri of a Resource

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



55
56
57
# File 'lib/pdc/resource/identity.rb', line 55

def ==(other)
  other.instance_of?(self.class) && id? && id == other.id
end

#as_json(options = nil) ⇒ Object



60
61
62
# File 'lib/pdc/resource/identity.rb', line 60

def as_json(options = nil)
  attributes.as_json(options)
end

#hashObject



51
52
53
# File 'lib/pdc/resource/identity.rb', line 51

def hash
  id.hash
end

#idObject



43
44
45
# File 'lib/pdc/resource/identity.rb', line 43

def id
  attributes[primary_key]
end

#id=(value) ⇒ Object



47
48
49
# File 'lib/pdc/resource/identity.rb', line 47

def id=(value)
  attributes[primary_key] = value if value.present?
end

#id?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/pdc/resource/identity.rb', line 39

def id?
  attributes[primary_key].present?
end

#uriObject



64
65
66
# File 'lib/pdc/resource/identity.rb', line 64

def uri
  Path.new(self.class.uri.to_s, attributes).expanded
end