Class: Graphiti::Renderer
Constant Summary collapse
- CONTENT_TYPE =
"application/vnd.api+json"
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#proxy ⇒ Object
readonly
Returns the value of attribute proxy.
Class Method Summary collapse
Instance Method Summary collapse
- #as_graphql ⇒ Object
- #as_json ⇒ Object
-
#initialize(proxy, options) ⇒ Renderer
constructor
A new instance of Renderer.
- #records ⇒ Object
- #to_graphql ⇒ Object
- #to_json ⇒ Object
- #to_jsonapi ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(proxy, options) ⇒ Renderer
Returns a new instance of Renderer.
7 8 9 10 |
# File 'lib/graphiti/renderer.rb', line 7 def initialize(proxy, ) @proxy = proxy @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/graphiti/renderer.rb', line 5 def @options end |
#proxy ⇒ Object (readonly)
Returns the value of attribute proxy.
5 6 7 |
# File 'lib/graphiti/renderer.rb', line 5 def proxy @proxy end |
Class Method Details
.graphql_renderer(proxy) ⇒ Object
50 51 52 53 |
# File 'lib/graphiti/renderer.rb', line 50 def self.graphql_renderer(proxy) implementation = Graphiti::HashRenderer.new(proxy.resource, graphql: true) JSONAPI::Serializable::Renderer.new(implementation) end |
.hash_renderer(proxy) ⇒ Object
45 46 47 48 |
# File 'lib/graphiti/renderer.rb', line 45 def self.hash_renderer(proxy) implementation = Graphiti::HashRenderer.new(proxy.resource) JSONAPI::Serializable::Renderer.new(implementation) end |
.jsonapi_renderer ⇒ Object
40 41 42 43 |
# File 'lib/graphiti/renderer.rb', line 40 def self.jsonapi_renderer @jsonapi_renderer ||= JSONAPI::Serializable::Renderer .new(JSONAPI::Renderer.new) end |
Instance Method Details
#as_graphql ⇒ Object
20 21 22 |
# File 'lib/graphiti/renderer.rb', line 20 def as_graphql render(self.class.graphql_renderer(@proxy)) end |
#as_json ⇒ Object
32 33 34 |
# File 'lib/graphiti/renderer.rb', line 32 def as_json render(self.class.hash_renderer(@proxy)) end |
#records ⇒ Object
12 13 14 |
# File 'lib/graphiti/renderer.rb', line 12 def records @records ||= @proxy.data end |
#to_graphql ⇒ Object
24 25 26 |
# File 'lib/graphiti/renderer.rb', line 24 def to_graphql as_graphql.to_json end |
#to_json ⇒ Object
28 29 30 |
# File 'lib/graphiti/renderer.rb', line 28 def to_json as_json.to_json end |
#to_jsonapi ⇒ Object
16 17 18 |
# File 'lib/graphiti/renderer.rb', line 16 def to_jsonapi render(self.class.jsonapi_renderer).to_json end |
#to_xml ⇒ Object
36 37 38 |
# File 'lib/graphiti/renderer.rb', line 36 def to_xml render(self.class.hash_renderer(@proxy)).to_xml(root: :data) end |