class Airspace::Dataset
This is the main input class that can persist data.
Attributes
client[R]
data[R]
id[R]
pages[R]
prefix[R]
serializer[R]
Public Class Methods
new(client, id: nil, data: {}, pages: [], options: {})
click to toggle source
# 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
Public Instance Methods
save()
click to toggle source
# File lib/airspace/dataset.rb, line 42 def save store.persist(key, info_hash, chunks, expires_in_seconds) self end
Private Instance Methods
chunks()
click to toggle source
# File lib/airspace/dataset.rb, line 57 def chunks chunks = [] chunker.each(page_count) do |chunk| chunk_data = pages[chunk.page_index_start..chunk.page_index_end] chunks << chunk_data.map do |page| page.map { |row| serializer.serialize_row(row) } end end chunks end
info_hash()
click to toggle source
# File lib/airspace/dataset.rb, line 50 def info_hash {}.tap do |hash| hash[DATA_KEY] = serializer.serialize_data(data) hash[METADATA_KEY] = metadata.to_json end end
key()
click to toggle source
# File lib/airspace/dataset.rb, line 75 def key ::Airspace::Key.new(id, prefix: prefix) end
store()
click to toggle source
# File lib/airspace/dataset.rb, line 71 def store ::Airspace::Store.new(client) end