Class: Airspace::Dataset

Inherits:
Object
  • Object
show all
Includes:
HasMetadata, InfoKeys
Defined in:
lib/airspace/dataset.rb

Overview

This is the main input class that can persist data.

Constant Summary

Constants included from InfoKeys

InfoKeys::DATA_KEY, InfoKeys::METADATA_KEY, InfoKeys::SEPARATOR_CHAR

Instance Attribute Summary collapse

Attributes included from HasMetadata

#metadata

Instance Method Summary collapse

Constructor Details

#initialize(client, id: nil, data: {}, pages: [], options: {}) ⇒ Dataset

Returns a new instance of Dataset.

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/airspace/dataset.rb', line 23

def initialize(client, id: nil, data: {}, pages: [], options: {})
  raise ArgumentError, 'client is required' unless client

  @client     = client
  @data       = data || {}
  @id         = id || SecureRandom.uuid
  @pages      = pages || []
  @prefix     = options[:prefix].to_s
  @serializer = options[:serializer] || ::Airspace::Serializer.new

  @metadata = ::Airspace::Metadata.new(
    expires_in_seconds: options[:expires_in_seconds],
    page_count: pages.length,
    pages_per_chunk: options[:pages_per_chunk]
  )

  freeze
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



16
17
18
# File 'lib/airspace/dataset.rb', line 16

def client
  @client
end

#dataObject (readonly)

Returns the value of attribute data.



16
17
18
# File 'lib/airspace/dataset.rb', line 16

def data
  @data
end

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/airspace/dataset.rb', line 16

def id
  @id
end

#pagesObject (readonly)

Returns the value of attribute pages.



16
17
18
# File 'lib/airspace/dataset.rb', line 16

def pages
  @pages
end

#prefixObject (readonly)

Returns the value of attribute prefix.



16
17
18
# File 'lib/airspace/dataset.rb', line 16

def prefix
  @prefix
end

#serializerObject (readonly)

Returns the value of attribute serializer.



16
17
18
# File 'lib/airspace/dataset.rb', line 16

def serializer
  @serializer
end

Instance Method Details

#saveObject



42
43
44
45
46
# File 'lib/airspace/dataset.rb', line 42

def save
  store.persist(key, info_hash, chunks, expires_in_seconds)

  self
end