Class: Camille::Rendered

Inherits:
Object
  • Object
show all
Defined in:
lib/camille/rendered.rb

Overview

A JSON string that has already passed a type check for the type identified by fingerprint. Any type will accept a Rendered with a matching fingerprint without re-checking it, and to_json splices the string verbatim, so a Rendered can be stored (e.g. in Rails.cache) and placed into a later response as an opaque, immutable fragment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fingerprint, json) ⇒ Rendered

Returns a new instance of Rendered.



10
11
12
13
# File 'lib/camille/rendered.rb', line 10

def initialize fingerprint, json
  @fingerprint = fingerprint
  @json = json
end

Instance Attribute Details

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



8
9
10
# File 'lib/camille/rendered.rb', line 8

def fingerprint
  @fingerprint
end

#jsonObject (readonly)

Returns the value of attribute json.



8
9
10
# File 'lib/camille/rendered.rb', line 8

def json
  @json
end

Instance Method Details

#marshal_dumpObject

Marshal (and therefore the default Rails.cache coder) stores only the two strings, so cached entries stay valid across changes to this class's internals.



22
23
24
# File 'lib/camille/rendered.rb', line 22

def marshal_dump
  [@fingerprint, @json]
end

#marshal_load(array) ⇒ Object



26
27
28
# File 'lib/camille/rendered.rb', line 26

def marshal_load array
  @fingerprint, @json = array
end

#to_json(options = nil) ⇒ Object



15
16
17
# File 'lib/camille/rendered.rb', line 15

def to_json options = nil
  @json
end