Class: Tama::Memory::EntityParams

Inherits:
Data
  • Object
show all
Defined in:
lib/tama/memory/entity_params.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier:, record:, validate_record: true) ⇒ EntityParams

Returns a new instance of EntityParams.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tama/memory/entity_params.rb', line 6

def initialize(identifier:, record:, validate_record: true)
  unless identifier.is_a?(String) && !identifier.empty?
    raise Error::ValidationError.new("identifier is required", errors: {identifier: "must be a non-empty string"})
  end
  unless record.is_a?(Hash)
    raise Error::ValidationError.new("record is required", errors: {record: "must be a hash"})
  end
  unless [true, false].include?(validate_record)
    raise Error::ValidationError.new("validate_record must be boolean", errors: {validate_record: "must be boolean"})
  end

  super
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier

Returns:

  • (Object)

    the current value of identifier



5
6
7
# File 'lib/tama/memory/entity_params.rb', line 5

def identifier
  @identifier
end

#recordObject (readonly)

Returns the value of attribute record

Returns:

  • (Object)

    the current value of record



5
6
7
# File 'lib/tama/memory/entity_params.rb', line 5

def record
  @record
end

#validate_recordObject (readonly)

Returns the value of attribute validate_record

Returns:

  • (Object)

    the current value of validate_record



5
6
7
# File 'lib/tama/memory/entity_params.rb', line 5

def validate_record
  @validate_record
end

Class Method Details

.parse(value) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/tama/memory/entity_params.rb', line 20

def self.parse(value)
  data = Params.hash(value, "entity")
  new(
    identifier: data["identifier"],
    record: data["record"],
    validate_record: data.fetch("validate_record", true)
  )
end

Instance Method Details

#to_hObject



29
30
31
# File 'lib/tama/memory/entity_params.rb', line 29

def to_h
  {"identifier" => identifier, "record" => record, "validate_record" => validate_record}
end