Class: SimpleJsonapi::Node::ObjectMeta
- Defined in:
- lib/simple_jsonapi/node/object_meta.rb
Overview
Represents a meta
object (a collection of meta members).
Instance Attribute Summary collapse
- #meta_definitions ⇒ Hash{Symbol => Definition::Meta} readonly
- #object ⇒ Object readonly
Attributes inherited from Base
#extras, #fields_spec, #include_spec, #root_node, #serializer, #serializer_inferrer, #sort_spec
Instance Method Summary collapse
- #as_jsonapi ⇒ Hash{Symbol => Hash}
-
#initialize(object:, meta_definitions:, **options) ⇒ ObjectMeta
constructor
A new instance of ObjectMeta.
Constructor Details
#initialize(object:, meta_definitions:, **options) ⇒ ObjectMeta
Returns a new instance of ObjectMeta.
14 15 16 17 18 19 |
# File 'lib/simple_jsonapi/node/object_meta.rb', line 14 def initialize(object:, meta_definitions:, **) super() @object = object @meta_definitions = || {} end |
Instance Attribute Details
#meta_definitions ⇒ Hash{Symbol => Definition::Meta} (readonly)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/simple_jsonapi/node/object_meta.rb', line 8 class ObjectMeta < Base attr_reader :object, :meta_definitions # @param object [Object] # @param meta_definitions [Hash{Symbol => Definition::Meta}] # @param options see {Node::Base#initialize} for additional parameters def initialize(object:, meta_definitions:, **) super() @object = object @meta_definitions = || {} end # @return [Hash{Symbol => Hash}] def as_jsonapi if .any? json = {} .each do |name, defn| json[name] = evaluate(defn.value_proc, object) end { meta: json } else {} end end private def @meta_definitions_to_render ||= @meta_definitions.select { |_, defn| render?(defn, object) } end end |
#object ⇒ Object (readonly)
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/simple_jsonapi/node/object_meta.rb', line 8 class ObjectMeta < Base attr_reader :object, :meta_definitions # @param object [Object] # @param meta_definitions [Hash{Symbol => Definition::Meta}] # @param options see {Node::Base#initialize} for additional parameters def initialize(object:, meta_definitions:, **) super() @object = object @meta_definitions = || {} end # @return [Hash{Symbol => Hash}] def as_jsonapi if .any? json = {} .each do |name, defn| json[name] = evaluate(defn.value_proc, object) end { meta: json } else {} end end private def @meta_definitions_to_render ||= @meta_definitions.select { |_, defn| render?(defn, object) } end end |
Instance Method Details
#as_jsonapi ⇒ Hash{Symbol => Hash}
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/simple_jsonapi/node/object_meta.rb', line 22 def as_jsonapi if .any? json = {} .each do |name, defn| json[name] = evaluate(defn.value_proc, object) end { meta: json } else {} end end |