Class: Unloq::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/unloq/entity.rb

Direct Known Subclasses

Author, Recipient

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, type: nil, meta: {}) ⇒ Entity

Initialize an instance of an unloq entity. This has subclasses for Author and Recipient for ease of understanding.

Parameters:

  • id (String) (defaults to: nil)

    The ID of the entity (may also be an integer), e.g. 1 or ‘1’

  • type (String) (defaults to: nil)

    The type of the entity, e.g. ‘User’



9
10
11
12
13
14
15
16
17
# File 'lib/unloq/entity.rb', line 9

def initialize id: nil, type: nil, meta: {}
  unless id && type
    raise ArgumentError.new("You must include both an id and a type, e.g. #{self.class.to_s}.new(id: 1, type: 'User')")
  end

  @id   = id
  @type = type
  @meta = meta
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/unloq/entity.rb', line 3

def id
  @id
end

#metaObject (readonly)

Returns the value of attribute meta.



3
4
5
# File 'lib/unloq/entity.rb', line 3

def meta
  @meta
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/unloq/entity.rb', line 3

def type
  @type
end