Class: Phronomy::ContentStore::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/content_store/base.rb

Direct Known Subclasses

Persistence::InMemory::Contents

Instance Method Summary collapse

Instance Method Details

#exist?(_content_id) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


12
# File 'lib/phronomy/content_store/base.rb', line 12

def exist?(_content_id) = raise(NotImplementedError)

#fetch(_content_id) ⇒ Object

Raises:

  • (NotImplementedError)


11
# File 'lib/phronomy/content_store/base.rb', line 11

def fetch(_content_id) = raise(NotImplementedError)

#fetch_json(content_id) ⇒ Object



36
37
38
# File 'lib/phronomy/content_store/base.rb', line 36

def fetch_json(content_id)
  Phronomy::CanonicalJSON.load(fetch(content_id))
end

#fetch_many(content_ids) ⇒ Object



40
41
42
# File 'lib/phronomy/content_store/base.rb', line 40

def fetch_many(content_ids)
  Array(content_ids).uniq.to_h { |content_id| [content_id, fetch(content_id)] }
end

#fetch_text(content_id) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/phronomy/content_store/base.rb', line 28

def fetch_text(content_id)
  value = fetch(content_id).force_encoding(Encoding::UTF_8)
  unless value.valid_encoding?
    raise IntegrityError, "content is not UTF-8: #{content_id}"
  end
  value
end

#put(_bytes, canonicalization_version:) ⇒ Object

Raises:

  • (NotImplementedError)


10
# File 'lib/phronomy/content_store/base.rb', line 10

def put(_bytes, canonicalization_version:) = raise(NotImplementedError)

#put_json(value) ⇒ Object



21
22
23
24
25
26
# File 'lib/phronomy/content_store/base.rb', line 21

def put_json(value)
  put(
    Phronomy::CanonicalJSON.dump(value),
    canonicalization_version: Phronomy::CanonicalJSON::VERSION
  )
end

#put_text(text) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
# File 'lib/phronomy/content_store/base.rb', line 14

def put_text(text)
  value = String(text).encode(Encoding::UTF_8)
  raise ArgumentError, "invalid UTF-8 text" unless value.valid_encoding?

  put(value, canonicalization_version: 1)
end