diff --git a/ActionController.html b/ActionController.html new file mode 100644 index 00000000..a7dcd038 --- /dev/null +++ b/ActionController.html @@ -0,0 +1,115 @@ + + + + + + Module: ActionController + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActionController + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/action_controller/serialization.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: Serialization + + + + +

+ + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActionController/Serialization.html b/ActionController/Serialization.html new file mode 100644 index 00000000..a4767e60 --- /dev/null +++ b/ActionController/Serialization.html @@ -0,0 +1,348 @@ + + + + + + Module: ActionController::Serialization + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActionController::Serialization + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + +
Includes:
+
Renderers
+ + + + + +
Defined in:
+
lib/action_controller/serialization.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: ClassMethods + + + + +

+ + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) get_serializer(resource, options = {}) + + + + + +

+ + + + +
+
+
+
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+
+
# File 'lib/action_controller/serialization.rb', line 26
+
+def get_serializer(resource, options = {})
+  if !use_adapter?
+    warn 'ActionController::Serialization#use_adapter? has been removed. '\
+      "Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
+    options[:adapter] = false
+  end
+  serializable_resource = ActiveModelSerializers::SerializableResource.new(resource, options)
+  serializable_resource.serialization_scope ||= options.fetch(:scope) { serialization_scope }
+  serializable_resource.serialization_scope_name = options.fetch(:scope_name) { _serialization_scope }
+  # For compatibility with the JSON renderer: `json.to_json(options) if json.is_a?(String)`.
+  # Otherwise, since `serializable_resource` is not a string, the renderer would call
+  # `to_json` on a String and given odd results, such as `"".to_json #=> '""'`
+  serializable_resource.adapter.is_a?(String) ? serializable_resource.adapter : serializable_resource
+end
+
+
+ +
+

+ + - (Object) serialization_scope + + + + + +

+ + + + +
+
+
+
+21
+22
+23
+24
+
+
# File 'lib/action_controller/serialization.rb', line 21
+
+def serialization_scope
+  send(_serialization_scope) if _serialization_scope &&
+    respond_to?(_serialization_scope, true)
+end
+
+
+ +
+

+ + - (Boolean) use_adapter? + + + + + +

+
+ +

Deprecated

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+42
+43
+44
+
+
# File 'lib/action_controller/serialization.rb', line 42
+
+def use_adapter?
+  true
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActionController/Serialization/ClassMethods.html b/ActionController/Serialization/ClassMethods.html new file mode 100644 index 00000000..e3dce043 --- /dev/null +++ b/ActionController/Serialization/ClassMethods.html @@ -0,0 +1,174 @@ + + + + + + Module: ActionController::Serialization::ClassMethods + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActionController::Serialization::ClassMethods + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/action_controller/serialization.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) serialization_scope(scope) + + + + + +

+ + + + +
+
+
+
+11
+12
+13
+
+
# File 'lib/action_controller/serialization.rb', line 11
+
+def serialization_scope(scope)
+  self._serialization_scope = scope
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel.html b/ActiveModel.html new file mode 100644 index 00000000..1f265b39 --- /dev/null +++ b/ActiveModel.html @@ -0,0 +1,129 @@ + + + + + + Module: ActiveModel + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model/serializer.rb,
+ lib/active_model/serializer/meta.rb,
lib/active_model/serializer/type.rb,
lib/active_model/serializer/null.rb,
lib/active_model/serializer/field.rb,
lib/active_model/serializer/links.rb,
lib/active_model/serializer/adapter.rb,
lib/active_model/serializer/version.rb,
lib/active_model/serializer/caching.rb,
lib/active_model/serializer/fieldset.rb,
lib/active_model/serializer/attribute.rb,
lib/active_model/serializable_resource.rb,
lib/active_model/serializer/reflection.rb,
lib/active_model/serializer/attributes.rb,
lib/active_model/serializer/association.rb,
lib/active_model/serializer/adapter/json.rb,
lib/active_model/serializer/adapter/null.rb,
lib/active_model/serializer/adapter/base.rb,
lib/active_model/serializer/associations.rb,
lib/active_model/serializer/configuration.rb,
lib/active_model/serializer/adapter/json_api.rb,
lib/active_model/serializer/adapter/attributes.rb,
lib/active_model/serializer/has_one_reflection.rb,
lib/active_model/serializer/singular_reflection.rb,
lib/active_model/serializer/has_many_reflection.rb,
lib/active_model/serializer/collection_reflection.rb,
lib/active_model/serializer/belongs_to_reflection.rb,
lib/active_model/serializer/collection_serializer.rb
+
+ +
+
+ +

Overview

+
+ +

ActiveModel::Serializer is an abstract class that is reified when +subclassed to decorate a resource.

+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + + + Classes: SerializableResource, Serializer + + +

+ + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/SerializableResource.html b/ActiveModel/SerializableResource.html new file mode 100644 index 00000000..9039e956 --- /dev/null +++ b/ActiveModel/SerializableResource.html @@ -0,0 +1,135 @@ + + + + + + Class: ActiveModel::SerializableResource + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::SerializableResource + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + +
Extended by:
+
ActiveModelSerializers::Deprecate
+ + + + + + + +
Defined in:
+
lib/active_model/serializable_resource.rb
+ +
+
+ + + + + + + + + + + + + + + +

Method Summary

+ +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer.html b/ActiveModel/Serializer.html new file mode 100644 index 00000000..df16f761 --- /dev/null +++ b/ActiveModel/Serializer.html @@ -0,0 +1,1764 @@ + + + + + + Class: ActiveModel::Serializer + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + +
Extended by:
+
ActiveModelSerializers::Deprecate, ActiveSupport::Autoload
+ + + + +
Includes:
+
Associations, Attributes, Caching, Configuration, Links, Meta, Type
+ + + + + +
Defined in:
+
lib/active_model/serializer.rb,
+ lib/active_model/serializer/meta.rb,
lib/active_model/serializer/type.rb,
lib/active_model/serializer/null.rb,
lib/active_model/serializer/field.rb,
lib/active_model/serializer/links.rb,
lib/active_model/serializer/adapter.rb,
lib/active_model/serializer/version.rb,
lib/active_model/serializer/caching.rb,
lib/active_model/serializer/fieldset.rb,
lib/active_model/serializer/attribute.rb,
lib/active_model/serializer/reflection.rb,
lib/active_model/serializer/attributes.rb,
lib/active_model/serializer/association.rb,
lib/active_model/serializer/adapter/json.rb,
lib/active_model/serializer/adapter/null.rb,
lib/active_model/serializer/adapter/base.rb,
lib/active_model/serializer/associations.rb,
lib/active_model/serializer/configuration.rb,
lib/active_model/serializer/adapter/json_api.rb,
lib/active_model/serializer/array_serializer.rb,
lib/active_model/serializer/adapter/attributes.rb,
lib/active_model/serializer/has_one_reflection.rb,
lib/active_model/serializer/singular_reflection.rb,
lib/active_model/serializer/has_many_reflection.rb,
lib/active_model/serializer/collection_reflection.rb,
lib/active_model/serializer/belongs_to_reflection.rb,
lib/active_model/serializer/collection_serializer.rb
+
+ +
+
+ +
+

Direct Known Subclasses

+

ErrorSerializer, Null

+
+

Defined Under Namespace

+

+ + + Modules: Adapter, Associations, Attributes, Caching, Configuration, Links, Lint, Meta, Type + + + + Classes: ArraySerializer, Association, Attribute, BelongsToReflection, CollectionReflection, CollectionSerializer, ErrorSerializer, ErrorsSerializer, Field, Fieldset, HasManyReflection, HasOneReflection, Null, Reflection, SingularReflection + + +

+ +

Constant Summary

+ +
+ +
SERIALIZABLE_HASH_VALID_KEYS = +
+
+ + +
+
+
+ + +

See Also:

+ + +
+
+
[:only, :except, :methods, :include, :root].freeze
+ +
VERSION = + +
+
'0.10.0'.freeze
+ +
UndefinedCacheKey = + +
+
Class.new(StandardError)
+ +
+ + + + + + +

Constants included + from Caching

+

Caching::CALLER_FILE

+ + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Class Method Summary + (collapse) +

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Methods included from Caching

+

#cache_key, #fetch, #fetch_attributes, #fetch_attributes_fragment, #object_cache_key, #serializer_class

+ + + + + + + + + + + + + + + + + +

Methods included from Associations

+

#associations

+ + + + + + + + + +
+

Constructor Details

+ +
+

+ + - (Serializer) initialize(object, options = {}) + + + + + +

+
+ +

`scope_name` is set as :current_user by default in the controller. If the +instance does not have a method named `scope_name`, it defines the method +so that it calls the scope.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+
+
# File 'lib/active_model/serializer.rb', line 122
+
+def initialize(object, options = {})
+  self.object = object
+  self.instance_options = options
+  self.root = instance_options[:root]
+  self.scope = instance_options[:scope]
+
+  scope_name = instance_options[:scope_name]
+  if scope_name && !respond_to?(scope_name)
+    define_singleton_method scope_name, lambda { scope }
+  end
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) object + + + + + +

+
+ +

Returns the value of attribute object

+ + +
+
+
+ + +
+ + + + +
+
+
+
+117
+118
+119
+
+
# File 'lib/active_model/serializer.rb', line 117
+
+def object
+  @object
+end
+
+
+ + + +
+

+ + - (Object) root + + + + + +

+
+ +

Returns the value of attribute root

+ + +
+
+
+ + +
+ + + + +
+
+
+
+117
+118
+119
+
+
# File 'lib/active_model/serializer.rb', line 117
+
+def root
+  @root
+end
+
+
+ + + +
+

+ + - (Object) scope + + + + + +

+
+ +

Returns the value of attribute scope

+ + +
+
+
+ + +
+ + + + +
+
+
+
+117
+118
+119
+
+
# File 'lib/active_model/serializer.rb', line 117
+
+def scope
+  @scope
+end
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + + (Object) adapter + + + + + +

+
+ +

Deprecated

+ + +
+
+
+ + +

See Also:

+ + +
+ + + + +
+
+
+
+53
+54
+55
+
+
# File 'lib/active_model/serializer.rb', line 53
+
+def self.adapter
+  ActiveModelSerializers::Adapter.lookup(config.adapter)
+end
+
+
+ +
+

+ + + (Object) get_serializer_for(klass) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ +

Find a serializer from a class and caches the lookup. Preferentially +returns:

+ +
1. class name appended with "Serializer"
+2. try again with superclass, if present
+3. nil
+ + +
+
+
+ + +
+ + + + +
+
+
+
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+
+
# File 'lib/active_model/serializer.rb', line 87
+
+def self.get_serializer_for(klass)
+  return nil unless config.serializer_lookup_enabled
+  serializers_cache.fetch_or_store(klass) do
+    # NOTE(beauby): When we drop 1.9.3 support we can lazify the map for perfs.
+    serializer_class = serializer_lookup_chain_for(klass).map(&:safe_constantize).find { |x| x && x < ActiveModel::Serializer }
+
+    if serializer_class
+      serializer_class
+    elsif klass.superclass
+      get_serializer_for(klass.superclass)
+    end
+  end
+end
+
+
+ +
+

+ + + (Object) include_directive_from_options(options) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+102
+103
+104
+105
+106
+107
+108
+109
+110
+
+
# File 'lib/active_model/serializer.rb', line 102
+
+def self.include_directive_from_options(options)
+  if options[:include_directive]
+    options[:include_directive]
+  elsif options[:include]
+    JSONAPI::IncludeDirective.new(options[:include], allow_wildcard: true)
+  else
+    ActiveModelSerializers.default_include_directive
+  end
+end
+
+
+ +
+

+ + + (Object) serialization_adapter_instance + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+113
+114
+115
+
+
# File 'lib/active_model/serializer.rb', line 113
+
+def self.serialization_adapter_instance
+  @serialization_adapter_instance ||= ActiveModelSerializers::Adapter::Attributes
+end
+
+
+ +
+

+ + + (ActiveModel::Serializer) serializer_for(resource, options = {}) + + + + + +

+
+ +

Returns Preferentially returns

+
  1. +

    resource.serializer

    +
  2. +

    ArraySerializer when resource is a collection

    +
  3. +

    options

    +
  4. +

    lookup serializer when resource is a Class

    +
+ + +
+
+
+

Parameters:

+ + +

Returns:

+
    + +
  • + + + (ActiveModel::Serializer) + + + + — +
    +

    Preferentially returns

    +
    1. +

      resource.serializer

      +
    2. +

      ArraySerializer when resource is a collection

      +
    3. +

      options

      +
    4. +

      lookup serializer when resource is a Class

      +
    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+41
+42
+43
+44
+45
+46
+47
+48
+49
+
+
# File 'lib/active_model/serializer.rb', line 41
+
+def self.serializer_for(resource, options = {})
+  if resource.respond_to?(:serializer_class)
+    resource.serializer_class
+  elsif resource.respond_to?(:to_ary)
+    config.collection_serializer
+  else
+    options.fetch(:serializer) { get_serializer_for(resource.class) }
+  end
+end
+
+
+ +
+

+ + + (Object) serializer_lookup_chain_for(klass) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+
+
# File 'lib/active_model/serializer.rb', line 62
+
+def self.serializer_lookup_chain_for(klass)
+  chain = []
+
+  resource_class_name = klass.name.demodulize
+  resource_namespace = klass.name.deconstantize
+  serializer_class_name = "#{resource_class_name}Serializer"
+
+  chain.push("#{name}::#{serializer_class_name}") if self != ActiveModel::Serializer
+  chain.push("#{resource_namespace}::#{serializer_class_name}")
+
+  chain
+end
+
+
+ +
+

+ + + (Object) serializers_cache + + + + + +

+
+ +

Used to cache serializer name => serializer class when looked up by +Serializer.get_serializer_for.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+77
+78
+79
+
+
# File 'lib/active_model/serializer.rb', line 77
+
+def self.serializers_cache
+  @serializers_cache ||= ThreadSafe::Cache.new
+end
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + - (Object) as_json(adapter_opts = nil) + + + + + +

+
+ +

TODO: When moving attributes adapter logic here, @see #serializable_hash So +that the below is true:

+ +
@param options [nil, Hash] The same valid options passed to `as_json`
+   (:root, :only, :except, :methods, and :include).
+The default for `root` is nil.
+The default value for include_root is false. You can change it to true if the given
+JSON string includes a single root node.
+ + +
+
+
+ + +

See Also:

+ + +
+ + + + +
+
+
+
+185
+186
+187
+
+
# File 'lib/active_model/serializer.rb', line 185
+
+def as_json(adapter_opts = nil)
+  serializable_hash(adapter_opts)
+end
+
+
+ +
+

+ + - (Object) json_key + + + + + +

+
+ +

Used by adapter as resource root.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+190
+191
+192
+
+
# File 'lib/active_model/serializer.rb', line 190
+
+def json_key
+  root || _type || object.class.model_name.to_s.underscore
+end
+
+
+ +
+

+ + - (Object) read_attribute_for_serialization(attr) + + + + + +

+ + + + +
+
+
+
+194
+195
+196
+197
+198
+199
+200
+
+
# File 'lib/active_model/serializer.rb', line 194
+
+def read_attribute_for_serialization(attr)
+  if respond_to?(attr)
+    send(attr)
+  else
+    object.read_attribute_for_serialization(attr)
+  end
+end
+
+
+ +
+

+ + - (Object) relationship_value_for(association, adapter_options, adapter_instance) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+
+
# File 'lib/active_model/serializer.rb', line 215
+
+def relationship_value_for(association, adapter_options, adapter_instance)
+  return association.options[:virtual_value] if association.options[:virtual_value]
+  association_serializer = association.serializer
+  association_object = association_serializer && association_serializer.object
+  return unless association_object
+
+  relationship_value = association_serializer.serializable_hash(adapter_options, {}, adapter_instance)
+
+  if association.options[:polymorphic] && relationship_value
+    polymorphic_type = association_object.class.name.underscore
+    relationship_value = { type: polymorphic_type, polymorphic_type.to_sym => relationship_value }
+  end
+
+  relationship_value
+end
+
+
+ +
+

+ + - (Object) resource_relationships(adapter_options, options, adapter_instance) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+
+
# File 'lib/active_model/serializer.rb', line 203
+
+def resource_relationships(adapter_options, options, adapter_instance)
+  relationships = {}
+  include_directive = options.fetch(:include_directive)
+  associations(include_directive).each do |association|
+    adapter_opts = adapter_options.merge(include_directive: include_directive[association.key])
+    relationships[association.key] ||= relationship_value_for(association, adapter_opts, adapter_instance)
+  end
+
+  relationships
+end
+
+
+ +
+

+ + - (Hash) serializable_hash(adapter_options = nil, options = {}, adapter_instance = self.class.serialization_adapter_instance) + + + + Also known as: + to_hash, to_h + + + + +

+
+ +

associations, similar to how ActiveModel::Serializers::JSON is used in +ActiveRecord::Base.

+ +

TODO: Include ActiveModel::Serializers::JSON. So that the +below is true:

+ +
@param options [nil, Hash] The same valid options passed to `serializable_hash`
+   (:only, :except, :methods, and :include).
+
+  See
+  https://github.com/rails/rails/blob/v5.0.0.beta2/activemodel/lib/active_model/serializers/json.rb#L17-L101
+  https://github.com/rails/rails/blob/v5.0.0.beta2/activemodel/lib/active_model/serialization.rb#L85-L123
+  https://github.com/rails/rails/blob/v5.0.0.beta2/activerecord/lib/active_record/serialization.rb#L11-L17
+  https://github.com/rails/rails/blob/v5.0.0.beta2/activesupport/lib/active_support/core_ext/object/json.rb#L147-L162
+
+@example
+  # The :only and :except options can be used to limit the attributes included, and work
+  # similar to the attributes method.
+  serializer.as_json(only: [:id, :name])
+  serializer.as_json(except: [:id, :created_at, :age])
+
+  # To include the result of some method calls on the model use :methods:
+  serializer.as_json(methods: :permalink)
+
+  # To include associations use :include:
+  serializer.as_json(include: :posts)
+  # Second level and higher order associations work as well:
+  serializer.as_json(include: { posts: { include: { comments: { only: :body } }, only: :title } })
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash) + + + + — +
    +

    containing the attributes and first level

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+166
+167
+168
+169
+170
+171
+172
+173
+
+
# File 'lib/active_model/serializer.rb', line 166
+
+def serializable_hash(adapter_options = nil, options = {}, adapter_instance = self.class.serialization_adapter_instance)
+  adapter_options ||= {}
+  options[:include_directive] ||= ActiveModel::Serializer.include_directive_from_options(adapter_options)
+  cached_attributes = adapter_options[:cached_attributes] ||= {}
+  resource = fetch_attributes(options[:fields], cached_attributes, adapter_instance)
+  relationships = resource_relationships(adapter_options, options, adapter_instance)
+  resource.merge(relationships)
+end
+
+
+ +
+

+ + - (Boolean) success? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+134
+135
+136
+
+
# File 'lib/active_model/serializer.rb', line 134
+
+def success?
+  true
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Adapter.html b/ActiveModel/Serializer/Adapter.html new file mode 100644 index 00000000..2b7f099a --- /dev/null +++ b/ActiveModel/Serializer/Adapter.html @@ -0,0 +1,156 @@ + + + + + + Module: ActiveModel::Serializer::Adapter + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Adapter + + Deprecated + +

+ +
+ + + +
Extended by:
+
ActiveModelSerializers::Deprecate
+ + + + + + + +
Defined in:
+
lib/active_model/serializer/adapter.rb,
+ lib/active_model/serializer/adapter/json.rb,
lib/active_model/serializer/adapter/null.rb,
lib/active_model/serializer/adapter/base.rb,
lib/active_model/serializer/adapter/json_api.rb,
lib/active_model/serializer/adapter/attributes.rb
+
+ +
+
+ +

Overview

+
+
Deprecated.
+

Use ActiveModelSerializers::Adapter instead

+
+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + + + Classes: Attributes, Base, Json, JsonApi, Null + + +

+ +

Constant Summary

+ +
+ +
DEPRECATED_METHODS = + +
+
[:create, :adapter_class, :adapter_map, :adapters, :register, :lookup].freeze
+ +
+ + + + + + + + + + + + + + + +

Method Summary

+ +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Adapter/Attributes.html b/ActiveModel/Serializer/Adapter/Attributes.html new file mode 100644 index 00000000..2bbf2cb5 --- /dev/null +++ b/ActiveModel/Serializer/Adapter/Attributes.html @@ -0,0 +1,248 @@ + + + + + + Class: ActiveModel::Serializer::Adapter::Attributes + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Adapter::Attributes + + + +

+ +
+ +
Inherits:
+
+ ActiveModelSerializers::Adapter::Attributes + + + show all + +
+ + + + +
Extended by:
+
ActiveModelSerializers::Deprecate
+ + + + + + + +
Defined in:
+
lib/active_model/serializer/adapter/attributes.rb
+ +
+
+ + + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from ActiveModelSerializers::Adapter::Base

+

#instance_options, #serializer

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + + + + + + + + +

Methods inherited from ActiveModelSerializers::Adapter::Attributes

+

#serializable_hash

+ + + + + + + + + +

Methods inherited from ActiveModelSerializers::Adapter::Base

+

#as_json, cache_key, #cache_key, default_key_transform, #fragment_cache, fragment_cache, inherited, #serializable_hash, transform, transform_key_casing!

+
+

Constructor Details

+ +
+

+ + - (Attributes) initialize(serializer, options = {}) + + + + + +

+
+ +

Returns a new instance of Attributes

+ + +
+
+
+ + +
+ + + + +
+
+
+
+5
+6
+7
+
+
# File 'lib/active_model/serializer/adapter/attributes.rb', line 5
+
+def initialize(serializer, options = {})
+  super(ActiveModelSerializers::Adapter::Attributes.new(serializer, options))
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Adapter/Base.html b/ActiveModel/Serializer/Adapter/Base.html new file mode 100644 index 00000000..c2001f31 --- /dev/null +++ b/ActiveModel/Serializer/Adapter/Base.html @@ -0,0 +1,235 @@ + + + + + + Class: ActiveModel::Serializer::Adapter::Base + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Adapter::Base + + + +

+ +
+ +
Inherits:
+
+ ActiveModelSerializers::Adapter::Base + + + show all + +
+ + + + +
Extended by:
+
ActiveModelSerializers::Deprecate
+ + + + + + + +
Defined in:
+
lib/active_model/serializer/adapter/base.rb
+ +
+
+ + + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from ActiveModelSerializers::Adapter::Base

+

#instance_options, #serializer

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + + + + + + + + +

Methods inherited from ActiveModelSerializers::Adapter::Base

+

#as_json, cache_key, #cache_key, default_key_transform, #fragment_cache, fragment_cache, inherited, #serializable_hash, transform, transform_key_casing!

+
+

Constructor Details

+ +
+

+ + - (Base) initialize(serializer, options = {}) + + + + + +

+
+ +

:nocov:

+ + +
+
+
+ + +
+ + + + +
+
+
+
+11
+12
+13
+
+
# File 'lib/active_model/serializer/adapter/base.rb', line 11
+
+def initialize(serializer, options = {})
+  super(ActiveModelSerializers::Adapter::Base.new(serializer, options))
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Adapter/Json.html b/ActiveModel/Serializer/Adapter/Json.html new file mode 100644 index 00000000..9af69a73 --- /dev/null +++ b/ActiveModel/Serializer/Adapter/Json.html @@ -0,0 +1,248 @@ + + + + + + Class: ActiveModel::Serializer::Adapter::Json + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Adapter::Json + + + +

+ +
+ +
Inherits:
+
+ ActiveModelSerializers::Adapter::Json + + + show all + +
+ + + + +
Extended by:
+
ActiveModelSerializers::Deprecate
+ + + + + + + +
Defined in:
+
lib/active_model/serializer/adapter/json.rb
+ +
+
+ + + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from ActiveModelSerializers::Adapter::Base

+

#instance_options, #serializer

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + + + + + + + + +

Methods inherited from ActiveModelSerializers::Adapter::Json

+

#meta, #meta_key, #serializable_hash

+ + + + + + + + + +

Methods inherited from ActiveModelSerializers::Adapter::Base

+

#as_json, cache_key, #cache_key, default_key_transform, #fragment_cache, fragment_cache, inherited, #serializable_hash, transform, transform_key_casing!

+
+

Constructor Details

+ +
+

+ + - (Json) initialize(serializer, options = {}) + + + + + +

+
+ +

Returns a new instance of Json

+ + +
+
+
+ + +
+ + + + +
+
+
+
+5
+6
+7
+
+
# File 'lib/active_model/serializer/adapter/json.rb', line 5
+
+def initialize(serializer, options = {})
+  super(ActiveModelSerializers::Adapter::Json.new(serializer, options))
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Adapter/JsonApi.html b/ActiveModel/Serializer/Adapter/JsonApi.html new file mode 100644 index 00000000..af6c5ed6 --- /dev/null +++ b/ActiveModel/Serializer/Adapter/JsonApi.html @@ -0,0 +1,249 @@ + + + + + + Class: ActiveModel::Serializer::Adapter::JsonApi + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Adapter::JsonApi + + + +

+ +
+ +
Inherits:
+
+ ActiveModelSerializers::Adapter::JsonApi + + + show all + +
+ + + + +
Extended by:
+
ActiveModelSerializers::Deprecate
+ + + + + + + +
Defined in:
+
lib/active_model/serializer/adapter/json_api.rb
+ +
+
+ + + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from ActiveModelSerializers::Adapter::Base

+

#instance_options, #serializer

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + + + + + + + + +

Methods inherited from ActiveModelSerializers::Adapter::JsonApi

+

default_key_transform, #failure_document, #fragment_cache, fragment_cache, #serializable_hash, #success_document

+ + + + + + + + + + +

Methods inherited from ActiveModelSerializers::Adapter::Base

+

#as_json, cache_key, #cache_key, default_key_transform, #fragment_cache, fragment_cache, inherited, #serializable_hash, transform, transform_key_casing!

+
+

Constructor Details

+ +
+

+ + - (JsonApi) initialize(serializer, options = {}) + + + + + +

+
+ +

Returns a new instance of JsonApi

+ + +
+
+
+ + +
+ + + + +
+
+
+
+5
+6
+7
+
+
# File 'lib/active_model/serializer/adapter/json_api.rb', line 5
+
+def initialize(serializer, options = {})
+  super(ActiveModelSerializers::Adapter::JsonApi.new(serializer, options))
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Adapter/Null.html b/ActiveModel/Serializer/Adapter/Null.html new file mode 100644 index 00000000..875f019a --- /dev/null +++ b/ActiveModel/Serializer/Adapter/Null.html @@ -0,0 +1,248 @@ + + + + + + Class: ActiveModel::Serializer::Adapter::Null + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Adapter::Null + + + +

+ +
+ +
Inherits:
+
+ ActiveModelSerializers::Adapter::Null + + + show all + +
+ + + + +
Extended by:
+
ActiveModelSerializers::Deprecate
+ + + + + + + +
Defined in:
+
lib/active_model/serializer/adapter/null.rb
+ +
+
+ + + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from ActiveModelSerializers::Adapter::Base

+

#instance_options, #serializer

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + + + + + + + + +

Methods inherited from ActiveModelSerializers::Adapter::Null

+

#serializable_hash

+ + + + + + + + + +

Methods inherited from ActiveModelSerializers::Adapter::Base

+

#as_json, cache_key, #cache_key, default_key_transform, #fragment_cache, fragment_cache, inherited, #serializable_hash, transform, transform_key_casing!

+
+

Constructor Details

+ +
+

+ + - (Null) initialize(serializer, options = {}) + + + + + +

+
+ +

Returns a new instance of Null

+ + +
+
+
+ + +
+ + + + +
+
+
+
+5
+6
+7
+
+
# File 'lib/active_model/serializer/adapter/null.rb', line 5
+
+def initialize(serializer, options = {})
+  super(ActiveModelSerializers::Adapter::Null.new(serializer, options))
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/ArraySerializer.html b/ActiveModel/Serializer/ArraySerializer.html new file mode 100644 index 00000000..5e680164 --- /dev/null +++ b/ActiveModel/Serializer/ArraySerializer.html @@ -0,0 +1,169 @@ + + + + + + Class: ActiveModel::Serializer::ArraySerializer + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::ArraySerializer + + + +

+ +
+ +
Inherits:
+
+ CollectionSerializer + + + show all + +
+ + + + +
Extended by:
+
ActiveModelSerializers::Deprecate
+ + + + + + + +
Defined in:
+
lib/active_model/serializer/array_serializer.rb
+ +
+
+ + +

Constant Summary

+ + + + +

Constant Summary

+ +

Constants inherited + from CollectionSerializer

+

CollectionSerializer::NoSerializerError

+ + + + +

Instance Attribute Summary

+ +

Attributes inherited from CollectionSerializer

+

#object, #root

+ + + + + + + + + +

Method Summary

+ +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + + + + + + + + +

Methods inherited from CollectionSerializer

+

#initialize, #json_key, #paginated?, #serializable_hash, #success?

+ +
+

Constructor Details

+ +

This class inherits a constructor from ActiveModel::Serializer::CollectionSerializer

+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Association.html b/ActiveModel/Serializer/Association.html new file mode 100644 index 00000000..fc5f3461 --- /dev/null +++ b/ActiveModel/Serializer/Association.html @@ -0,0 +1,592 @@ + + + + + + Class: ActiveModel::Serializer::Association + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Association + + + +

+ +
+ +
Inherits:
+
+ Struct + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/association.rb
+ +
+
+ +

Overview

+
+ +

This class hold all information about serializer's association.

+ + +
+
+
+ +
+

Examples:

+ + +
Association.new(:comments, CommentSummarySerializer)
+ +
+ + +
+ + + +

Instance Attribute Summary (collapse)

+ + + + + + + +
+

Instance Attribute Details

+ + + +
+
+
+ +

Returns the value of attribute links

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Object) + + + + — +
    +

    the current value of links

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/active_model/serializer/association.rb', line 12
+
+def links
+  @links
+end
+
+
+ + + +
+

+ + - (Object) meta + + + + + +

+
+ +

Returns the value of attribute meta

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Object) + + + + — +
    +

    the current value of meta

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/active_model/serializer/association.rb', line 12
+
+def meta
+  @meta
+end
+
+
+ + + +
+

+ + - (Symbol) name + + + + + +

+
+ +

Returns the current value of name

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Symbol) + + + + — +
    +

    the current value of name

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/active_model/serializer/association.rb', line 12
+
+def name
+  @name
+end
+
+
+ + + +
+

+ + - (Hash{Symbol => Object}) options + + + + + +

+
+ +

Returns the current value of options

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash{Symbol => Object}) + + + + — +
    +

    the current value of options

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/active_model/serializer/association.rb', line 12
+
+def options
+  @options
+end
+
+
+ + + +
+

+ + - (ActiveModel::Serializer) serializer + + + + + +

+
+ +

Returns the current value of serializer

+ + +
+
+
+ +

Returns:

+ + +
+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/active_model/serializer/association.rb', line 12
+
+def serializer
+  @serializer
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Associations.html b/ActiveModel/Serializer/Associations.html new file mode 100644 index 00000000..abda16ca --- /dev/null +++ b/ActiveModel/Serializer/Associations.html @@ -0,0 +1,272 @@ + + + + + + Module: ActiveModel::Serializer::Associations + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Associations + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + + + +
Included in:
+
ActiveModel::Serializer
+ + + +
Defined in:
+
lib/active_model/serializer/associations.rb
+ +
+
+ +

Overview

+
+ +

Defines an association in the object should be rendered.

+ +

The serializer object should implement the association name as a method +which should return an array when invoked. If a method with the association +name does not exist, the association name is dispatched to the serialized +object.

+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + Modules: ClassMethods + + + + +

+ + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Enumerator<Association>) associations(include_directive = ActiveModelSerializers.default_include_directive) + + + + + +

+
+ + +
+
+
+

Parameters:

+
    + +
  • + + include_directive + + + (JSONAPI::IncludeDirective) + + + (defaults to: ActiveModelSerializers.default_include_directive) + + + — +
    +

    (defaults to the default_include_directive config value when +not provided)

    +
    + +
  • + +
+ +

Returns:

+ + +
+ + + + +
+
+
+
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+
+
# File 'lib/active_model/serializer/associations.rb', line 85
+
+def associations(include_directive = ActiveModelSerializers.default_include_directive)
+  return unless object
+
+  Enumerator.new do |y|
+    self.class._reflections.each do |reflection|
+      next if reflection.excluded?(self)
+      key = reflection.options.fetch(:key, reflection.name)
+      next unless include_directive.key?(key)
+      y.yield reflection.build_association(self, instance_options)
+    end
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Associations/ClassMethods.html b/ActiveModel/Serializer/Associations/ClassMethods.html new file mode 100644 index 00000000..def9bef6 --- /dev/null +++ b/ActiveModel/Serializer/Associations/ClassMethods.html @@ -0,0 +1,497 @@ + + + + + + Module: ActiveModel::Serializer::Associations::ClassMethods + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Associations::ClassMethods + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model/serializer/associations.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (void) belongs_to(name, options = {}, &block) + + + + + +

+
+

This method returns an undefined value.

+ +
+
+
+ +
+

Examples:

+ + +
belongs_to :author, serializer: AuthorSerializer
+ +
+

Parameters:

+
    + +
  • + + name + + + (Symbol) + + + + — +
    +

    of the association

    +
    + +
  • + +
  • + + options + + + (Hash<Symbol => any>) + + + (defaults to: {}) + + + — +
    +

    for the reflection

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+53
+54
+55
+
+
# File 'lib/active_model/serializer/associations.rb', line 53
+
+def belongs_to(name, options = {}, &block)
+  associate(BelongsToReflection.new(name, options, block))
+end
+
+
+ +
+

+ + - (void) has_many(name, options = {}, &block) + + + + + +

+
+

This method returns an undefined value.

+ +
+
+
+ +
+

Examples:

+ + +
has_many :comments, serializer: CommentSummarySerializer
+ +
+

Parameters:

+
    + +
  • + + name + + + (Symbol) + + + + — +
    +

    of the association

    +
    + +
  • + +
  • + + options + + + (Hash<Symbol => any>) + + + (defaults to: {}) + + + — +
    +

    for the reflection

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+42
+43
+44
+
+
# File 'lib/active_model/serializer/associations.rb', line 42
+
+def has_many(name, options = {}, &block)
+  associate(HasManyReflection.new(name, options, block))
+end
+
+
+ +
+

+ + - (void) has_one(name, options = {}, &block) + + + + + +

+
+

This method returns an undefined value.

+ +
+
+
+ +
+

Examples:

+ + +
has_one :author, serializer: AuthorSerializer
+ +
+

Parameters:

+
    + +
  • + + name + + + (Symbol) + + + + — +
    +

    of the association

    +
    + +
  • + +
  • + + options + + + (Hash<Symbol => any>) + + + (defaults to: {}) + + + — +
    +

    for the reflection

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+64
+65
+66
+
+
# File 'lib/active_model/serializer/associations.rb', line 64
+
+def has_one(name, options = {}, &block)
+  associate(HasOneReflection.new(name, options, block))
+end
+
+
+ +
+

+ + - (Object) inherited(base) + + + + + +

+ + + + +
+
+
+
+30
+31
+32
+33
+
+
# File 'lib/active_model/serializer/associations.rb', line 30
+
+def inherited(base)
+  super
+  base._reflections = _reflections.dup
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Attribute.html b/ActiveModel/Serializer/Attribute.html new file mode 100644 index 00000000..0a597d94 --- /dev/null +++ b/ActiveModel/Serializer/Attribute.html @@ -0,0 +1,167 @@ + + + + + + Class: ActiveModel::Serializer::Attribute + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Attribute + + + +

+ +
+ +
Inherits:
+
+ Field + +
    +
  • Object
  • + + + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/attribute.rb
+ +
+
+ +

Overview

+
+ +

Holds all the meta-data about an attribute as it was specified in the +ActiveModel::Serializer class.

+ + +
+
+
+ +
+

Examples:

+ + +
class PostSerializer < ActiveModel::Serializer
+  attribute :content
+  attribute :name, key: :title
+  attribute :email, key: :author_email, if: :user_logged_in?
+  attribute :preview do
+    truncate(object.content)
+  end
+
+  def user_logged_in?
+    current_user.logged_in?
+  end
+end
+ +
+ + +
+ + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Field

+

#block, #name, #options

+ + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Attributes.html b/ActiveModel/Serializer/Attributes.html new file mode 100644 index 00000000..fa2ad244 --- /dev/null +++ b/ActiveModel/Serializer/Attributes.html @@ -0,0 +1,124 @@ + + + + + + Module: ActiveModel::Serializer::Attributes + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Attributes + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + + + +
Included in:
+
ActiveModel::Serializer
+ + + +
Defined in:
+
lib/active_model/serializer/attributes.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: ClassMethods + + + + +

+ + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Attributes/ClassMethods.html b/ActiveModel/Serializer/Attributes/ClassMethods.html new file mode 100644 index 00000000..db620e81 --- /dev/null +++ b/ActiveModel/Serializer/Attributes/ClassMethods.html @@ -0,0 +1,497 @@ + + + + + + Module: ActiveModel::Serializer::Attributes::ClassMethods + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Attributes::ClassMethods + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model/serializer/attributes.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) _attributes + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ +

keys of attributes

+ + +
+
+
+ + +

See Also:

+
    + +
  • Serializer::attribute
  • + +
+ +
+ + + + +
+
+
+
+64
+65
+66
+
+
# File 'lib/active_model/serializer/attributes.rb', line 64
+
+def _attributes
+  _attributes_data.keys
+end
+
+
+ +
+

+ + - (Object) _attributes_keys + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ +

maps attribute value to explict key name

+ + +
+
+
+ + +

See Also:

+
    + +
  • Serializer::attribute
  • + +
  • FragmentCache#fragment_serializer
  • + +
+ +
+ + + + +
+
+
+
+72
+73
+74
+75
+76
+77
+78
+
+
# File 'lib/active_model/serializer/attributes.rb', line 72
+
+def _attributes_keys
+  _attributes_data
+    .each_with_object({}) do |(key, attr), hash|
+      next if key == attr.name
+      hash[attr.name] = { key: key }
+    end
+end
+
+
+ +
+

+ + - (Object) attribute(attr, options = {}, &block) + + + + + +

+
+ + +
+
+
+ +
+

Examples:

+ + +
class AdminAuthorSerializer < ActiveModel::Serializer
+  attributes :id, :recent_edits
+  attribute :name, key: :title
+
+  attribute :full_name do
+    "#{object.first_name} #{object.last_name}"
+  end
+
+  def recent_edits
+    object.edits.last(5)
+  end
+ +
+ + +
+ + + + +
+
+
+
+56
+57
+58
+59
+
+
# File 'lib/active_model/serializer/attributes.rb', line 56
+
+def attribute(attr, options = {}, &block)
+  key = options.fetch(:key, attr)
+  _attributes_data[key] = Attribute.new(attr, options, block)
+end
+
+
+ +
+

+ + - (Object) attributes(*attrs) + + + + + +

+
+ + +
+
+
+ +
+

Examples:

+ + +
class AdminAuthorSerializer < ActiveModel::Serializer
+  attributes :id, :name, :recent_edits
+ +
+ + +
+ + + + +
+
+
+
+36
+37
+38
+39
+40
+41
+42
+
+
# File 'lib/active_model/serializer/attributes.rb', line 36
+
+def attributes(*attrs)
+  attrs = attrs.first if attrs.first.class == Array
+
+  attrs.each do |attr|
+    attribute(attr)
+  end
+end
+
+
+ +
+

+ + - (Object) inherited(base) + + + + + +

+ + + + +
+
+
+
+28
+29
+30
+31
+
+
# File 'lib/active_model/serializer/attributes.rb', line 28
+
+def inherited(base)
+  super
+  base._attributes_data = _attributes_data.dup
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/BelongsToReflection.html b/ActiveModel/Serializer/BelongsToReflection.html new file mode 100644 index 00000000..2f6226bc --- /dev/null +++ b/ActiveModel/Serializer/BelongsToReflection.html @@ -0,0 +1,176 @@ + + + + + + Class: ActiveModel::Serializer::BelongsToReflection + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::BelongsToReflection + + + Private +

+ +
+ +
Inherits:
+
+ SingularReflection + + + show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/belongs_to_reflection.rb
+ +
+
+ +
+
+

+ This class is part of a private API. + You should avoid using this class if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Field

+

#block, #name, #options

+ + + + + + + + + + + + + + + +

Method Summary

+ +

Methods inherited from Reflection

+

#build_association, #include_data, #initialize, #link, #meta, #value

+ + + + + + + +
+

Constructor Details

+ +

This class inherits a constructor from ActiveModel::Serializer::Reflection

+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Caching.html b/ActiveModel/Serializer/Caching.html new file mode 100644 index 00000000..e59a382d --- /dev/null +++ b/ActiveModel/Serializer/Caching.html @@ -0,0 +1,638 @@ + + + + + + Module: ActiveModel::Serializer::Caching + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Caching + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + + + +
Included in:
+
ActiveModel::Serializer
+ + + +
Defined in:
+
lib/active_model/serializer/caching.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: ClassMethods + + + + +

+ +

Constant Summary

+ +
+ +
CALLER_FILE = +
+
+ +

Matches

+ +
"c:/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'"
+AND
+"/c/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb:1:in `<top (required)>'"
+AS
+c/git/emberjs/ember-crm-backend/app/serializers/lead_serializer.rb
+
+ + +
+
+
+ + +
+
+
/
+  \A       # start of string
+  .+       # file path (one or more characters)
+  (?=      # stop previous match when
+    :\d+     # a colon is followed by one or more digits
+    :in      # followed by a colon followed by in
+  )
+/x
+ +
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) cache_key(adapter_instance) + + + + + +

+ + + + +
+
+
+
+256
+257
+258
+259
+260
+261
+262
+263
+264
+
+
# File 'lib/active_model/serializer/caching.rb', line 256
+
+def cache_key(adapter_instance)
+  return @cache_key if defined?(@cache_key)
+
+  parts = []
+  parts << object_cache_key
+  parts << adapter_instance.cache_key
+  parts << serializer_class._cache_digest unless serializer_class._skip_digest?
+  @cache_key = parts.join('/')
+end
+
+
+ +
+

+ + - (Object) fetch(adapter_instance, cache_options = serializer_class._cache_options) + + + + + +

+ + + + +
+
+
+
+220
+221
+222
+223
+224
+225
+226
+227
+228
+
+
# File 'lib/active_model/serializer/caching.rb', line 220
+
+def fetch(adapter_instance, cache_options = serializer_class._cache_options)
+  if serializer_class.cache_store
+    serializer_class.cache_store.fetch(cache_key(adapter_instance), cache_options) do
+      yield
+    end
+  else
+    yield
+  end
+end
+
+
+ +
+

+ + - (Object) fetch_attributes(fields, cached_attributes, adapter_instance) + + + + + +

+
+ +

INSTANCE METHODS

+ + +
+
+
+ + +
+ + + + +
+
+
+
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+
+
# File 'lib/active_model/serializer/caching.rb', line 205
+
+def fetch_attributes(fields, cached_attributes, adapter_instance)
+  if serializer_class.cache_enabled?
+    key = cache_key(adapter_instance)
+    cached_attributes.fetch(key) do
+      serializer_class.cache_store.fetch(key, serializer_class._cache_options) do
+        attributes(fields, true)
+      end
+    end
+  elsif serializer_class.fragment_cache_enabled?
+    fetch_attributes_fragment(adapter_instance)
+  else
+    attributes(fields, true)
+  end
+end
+
+
+ +
+

+ + - (Object) fetch_attributes_fragment(adapter_instance) + + + + + +

+
+
  1. +

    Determine cached fields from serializer class options

    +
  2. +

    Get non_cached_fields and fetch cache_fields

    +
  3. +

    Merge the two hashes using adapter_instance#fragment_cache

    +
+ + +
+
+
+ + +
+ + + + +
+
+
+
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+
+
# File 'lib/active_model/serializer/caching.rb', line 233
+
+def fetch_attributes_fragment(adapter_instance)
+  serializer_class._cache_options ||= {}
+  serializer_class._cache_options[:key] = serializer_class._cache_key if serializer_class._cache_key
+  fields = serializer_class.fragmented_attributes
+
+  non_cached_fields = fields[:non_cached].dup
+  non_cached_hash = attributes(non_cached_fields, true)
+  include_directive = JSONAPI::IncludeDirective.new(non_cached_fields - non_cached_hash.keys)
+  non_cached_hash.merge! resource_relationships({}, { include_directive: include_directive }, adapter_instance)
+
+  cached_fields = fields[:cached].dup
+  key = cache_key(adapter_instance)
+  cached_hash =
+    serializer_class.cache_store.fetch(key, serializer_class._cache_options) do
+      hash = attributes(cached_fields, true)
+      include_directive = JSONAPI::IncludeDirective.new(cached_fields - hash.keys)
+      hash.merge! resource_relationships({}, { include_directive: include_directive }, adapter_instance)
+    end
+
+  # Merge both results
+  adapter_instance.fragment_cache(cached_hash, non_cached_hash)
+end
+
+
+ +
+

+ + - (Object) object_cache_key + + + + + +

+
+ +

Use object's cache_key if available, else derive a key from the object +Pass the `key` option to the `cache` declaration or override this method to +customize the cache key

+ + +
+
+
+ + +
+ + + + +
+
+
+
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+
+
# File 'lib/active_model/serializer/caching.rb', line 268
+
+def object_cache_key
+  if object.respond_to?(:cache_key)
+    object.cache_key
+  elsif (serializer_cache_key = (serializer_class._cache_key || serializer_class._cache_options[:key]))
+    object_time_safe = object.updated_at
+    object_time_safe = object_time_safe.strftime('%Y%m%d%H%M%S%9N') if object_time_safe.respond_to?(:strftime)
+    "#{serializer_cache_key}/#{object.id}-#{object_time_safe}"
+  else
+    fail UndefinedCacheKey, "#{object.class} must define #cache_key, or the 'key:' option must be passed into '#{serializer_class}.cache'"
+  end
+end
+
+
+ +
+

+ + - (Object) serializer_class + + + + + +

+ + + + +
+
+
+
+280
+281
+282
+
+
# File 'lib/active_model/serializer/caching.rb', line 280
+
+def serializer_class
+  @serializer_class ||= self.class
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Caching/ClassMethods.html b/ActiveModel/Serializer/Caching/ClassMethods.html new file mode 100644 index 00000000..07bbfa85 --- /dev/null +++ b/ActiveModel/Serializer/Caching/ClassMethods.html @@ -0,0 +1,1300 @@ + + + + + + Module: ActiveModel::Serializer::Caching::ClassMethods + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Caching::ClassMethods + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model/serializer/caching.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) _cache_digest + + + + + +

+ + + + +
+
+
+
+48
+49
+50
+51
+
+
# File 'lib/active_model/serializer/caching.rb', line 48
+
+def _cache_digest
+  return @_cache_digest if defined?(@_cache_digest)
+  @_cache_digest = digest_caller_file(_cache_digest_file_path)
+end
+
+
+ +
+

+ + - (Boolean) _skip_digest? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+67
+68
+69
+
+
# File 'lib/active_model/serializer/caching.rb', line 67
+
+def _skip_digest?
+  _cache_options && _cache_options[:skip_digest]
+end
+
+
+ +
+

+ + - (Object) cache(options = {}) + + + + + +

+
+ +
+ TODO: +
+

require less code comments. See

+
+
+ + +

Enables a serializer to be automatically cached

+ +

Sets ::_cache object to +ActionController::Base.cache_store

+ +
when Rails.configuration.action_controller.perform_caching
+ +

github.com/rails-api/active_model_serializers/pull/1249#issuecomment-146567837

+ + +
+
+
+ +
+

Examples:

+ + +
class PostSerializer < ActiveModel::Serializer
+  cache key: 'post', expires_in: 3.hours
+  attributes :title, :body
+
+  has_many :comments
+end
+ +
+

Parameters:

+
    + +
  • + + options + + + (Hash) + + + (defaults to: {}) + + + — +
    +

    with valid keys: cache_store : @see ::_cache key : @see +::_cache_key only : @see ::_cache_only except : @see +::_cache_except skip_digest : does not include digest in cache_key all +else : @see ::_cache_options

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+
+
# File 'lib/active_model/serializer/caching.rb', line 105
+
+def cache(options = {})
+  self._cache =
+    options.delete(:cache_store) ||
+    ActiveModelSerializers.config.cache_store ||
+    ActiveSupport::Cache.lookup_store(:null_store)
+  self._cache_key = options.delete(:key)
+  self._cache_only = options.delete(:only)
+  self._cache_except = options.delete(:except)
+  self._cache_options = options.empty? ? nil : options
+end
+
+
+ +
+

+ + - (Boolean) cache_enabled? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+150
+151
+152
+
+
# File 'lib/active_model/serializer/caching.rb', line 150
+
+def cache_enabled?
+  perform_caching? && cache_store && !_cache_only && !_cache_except
+end
+
+
+ +
+

+ + - (Hash) cache_read_multi(collection_serializer, adapter_instance, include_directive) + + + + + +

+
+ +

Read cache from cache_store

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash) + + + +
  • + +
+ +
+ + + + +
+
+
+
+161
+162
+163
+164
+165
+166
+167
+168
+169
+
+
# File 'lib/active_model/serializer/caching.rb', line 161
+
+def cache_read_multi(collection_serializer, adapter_instance, include_directive)
+  return {} if ActiveModelSerializers.config.cache_store.blank?
+
+  keys = object_cache_keys(collection_serializer, adapter_instance, include_directive)
+
+  return {} if keys.blank?
+
+  ActiveModelSerializers.config.cache_store.read_multi(*keys)
+end
+
+
+ +
+

+ + - (nil, ...) cache_store + + + + + +

+
+ +

The canonical method for getting the cache store for the serializer.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (nil) + + + + — +
    +

    when _cache is not set (i.e. when `cache` has not been called)

    +
    + +
  • + +
  • + + + (._cache) + + + + — +
    +

    when _cache is not the NullStore

    +
    + +
  • + +
  • + + + (ActiveModelSerializers.config.cache_store) + + + + — +
    +

    when _cache is the NullStore. This is so we can use `cache` being called to +mean the serializer should be cached even if +ActiveModelSerializers.config.cache_store has not yet been set. That means +that when _cache is the NullStore and +ActiveModelSerializers.config.cache_store is configured, `cache_store` +becomes `ActiveModelSerializers.config.cache_store`.

    +
    + +
  • + +
  • + + + (nil) + + + + — +
    +

    when _cache is the NullStore and ActiveModelSerializers.config.cache_store +is nil.

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+140
+141
+142
+143
+144
+145
+146
+147
+148
+
+
# File 'lib/active_model/serializer/caching.rb', line 140
+
+def cache_store
+  return nil if _cache.nil?
+  return _cache if _cache.class != ActiveSupport::Cache::NullStore
+  if ActiveModelSerializers.config.cache_store
+    self._cache = ActiveModelSerializers.config.cache_store
+  else
+    nil
+  end
+end
+
+
+ +
+

+ + - (Object) digest_caller_file(caller_line) + + + + + +

+
+ +

Hashes contents of file for _cache_digest

+ + +
+
+
+ + +
+ + + + +
+
+
+
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+
+
# File 'lib/active_model/serializer/caching.rb', line 54
+
+def digest_caller_file(caller_line)
+  serializer_file_path = caller_line[CALLER_FILE]
+  serializer_file_contents = IO.read(serializer_file_path)
+  Digest::MD5.hexdigest(serializer_file_contents)
+rescue TypeError, Errno::ENOENT
+  warn <<-EOF.strip_heredoc
+    Cannot digest non-existent file: '#{caller_line}'.
+    Please set `::_cache_digest` of the serializer
+    if you'd like to cache it.
+    EOF
+  ''.freeze
+end
+
+
+ +
+

+ + - (Boolean) fragment_cache_enabled? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+154
+155
+156
+157
+
+
# File 'lib/active_model/serializer/caching.rb', line 154
+
+def fragment_cache_enabled?
+  perform_caching? && cache_store &&
+    (_cache_only && !_cache_except || !_cache_only && _cache_except)
+end
+
+
+ +
+

+ + - (Object) fragmented_attributes + + + + + +

+ + + + +
+
+
+
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+
+
# File 'lib/active_model/serializer/caching.rb', line 71
+
+def fragmented_attributes
+  cached = _cache_only ? _cache_only : _attributes - _cache_except
+  cached = cached.map! { |field| _attributes_keys.fetch(field, field) }
+  non_cached = _attributes - cached
+  non_cached = non_cached.map! { |field| _attributes_keys.fetch(field, field) }
+  {
+    cached: cached,
+    non_cached: non_cached
+  }
+end
+
+
+ +
+

+ + - (Object) inherited(base) + + + + + +

+ + + + +
+
+
+
+42
+43
+44
+45
+46
+
+
# File 'lib/active_model/serializer/caching.rb', line 42
+
+def inherited(base)
+  super
+  caller_line = caller[1]
+  base._cache_digest_file_path = caller_line
+end
+
+
+ +
+

+ + - (String?) object_cache_key(serializer, adapter_instance) + + + + + +

+
+ +

Returns the cache_key of the serializer or nil

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (String, nil) + + + + — +
    +

    the cache_key of the serializer or nil

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+197
+198
+199
+200
+201
+
+
# File 'lib/active_model/serializer/caching.rb', line 197
+
+def object_cache_key(serializer, adapter_instance)
+  return unless serializer.present? && serializer.object.present?
+
+  serializer.class.cache_enabled? ? serializer.cache_key(adapter_instance) : nil
+end
+
+
+ +
+

+ + - (Array) object_cache_keys(collection_serializer, adapter_instance, include_directive) + + + + + +

+
+ +

Find all cache_key for the collection_serializer

+ + +
+
+
+

Parameters:

+ + +

Returns:

+
    + +
  • + + + (Array) + + + + — +
    +

    all cache_key of collection_serializer

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+
+
# File 'lib/active_model/serializer/caching.rb', line 176
+
+def object_cache_keys(collection_serializer, adapter_instance, include_directive)
+  cache_keys = []
+
+  collection_serializer.each do |serializer|
+    cache_keys << object_cache_key(serializer, adapter_instance)
+
+    serializer.associations(include_directive).each do |association|
+      if association.serializer.respond_to?(:each)
+        association.serializer.each do |sub_serializer|
+          cache_keys << object_cache_key(sub_serializer, adapter_instance)
+        end
+      else
+        cache_keys << object_cache_key(association.serializer, adapter_instance)
+      end
+    end
+  end
+
+  cache_keys.compact.uniq
+end
+
+
+ +
+

+ + - (true, false) perform_caching + + + + Also known as: + perform_caching? + + + + +

+
+ +

Value is from ActiveModelSerializers.config.perform_caching. Is used to +globally enable or disable all serializer caching, just like +Rails.configuration.action_controller.perform_caching, which is its default +value in a Rails application. Memoizes value of config first time it is +called with a non-nil value. rubocop:disable Style/ClassVars

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (true, false) + + + +
  • + +
+ +
+ + + + +
+
+
+
+123
+124
+125
+126
+
+
# File 'lib/active_model/serializer/caching.rb', line 123
+
+def perform_caching
+  return @@perform_caching if defined?(@@perform_caching) && !@@perform_caching.nil?
+  @@perform_caching = ActiveModelSerializers.config.perform_caching
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/CollectionReflection.html b/ActiveModel/Serializer/CollectionReflection.html new file mode 100644 index 00000000..b684648a --- /dev/null +++ b/ActiveModel/Serializer/CollectionReflection.html @@ -0,0 +1,172 @@ + + + + + + Class: ActiveModel::Serializer::CollectionReflection + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::CollectionReflection + + + Private +

+ +
+ +
Inherits:
+
+ Reflection + +
    +
  • Object
  • + + + + + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/collection_reflection.rb
+ +
+
+ +
+
+

+ This class is part of a private API. + You should avoid using this class if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+

Direct Known Subclasses

+

HasManyReflection

+
+ + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Field

+

#block, #name, #options

+ + + + + + + + + +

Method Summary

+ +

Methods inherited from Reflection

+

#build_association, #include_data, #initialize, #link, #meta, #value

+ + + + + + + +
+

Constructor Details

+ +

This class inherits a constructor from ActiveModel::Serializer::Reflection

+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/CollectionSerializer.html b/ActiveModel/Serializer/CollectionSerializer.html new file mode 100644 index 00000000..4067a74e --- /dev/null +++ b/ActiveModel/Serializer/CollectionSerializer.html @@ -0,0 +1,712 @@ + + + + + + Class: ActiveModel::Serializer::CollectionSerializer + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::CollectionSerializer + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + +
Includes:
+
Enumerable
+ + + + + +
Defined in:
+
lib/active_model/serializer/collection_serializer.rb
+ +
+
+ +
+

Direct Known Subclasses

+

ArraySerializer

+
+ +

Constant Summary

+ +
+ +
NoSerializerError = + +
+
Class.new(StandardError)
+ +
+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + +
+

Constructor Details

+ +
+

+ + - (CollectionSerializer) initialize(resources, options = {}) + + + + + +

+
+ +

Returns a new instance of CollectionSerializer

+ + +
+
+
+ + +
+ + + + +
+
+
+
+10
+11
+12
+13
+14
+15
+
+
# File 'lib/active_model/serializer/collection_serializer.rb', line 10
+
+def initialize(resources, options = {})
+  @object                  = resources
+  @options                 = options
+  @root                    = options[:root]
+  @serializers             = serializers_from_resources
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) object (readonly) + + + + + +

+
+ +

Returns the value of attribute object

+ + +
+
+
+ + +
+ + + + +
+
+
+
+8
+9
+10
+
+
# File 'lib/active_model/serializer/collection_serializer.rb', line 8
+
+def object
+  @object
+end
+
+
+ + + +
+

+ + - (Object) root (readonly) + + + + + +

+
+ +

Returns the value of attribute root

+ + +
+
+
+ + +
+ + + + +
+
+
+
+8
+9
+10
+
+
# File 'lib/active_model/serializer/collection_serializer.rb', line 8
+
+def root
+  @root
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) json_key + + + + + +

+
+ +

TODO: unify naming of root, json_key, and _type. Right now, a +serializer's json_key comes from the root option or the object's +model name, by default. But, if a dev defines a custom `json_key` method +with an explicit value, we have no simple way to know that it is safe to +call that instance method. (which is really a class property at this point, +anyhow). rubocop:disable Metrics/CyclomaticComplexity Disabling cop since +it's good to highlight the complexity of this method by including all +the logic right here.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+
+
# File 'lib/active_model/serializer/collection_serializer.rb', line 39
+
+def json_key
+  return root if root
+  # 1. get from options[:serializer] for empty resource collection
+  key = object.empty? &&
+    (explicit_serializer_class = options[:serializer]) &&
+    explicit_serializer_class._type
+  # 2. get from first serializer instance in collection
+  key ||= (serializer = serializers.first) && serializer.json_key
+  # 3. get from collection name, if a named collection
+  key ||= object.respond_to?(:name) ? object.name && object.name.underscore : nil
+  # 4. key may be nil for empty collection and no serializer option
+  key && key.pluralize
+end
+
+
+ +
+

+ + - (Boolean) paginated? + + + + + +

+
+ +

rubocop:enable Metrics/CyclomaticComplexity

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+54
+55
+56
+57
+58
+
+
# File 'lib/active_model/serializer/collection_serializer.rb', line 54
+
+def paginated?
+  object.respond_to?(:current_page) &&
+    object.respond_to?(:total_pages) &&
+    object.respond_to?(:size)
+end
+
+
+ +
+

+ + - (Object) serializable_hash(adapter_options, options, adapter_instance) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+22
+23
+24
+25
+26
+27
+28
+29
+
+
# File 'lib/active_model/serializer/collection_serializer.rb', line 22
+
+def serializable_hash(adapter_options, options, adapter_instance)
+  include_directive = ActiveModel::Serializer.include_directive_from_options(adapter_options)
+  adapter_options[:cached_attributes] ||= ActiveModel::Serializer.cache_read_multi(self, adapter_instance, include_directive)
+  adapter_opts = adapter_options.merge(include_directive: include_directive)
+  serializers.map do |serializer|
+    serializer.serializable_hash(adapter_opts, options, adapter_instance)
+  end
+end
+
+
+ +
+

+ + - (Boolean) success? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+17
+18
+19
+
+
# File 'lib/active_model/serializer/collection_serializer.rb', line 17
+
+def success?
+  true
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Configuration.html b/ActiveModel/Serializer/Configuration.html new file mode 100644 index 00000000..80471f8d --- /dev/null +++ b/ActiveModel/Serializer/Configuration.html @@ -0,0 +1,119 @@ + + + + + + Module: ActiveModel::Serializer::Configuration + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Configuration + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + +
Includes:
+
ActiveSupport::Configurable
+ + + + +
Included in:
+
ActiveModel::Serializer
+ + + +
Defined in:
+
lib/active_model/serializer/configuration.rb
+ +
+
+ + + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/ErrorSerializer.html b/ActiveModel/Serializer/ErrorSerializer.html new file mode 100644 index 00000000..73d59e4d --- /dev/null +++ b/ActiveModel/Serializer/ErrorSerializer.html @@ -0,0 +1,396 @@ + + + + + + Class: ActiveModel::Serializer::ErrorSerializer + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::ErrorSerializer + + + +

+ +
+ +
Inherits:
+
+ ActiveModel::Serializer + + + show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/error_serializer.rb
+ +
+
+ + +

Constant Summary

+ + + + +

Constant Summary

+ +

Constants inherited + from ActiveModel::Serializer

+

SERIALIZABLE_HASH_VALID_KEYS, UndefinedCacheKey, VERSION

+ + + +

Constants included + from Caching

+

Caching::CALLER_FILE

+ + + + +

Instance Attribute Summary

+ +

Attributes inherited from ActiveModel::Serializer

+

#object, #root, #scope

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods inherited from ActiveModel::Serializer

+

adapter, get_serializer_for, include_directive_from_options, #initialize, #json_key, #read_attribute_for_serialization, #relationship_value_for, #resource_relationships, #serializable_hash, serialization_adapter_instance, serializer_for, serializer_lookup_chain_for, serializers_cache

+ + + + + + + + + +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Methods included from Caching

+

#cache_key, #fetch, #fetch_attributes, #fetch_attributes_fragment, #object_cache_key, #serializer_class

+ + + + + + + + + + + + + + + + + +

Methods included from Associations

+

#associations

+ + + + + + + + + +
+

Constructor Details

+ +

This class inherits a constructor from ActiveModel::Serializer

+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Hash<field_name,Array<error_message>>) as_json + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Hash<field_name,Array<error_message>>) + + + +
  • + +
+ +
+ + + + +
+
+
+
+3
+4
+5
+
+
# File 'lib/active_model/serializer/error_serializer.rb', line 3
+
+def as_json
+  object.errors.messages
+end
+
+
+ +
+

+ + - (Boolean) success? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+7
+8
+9
+
+
# File 'lib/active_model/serializer/error_serializer.rb', line 7
+
+def success?
+  false
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/ErrorsSerializer.html b/ActiveModel/Serializer/ErrorsSerializer.html new file mode 100644 index 00000000..be513c49 --- /dev/null +++ b/ActiveModel/Serializer/ErrorsSerializer.html @@ -0,0 +1,503 @@ + + + + + + Class: ActiveModel::Serializer::ErrorsSerializer + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::ErrorsSerializer + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + +
Includes:
+
Enumerable
+ + + + + +
Defined in:
+
lib/active_model/serializer/errors_serializer.rb
+ +
+
+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + +
+

Constructor Details

+ +
+

+ + - (ErrorsSerializer) initialize(resources, options = {}) + + + + + +

+
+ +

Returns a new instance of ErrorsSerializer

+ + +
+
+
+ + +
+ + + + +
+
+
+
+7
+8
+9
+10
+11
+12
+13
+14
+
+
# File 'lib/active_model/serializer/errors_serializer.rb', line 7
+
+def initialize(resources, options = {})
+  @root = options[:root]
+  @object = resources
+  @serializers = resources.map do |resource|
+    serializer_class = options.fetch(:serializer) { ActiveModel::Serializer::ErrorSerializer }
+    serializer_class.new(resource, options.except(:serializer))
+  end
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) object (readonly) + + + + + +

+
+ +

Returns the value of attribute object

+ + +
+
+
+ + +
+ + + + +
+
+
+
+5
+6
+7
+
+
# File 'lib/active_model/serializer/errors_serializer.rb', line 5
+
+def object
+  @object
+end
+
+
+ + + +
+

+ + - (Object) root (readonly) + + + + + +

+
+ +

Returns the value of attribute root

+ + +
+
+
+ + +
+ + + + +
+
+
+
+5
+6
+7
+
+
# File 'lib/active_model/serializer/errors_serializer.rb', line 5
+
+def root
+  @root
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) json_key + + + + + +

+ + + + +
+
+
+
+20
+21
+22
+
+
# File 'lib/active_model/serializer/errors_serializer.rb', line 20
+
+def json_key
+  nil
+end
+
+
+ +
+

+ + - (Boolean) success? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+16
+17
+18
+
+
# File 'lib/active_model/serializer/errors_serializer.rb', line 16
+
+def success?
+  false
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Field.html b/ActiveModel/Serializer/Field.html new file mode 100644 index 00000000..be09521c --- /dev/null +++ b/ActiveModel/Serializer/Field.html @@ -0,0 +1,414 @@ + + + + + + Class: ActiveModel::Serializer::Field + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Field + + + +

+ +
+ +
Inherits:
+
+ Struct + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/field.rb
+ +
+
+ +

Overview

+
+ +

Holds all the meta-data about a field (i.e. attribute or association) as it +was specified in the ActiveModel::Serializer class. Notice that the field +block is evaluated in the context of the serializer.

+ + +
+
+
+ + +
+

Direct Known Subclasses

+

Attribute, Reflection

+
+ + + + +

Instance Attribute Summary (collapse)

+ + + + + + + +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) block + + + + + +

+
+ +

Returns the value of attribute block

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Object) + + + + — +
    +

    the current value of block

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+6
+7
+8
+
+
# File 'lib/active_model/serializer/field.rb', line 6
+
+def block
+  @block
+end
+
+
+ + + +
+

+ + - (Object) name + + + + + +

+
+ +

Returns the value of attribute name

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Object) + + + + — +
    +

    the current value of name

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+6
+7
+8
+
+
# File 'lib/active_model/serializer/field.rb', line 6
+
+def name
+  @name
+end
+
+
+ + + +
+

+ + - (Object) options + + + + + +

+
+ +

Returns the value of attribute options

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Object) + + + + — +
    +

    the current value of options

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+6
+7
+8
+
+
# File 'lib/active_model/serializer/field.rb', line 6
+
+def options
+  @options
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Fieldset.html b/ActiveModel/Serializer/Fieldset.html new file mode 100644 index 00000000..bbf63156 --- /dev/null +++ b/ActiveModel/Serializer/Fieldset.html @@ -0,0 +1,312 @@ + + + + + + Class: ActiveModel::Serializer::Fieldset + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Fieldset + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/fieldset.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Fieldset) initialize(fields) + + + + + +

+
+ +

Returns a new instance of Fieldset

+ + +
+
+
+ + +
+ + + + +
+
+
+
+4
+5
+6
+
+
# File 'lib/active_model/serializer/fieldset.rb', line 4
+
+def initialize(fields)
+  @raw_fields = fields || {}
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) fields + + + + + +

+ + + + +
+
+
+
+8
+9
+10
+
+
# File 'lib/active_model/serializer/fieldset.rb', line 8
+
+def fields
+  @fields ||= parsed_fields
+end
+
+
+ +
+

+ + - (Object) fields_for(type) + + + + + +

+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/active_model/serializer/fieldset.rb', line 12
+
+def fields_for(type)
+  fields[type.singularize.to_sym] || fields[type.pluralize.to_sym]
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/HasManyReflection.html b/ActiveModel/Serializer/HasManyReflection.html new file mode 100644 index 00000000..9866ab3f --- /dev/null +++ b/ActiveModel/Serializer/HasManyReflection.html @@ -0,0 +1,176 @@ + + + + + + Class: ActiveModel::Serializer::HasManyReflection + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::HasManyReflection + + + Private +

+ +
+ +
Inherits:
+
+ CollectionReflection + + + show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/has_many_reflection.rb
+ +
+
+ +
+
+

+ This class is part of a private API. + You should avoid using this class if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Field

+

#block, #name, #options

+ + + + + + + + + + + + + + + +

Method Summary

+ +

Methods inherited from Reflection

+

#build_association, #include_data, #initialize, #link, #meta, #value

+ + + + + + + +
+

Constructor Details

+ +

This class inherits a constructor from ActiveModel::Serializer::Reflection

+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/HasOneReflection.html b/ActiveModel/Serializer/HasOneReflection.html new file mode 100644 index 00000000..a30cd7cc --- /dev/null +++ b/ActiveModel/Serializer/HasOneReflection.html @@ -0,0 +1,176 @@ + + + + + + Class: ActiveModel::Serializer::HasOneReflection + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::HasOneReflection + + + Private +

+ +
+ +
Inherits:
+
+ SingularReflection + + + show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/has_one_reflection.rb
+ +
+
+ +
+
+

+ This class is part of a private API. + You should avoid using this class if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Field

+

#block, #name, #options

+ + + + + + + + + + + + + + + +

Method Summary

+ +

Methods inherited from Reflection

+

#build_association, #include_data, #initialize, #link, #meta, #value

+ + + + + + + +
+

Constructor Details

+ +

This class inherits a constructor from ActiveModel::Serializer::Reflection

+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Links.html b/ActiveModel/Serializer/Links.html new file mode 100644 index 00000000..25df9c08 --- /dev/null +++ b/ActiveModel/Serializer/Links.html @@ -0,0 +1,124 @@ + + + + + + Module: ActiveModel::Serializer::Links + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Links + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + + + +
Included in:
+
ActiveModel::Serializer
+ + + +
Defined in:
+
lib/active_model/serializer/links.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: ClassMethods + + + + +

+ + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Links/ClassMethods.html b/ActiveModel/Serializer/Links/ClassMethods.html new file mode 100644 index 00000000..3f981578 --- /dev/null +++ b/ActiveModel/Serializer/Links/ClassMethods.html @@ -0,0 +1,255 @@ + + + + + + Module: ActiveModel::Serializer::Links::ClassMethods + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Links::ClassMethods + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model/serializer/links.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) inherited(base) + + + + + +

+ + + + +
+
+
+
+16
+17
+18
+19
+
+
# File 'lib/active_model/serializer/links.rb', line 16
+
+def inherited(base)
+  super
+  base._links = _links.dup
+end
+
+
+ +
+
+
+ +

Define a link on a serializer.

+ + +
+
+
+ +
+

Examples:

+ + +
link(:self) { resource_url(object) }
+ + +
link(:self) { "http://example.com/resource/#{object.id}" }
+ + +
link :resource, "http://example.com/resource"
+ +
+ + +
+ + + + +
+
+
+
+29
+30
+31
+
+
# File 'lib/active_model/serializer/links.rb', line 29
+
+def link(name, value = nil, &block)
+  _links[name] = block || value
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Lint.html b/ActiveModel/Serializer/Lint.html new file mode 100644 index 00000000..3bc6cafc --- /dev/null +++ b/ActiveModel/Serializer/Lint.html @@ -0,0 +1,115 @@ + + + + + + Module: ActiveModel::Serializer::Lint + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Lint + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model/serializer/lint.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: Tests + + + + +

+ + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Lint/Tests.html b/ActiveModel/Serializer/Lint/Tests.html new file mode 100644 index 00000000..b34597c4 --- /dev/null +++ b/ActiveModel/Serializer/Lint/Tests.html @@ -0,0 +1,910 @@ + + + + + + Module: ActiveModel::Serializer::Lint::Tests + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Lint::Tests + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model/serializer/lint.rb
+ +
+
+ +

Overview

+
+ +

Active Model Serializer Lint Tests

+ +

You can test whether an object is compliant with the Active Model +Serializers API by including +ActiveModel::Serializer::Lint::Tests in your TestCase. It will +include tests that tell you whether your object is fully compliant, or if +not, which aspects of the API are not implemented.

+ +

Note an object is not required to implement all APIs in order to work with +Active Model Serializers. This module only intends to provide guidance in +case you want all features out of the box.

+ +

These tests do not attempt to determine the semantic correctness of the +returned values. For instance, you could implement +serializable_hash to always return {}, and the tests would +pass. It is up to you to ensure that the values are semantically +meaningful.

+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) test_active_model_errors + + + + + +

+ + + + +
+
+
+
+122
+123
+124
+
+
# File 'lib/active_model/serializer/lint.rb', line 122
+
+def test_active_model_errors
+  assert_respond_to resource, :errors
+end
+
+
+ +
+

+ + - (Object) test_active_model_errors_human_attribute_name + + + + + +

+ + + + +
+
+
+
+126
+127
+128
+129
+
+
# File 'lib/active_model/serializer/lint.rb', line 126
+
+def test_active_model_errors_human_attribute_name
+  assert_respond_to resource.class, :human_attribute_name
+  assert_equal(-2, resource.class.method(:human_attribute_name).arity)
+end
+
+
+ +
+

+ + - (Object) test_active_model_errors_lookup_ancestors + + + + + +

+ + + + +
+
+
+
+131
+132
+133
+134
+
+
# File 'lib/active_model/serializer/lint.rb', line 131
+
+def test_active_model_errors_lookup_ancestors
+  assert_respond_to resource.class, :lookup_ancestors
+  assert_equal 0, resource.class.method(:lookup_ancestors).arity
+end
+
+
+ +
+

+ + - (Object) test_as_json + + + + + +

+
+ +

Passes if the object responds to as_json and if it takes zero +or one arguments. Fails otherwise.

+ +

as_json returns a hash representation of a serialized object. +It may delegate to serializable_hash Typically, it is +implemented either by including ActiveModel::Serialization which includes +ActiveModel::Serializers::JSON. or by the JSON gem when required.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+54
+55
+56
+57
+58
+
+
# File 'lib/active_model/serializer/lint.rb', line 54
+
+def test_as_json
+  assert_respond_to resource, :as_json
+  resource.as_json
+  resource.as_json(nil)
+end
+
+
+ +
+

+ + - (Object) test_cache_key + + + + + +

+
+ +

Passes if the object responds to cache_key Fails otherwise.

+ +

cache_key returns a (self-expiring) unique key for the object, +and is part of the (self-expiring) cache_key, which is used by the adapter. +It is not required unless caching is enabled.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+79
+80
+81
+82
+83
+
+
# File 'lib/active_model/serializer/lint.rb', line 79
+
+def test_cache_key
+  assert_respond_to resource, :cache_key
+  actual_arity = resource.method(:cache_key).arity
+  assert_includes [-1, 0], actual_arity, "expected #{actual_arity.inspect} to be 0 or -1"
+end
+
+
+ +
+

+ + - (Object) test_id + + + + + +

+
+ +

Passes if the object responds to id and if it takes no +arguments. Fails otherwise.

+ +

id returns a unique identifier for the object. It is not +required unless caching is enabled.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+104
+105
+106
+107
+
+
# File 'lib/active_model/serializer/lint.rb', line 104
+
+def test_id
+  assert_respond_to resource, :id
+  assert_equal 0, resource.method(:id).arity
+end
+
+
+ +
+

+ + - (Object) test_model_name + + + + + +

+
+ +

Passes if the object's class responds to model_name and if +it is in an instance of ActiveModel::Name. Fails otherwise.

+ +

model_name returns an ActiveModel::Name instance. It is used +by the serializer to identify the object's type. It is not required +unless caching is enabled.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+116
+117
+118
+119
+120
+
+
# File 'lib/active_model/serializer/lint.rb', line 116
+
+def test_model_name
+  resource_class = resource.class
+  assert_respond_to resource_class, :model_name
+  assert_instance_of resource_class.model_name, ActiveModel::Name
+end
+
+
+ +
+

+ + - (Object) test_read_attribute_for_serialization + + + + + +

+
+ +

Passes if the object responds to +read_attribute_for_serialization and if it requires one +argument (the attribute to be read). Fails otherwise.

+ +

read_attribute_for_serialization gets the attribute value for +serialization Typically, it is implemented by including +ActiveModel::Serialization.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+36
+37
+38
+39
+40
+41
+42
+43
+
+
# File 'lib/active_model/serializer/lint.rb', line 36
+
+def test_read_attribute_for_serialization
+  assert_respond_to resource, :read_attribute_for_serialization, 'The resource should respond to read_attribute_for_serialization'
+  actual_arity = resource.method(:read_attribute_for_serialization).arity
+  # using absolute value since arity is:
+  #  1 for def read_attribute_for_serialization(name); end
+  # -1 for alias :read_attribute_for_serialization :send
+  assert_equal 1, actual_arity.abs, "expected #{actual_arity.inspect}.abs to be 1 or -1"
+end
+
+
+ +
+

+ + - (Object) test_serializable_hash + + + + + +

+
+ +

Passes if the object responds to serializable_hash and if it +takes zero or one arguments. Fails otherwise.

+ +

serializable_hash returns a hash representation of a +object's attributes. Typically, it is implemented by including +ActiveModel::Serialization.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+24
+25
+26
+27
+28
+
+
# File 'lib/active_model/serializer/lint.rb', line 24
+
+def test_serializable_hash
+  assert_respond_to resource, :serializable_hash, 'The resource should respond to serializable_hash'
+  resource.serializable_hash
+  resource.serializable_hash(nil)
+end
+
+
+ +
+

+ + - (Object) test_to_json + + + + + +

+
+ +

Passes if the object responds to to_json and if it takes zero +or one arguments. Fails otherwise.

+ +

to_json returns a string representation (JSON) of a serialized +object. It may be called on the result of as_json. Typically, +it is implemented on all objects when the JSON gem is required.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+67
+68
+69
+70
+71
+
+
# File 'lib/active_model/serializer/lint.rb', line 67
+
+def test_to_json
+  assert_respond_to resource, :to_json
+  resource.to_json
+  resource.to_json(nil)
+end
+
+
+ +
+

+ + - (Object) test_updated_at + + + + + +

+
+ +

Passes if the object responds to updated_at and if it takes no +arguments. Fails otherwise.

+ +

updated_at returns a Time object or iso8601 string and is part +of the (self-expiring) cache_key, which is used by the adapter. It is not +required unless caching is enabled.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+92
+93
+94
+95
+96
+
+
# File 'lib/active_model/serializer/lint.rb', line 92
+
+def test_updated_at
+  assert_respond_to resource, :updated_at
+  actual_arity = resource.method(:updated_at).arity
+  assert_equal 0, actual_arity
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Meta.html b/ActiveModel/Serializer/Meta.html new file mode 100644 index 00000000..98bc6172 --- /dev/null +++ b/ActiveModel/Serializer/Meta.html @@ -0,0 +1,124 @@ + + + + + + Module: ActiveModel::Serializer::Meta + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Meta + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + + + +
Included in:
+
ActiveModel::Serializer
+ + + +
Defined in:
+
lib/active_model/serializer/meta.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: ClassMethods + + + + +

+ + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Meta/ClassMethods.html b/ActiveModel/Serializer/Meta/ClassMethods.html new file mode 100644 index 00000000..3031aa51 --- /dev/null +++ b/ActiveModel/Serializer/Meta/ClassMethods.html @@ -0,0 +1,201 @@ + + + + + + Module: ActiveModel::Serializer::Meta::ClassMethods + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Meta::ClassMethods + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model/serializer/meta.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) meta(value = nil, &block) + + + + + +

+
+ +

Set the JSON API meta attribute of a serializer.

+ + +
+
+
+ +
+

Examples:

+ + +
class AdminAuthorSerializer < ActiveModel::Serializer
+  meta { stuff: 'value' }
+ + +
meta do
+  { comment_count: object.comments.count }
+end
+ +
+ + +
+ + + + +
+
+
+
+23
+24
+25
+
+
# File 'lib/active_model/serializer/meta.rb', line 23
+
+def meta(value = nil, &block)
+  self._meta = block || value
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Null.html b/ActiveModel/Serializer/Null.html new file mode 100644 index 00000000..a1b63a2b --- /dev/null +++ b/ActiveModel/Serializer/Null.html @@ -0,0 +1,399 @@ + + + + + + Class: ActiveModel::Serializer::Null + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Null + + + +

+ +
+ +
Inherits:
+
+ ActiveModel::Serializer + + + show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/null.rb
+ +
+
+ + +

Constant Summary

+ + + + +

Constant Summary

+ +

Constants inherited + from ActiveModel::Serializer

+

SERIALIZABLE_HASH_VALID_KEYS, UndefinedCacheKey, VERSION

+ + + +

Constants included + from Caching

+

Caching::CALLER_FILE

+ + + + +

Instance Attribute Summary

+ +

Attributes inherited from ActiveModel::Serializer

+

#object, #root, #scope

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods inherited from ActiveModel::Serializer

+

adapter, #as_json, get_serializer_for, include_directive_from_options, #initialize, #json_key, #read_attribute_for_serialization, #relationship_value_for, #resource_relationships, serialization_adapter_instance, serializer_for, serializer_lookup_chain_for, serializers_cache, #success?

+ + + + + + + + + +

Methods included from ActiveModelSerializers::Deprecate

+

delegate_and_deprecate, deprecate

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Methods included from Caching

+

#cache_key, #fetch, #fetch_attributes, #fetch_attributes_fragment, #object_cache_key, #serializer_class

+ + + + + + + + + + + + + + + + + + + + + + + +
+

Constructor Details

+ +

This class inherits a constructor from ActiveModel::Serializer

+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) associations + + + + + +

+ + + + +
+
+
+
+8
+9
+10
+
+
# File 'lib/active_model/serializer/null.rb', line 8
+
+def associations(*)
+  {}
+end
+
+
+ +
+

+ + - (Object) attributes + + + + + +

+ + + + +
+
+
+
+4
+5
+6
+
+
# File 'lib/active_model/serializer/null.rb', line 4
+
+def attributes(*)
+  {}
+end
+
+
+ +
+

+ + - (Object) serializable_hash + + + + + +

+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/active_model/serializer/null.rb', line 12
+
+def serializable_hash(*)
+  {}
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Reflection.html b/ActiveModel/Serializer/Reflection.html new file mode 100644 index 00000000..f8cb7e3d --- /dev/null +++ b/ActiveModel/Serializer/Reflection.html @@ -0,0 +1,738 @@ + + + + + + Class: ActiveModel::Serializer::Reflection + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::Reflection + + + +

+ +
+ +
Inherits:
+
+ Field + +
    +
  • Object
  • + + + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/reflection.rb
+ +
+
+ +

Overview

+
+ +

Holds all the meta-data about an association as it was specified in the +ActiveModel::Serializer class.

+ +
Specifically, the association 'comments' is evaluated two different ways:
+1) as 'comments' and named 'comments'.
+2) as 'object.comments.last(1)' and named 'last_comments'.
+
+PostSerializer._reflections #=>
+  # [
+  #   HasOneReflection.new(:author, serializer: AuthorSerializer),
+  #   HasManyReflection.new(:comments)
+  #   HasManyReflection.new(:comments, { key: :last_comments }, #<Block>)
+  #   HasManyReflection.new(:secret_meta_data, { if: :is_admin? })
+  # ]
+ +

So you can inspect reflections in your Adapters.

+ + +
+
+
+ +
+

Examples:

+ + +
class PostSerializer < ActiveModel::Serializer
+  has_one :author, serializer: AuthorSerializer
+  has_many :comments
+  has_many :comments, key: :last_comments do
+    object.comments.last(1)
+  end
+  has_many :secret_meta_data, if: :is_admin?
+
+  def is_admin?
+    current_user.admin?
+  end
+end
+ +
+ + +
+

Direct Known Subclasses

+

CollectionReflection, SingularReflection

+
+ + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Field

+

#block, #name, #options

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + +
+

Constructor Details

+ +
+

+ + - (Reflection) initialize + + + + + +

+
+ +

Returns a new instance of Reflection

+ + +
+
+
+ + +
+ + + + +
+
+
+
+37
+38
+39
+40
+41
+42
+
+
# File 'lib/active_model/serializer/reflection.rb', line 37
+
+def initialize(*)
+  super
+  @_links = {}
+  @_include_data = true
+  @_meta = nil
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) build_association(subject, parent_serializer_options) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ +

Build association. This method is used internally to build serializer's +association by its reflection.

+ + +
+
+
+ +
+

Examples:

+ + +
# Given the following serializer defined:
+class PostSerializer < ActiveModel::Serializer
+  has_many :comments, serializer: CommentSummarySerializer
+end
+
+# Then you instantiate your serializer
+post_serializer = PostSerializer.new(post, foo: 'bar') #
+# to build association for comments you need to get reflection
+comments_reflection = PostSerializer._reflections.detect { |r| r.name == :comments }
+# and #build_association
+comments_reflection.build_association(post_serializer, foo: 'bar')
+ +
+

Parameters:

+
    + +
  • + + subject + + + (Serializer) + + + + — +
    +

    is a parent serializer for given association

    +
    + +
  • + +
  • + + parent_serializer_options + + + (Hash{Symbol => Object}) + + + +
  • + +
+ + +
+ + + + +
+
+
+
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+
+
# File 'lib/active_model/serializer/reflection.rb', line 109
+
+def build_association(subject, parent_serializer_options)
+  association_value = value(subject)
+  reflection_options = options.dup
+  serializer_class = subject.class.serializer_for(association_value, reflection_options)
+  reflection_options[:include_data] = @_include_data
+
+  if serializer_class
+    begin
+      serializer = serializer_class.new(
+        association_value,
+        serializer_options(subject, parent_serializer_options, reflection_options)
+      )
+    rescue ActiveModel::Serializer::CollectionSerializer::NoSerializerError
+      reflection_options[:virtual_value] = association_value.try(:as_json) || association_value
+    end
+  elsif !association_value.nil? && !association_value.instance_of?(Object)
+    reflection_options[:virtual_value] = association_value
+  end
+
+  Association.new(name, serializer, reflection_options, @_links, @_meta)
+end
+
+
+ +
+

+ + - (Object) include_data(value = true) + + + + + +

+ + + + +
+
+
+
+54
+55
+56
+57
+
+
# File 'lib/active_model/serializer/reflection.rb', line 54
+
+def include_data(value = true)
+  @_include_data = value
+  :nil
+end
+
+
+ +
+ + + + + +
+
+
+
+44
+45
+46
+47
+
+
# File 'lib/active_model/serializer/reflection.rb', line 44
+
+def link(name, value = nil, &block)
+  @_links[name] = block || value
+  :nil
+end
+
+
+ +
+

+ + - (Object) meta(value = nil, &block) + + + + + +

+ + + + +
+
+
+
+49
+50
+51
+52
+
+
# File 'lib/active_model/serializer/reflection.rb', line 49
+
+def meta(value = nil, &block)
+  @_meta = block || value
+  :nil
+end
+
+
+ +
+

+ + - (:nil, associated resource or resource collection) value(serializer) {|ActiveModel::Serializer| ... } + + + + + +

+
+ + +
+
+
+ +
+

Examples:

+ + +
has_one :blog do |serializer|
+  serializer.cached_blog
+end
+
+def cached_blog
+  cache_store.fetch("cached_blog:#{object.updated_at}") do
+    Blog.find(object.blog_id)
+  end
+end
+ +
+

Parameters:

+ + +

Yields:

+ +

Returns:

+
    + +
  • + + + (:nil, associated resource or resource collection) + + + +
  • + +
+ +
+ + + + +
+
+
+
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+
+
# File 'lib/active_model/serializer/reflection.rb', line 72
+
+def value(serializer)
+  @object = serializer.object
+  @scope = serializer.scope
+
+  if block
+    block_value = instance_exec(serializer, &block)
+    if block_value != :nil
+      block_value
+    elsif @_include_data
+      serializer.read_attribute_for_serialization(name)
+    end
+  else
+    serializer.read_attribute_for_serialization(name)
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/SingularReflection.html b/ActiveModel/Serializer/SingularReflection.html new file mode 100644 index 00000000..8fd952d9 --- /dev/null +++ b/ActiveModel/Serializer/SingularReflection.html @@ -0,0 +1,172 @@ + + + + + + Class: ActiveModel::Serializer::SingularReflection + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModel::Serializer::SingularReflection + + + Private +

+ +
+ +
Inherits:
+
+ Reflection + +
    +
  • Object
  • + + + + + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model/serializer/singular_reflection.rb
+ +
+
+ +
+
+

+ This class is part of a private API. + You should avoid using this class if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+

Direct Known Subclasses

+

BelongsToReflection, HasOneReflection

+
+ + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Field

+

#block, #name, #options

+ + + + + + + + + +

Method Summary

+ +

Methods inherited from Reflection

+

#build_association, #include_data, #initialize, #link, #meta, #value

+ + + + + + + +
+

Constructor Details

+ +

This class inherits a constructor from ActiveModel::Serializer::Reflection

+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Type.html b/ActiveModel/Serializer/Type.html new file mode 100644 index 00000000..d348a2bc --- /dev/null +++ b/ActiveModel/Serializer/Type.html @@ -0,0 +1,124 @@ + + + + + + Module: ActiveModel::Serializer::Type + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Type + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + + + +
Included in:
+
ActiveModel::Serializer
+ + + +
Defined in:
+
lib/active_model/serializer/type.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: ClassMethods + + + + +

+ + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModel/Serializer/Type/ClassMethods.html b/ActiveModel/Serializer/Type/ClassMethods.html new file mode 100644 index 00000000..90bbed4a --- /dev/null +++ b/ActiveModel/Serializer/Type/ClassMethods.html @@ -0,0 +1,196 @@ + + + + + + Module: ActiveModel::Serializer::Type::ClassMethods + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModel::Serializer::Type::ClassMethods + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model/serializer/type.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) type(type) + + + + + +

+
+ +

Set the JSON API type of a serializer.

+ + +
+
+
+ +
+

Examples:

+ + +
class AdminAuthorSerializer < ActiveModel::Serializer
+  type 'authors'
+ +
+ + +
+ + + + +
+
+
+
+19
+20
+21
+
+
# File 'lib/active_model/serializer/type.rb', line 19
+
+def type(type)
+  self._type = type && type.to_s
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers.html b/ActiveModelSerializers.html new file mode 100644 index 00000000..8aed693d --- /dev/null +++ b/ActiveModelSerializers.html @@ -0,0 +1,462 @@ + + + + + + Module: ActiveModelSerializers + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Autoload
+ + + + + + + +
Defined in:
+
lib/active_model_serializers/model.rb,
+ lib/active_model_serializers.rb,
lib/active_model_serializers/test.rb,
lib/active_model_serializers/railtie.rb,
lib/active_model_serializers/adapter.rb,
lib/active_model_serializers/logging.rb,
lib/active_model_serializers/deprecate.rb,
lib/active_model_serializers/callbacks.rb,
lib/active_model_serializers/test/schema.rb,
lib/active_model_serializers/adapter/base.rb,
lib/active_model_serializers/adapter/json.rb,
lib/active_model_serializers/json_pointer.rb,
lib/active_model_serializers/adapter/null.rb,
lib/active_model_serializers/key_transform.rb,
lib/active_model_serializers/deserialization.rb,
lib/active_model_serializers/test/serializer.rb,
lib/active_model_serializers/adapter/json_api.rb,
lib/active_model_serializers/adapter/attributes.rb,
lib/active_model_serializers/serializable_resource.rb,
lib/active_model_serializers/adapter/json_api/meta.rb,
lib/active_model_serializers/serialization_context.rb,
lib/active_model_serializers/adapter/json_api/link.rb,
lib/active_model_serializers/adapter/json_api/error.rb,
lib/active_model_serializers/adapter/json_api/jsonapi.rb,
lib/active_model_serializers/adapter/json_api/relationship.rb,
lib/active_model_serializers/adapter/json_api/deserialization.rb,
lib/active_model_serializers/adapter/json_api/pagination_links.rb,
lib/active_model_serializers/adapter/json_api/resource_identifier.rb
+
+ +
+
+ +

Overview

+
+ +

JSON API specification rubocop:disable +Style/AsciiComments TODO: implement!

+ +
 https://github.com/rails-api/active_model_serializers/issues/1235
+ +

TODO: use uri_template in link generation?

+ +
☐ https://github.com/rails-api/active_model_serializers/pull/1282#discussion_r42528812
+  see gem https://github.com/hannesg/uri_template
+  spec http://tools.ietf.org/html/rfc6570
+  impl https://developer.github.com/v3/#schema https://api.github.com/
+ +

TODO: validate against a JSON schema document?

+ +
 https://github.com/rails-api/active_model_serializers/issues/1162
+ https://github.com/rails-api/active_model_serializers/pull/1270
+ +

TODO: Routing

+ +
 https://github.com/rails-api/active_model_serializers/pull/1476
+ +

TODO: Query Params

+ +
☑ `include` https://github.com/rails-api/active_model_serializers/pull/1131
+☑ `fields` https://github.com/rails-api/active_model_serializers/pull/700
+☑ `page[number]=3&page[size]=1` https://github.com/rails-api/active_model_serializers/pull/1041
+☐ `filter`
+☐ `sort`
+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + Modules: Adapter, Callbacks, Deprecate, Deserialization, JsonPointer, Jsonapi, KeyTransform, Logging, Test + + + + Classes: Model, Railtie, SerializableResource, SerializationContext + + +

+ + + + +

Class Attribute Summary (collapse)

+ + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Attribute Details

+ + + +
+

+ + + (Object) logger + + + + + +

+
+ +

Returns the value of attribute logger

+ + +
+
+
+ + +
+ + + + +
+
+
+
+18
+19
+20
+
+
# File 'lib/active_model_serializers.rb', line 18
+
+def logger
+  @logger
+end
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + + (Object) config + + + + + +

+ + + + +
+
+
+
+21
+22
+23
+
+
# File 'lib/active_model_serializers.rb', line 21
+
+def self.config
+  ActiveModel::Serializer.config
+end
+
+
+ +
+

+ + + (JSONAPI::IncludeDirective) default_include_directive + + + + + +

+
+ +

Memoized default include directive

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (JSONAPI::IncludeDirective) + + + +
  • + +
+ +
+ + + + +
+
+
+
+36
+37
+38
+
+
# File 'lib/active_model_serializers.rb', line 36
+
+def self.default_include_directive
+  @default_include_directive ||= JSONAPI::IncludeDirective.new(config.default_includes, allow_wildcard: true)
+end
+
+
+ +
+

+ + + (Object) location_of_caller + + + + + +

+
+ +

The file name and line number of the caller of the caller of this method.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+26
+27
+28
+29
+30
+31
+32
+
+
# File 'lib/active_model_serializers.rb', line 26
+
+def self.location_of_caller
+  caller[1] =~ /(.*?):(\d+).*?$/i
+  file = Regexp.last_match(1)
+  lineno = Regexp.last_match(2).to_i
+
+  [file, lineno]
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter.html b/ActiveModelSerializers/Adapter.html new file mode 100644 index 00000000..f4a18a03 --- /dev/null +++ b/ActiveModelSerializers/Adapter.html @@ -0,0 +1,887 @@ + + + + + + Module: ActiveModelSerializers::Adapter + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Adapter + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Autoload
+ + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter.rb,
+ lib/active_model_serializers/adapter/base.rb,
lib/active_model_serializers/adapter/json.rb,
lib/active_model_serializers/adapter/null.rb,
lib/active_model_serializers/adapter/json_api.rb,
lib/active_model_serializers/adapter/attributes.rb,
lib/active_model_serializers/adapter/json_api/meta.rb,
lib/active_model_serializers/adapter/json_api/link.rb,
lib/active_model_serializers/adapter/json_api/error.rb,
lib/active_model_serializers/adapter/json_api/jsonapi.rb,
lib/active_model_serializers/adapter/json_api/relationship.rb,
lib/active_model_serializers/adapter/json_api/deserialization.rb,
lib/active_model_serializers/adapter/json_api/pagination_links.rb,
lib/active_model_serializers/adapter/json_api/resource_identifier.rb
+
+ +
+
+ +

Defined Under Namespace

+

+ + + + + Classes: Attributes, Base, Json, JsonApi, Null + + +

+ +

Constant Summary

+ +
+ +
UnknownAdapterError = + +
+
Class.new(ArgumentError)
+ +
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) adapter_class(adapter) + + + + + +

+
+ + +
+
+
+ + +

See Also:

+ + +
+ + + + +
+
+
+
+27
+28
+29
+
+
# File 'lib/active_model_serializers/adapter.rb', line 27
+
+def adapter_class(adapter)
+  ActiveModelSerializers::Adapter.lookup(adapter)
+end
+
+
+ +
+

+ + + (Hash<adapter_name, adapter_class>) adapter_map + + + + + +

+
+ + +
+
+
+ +

Returns:

+ + +
+ + + + +
+
+
+
+32
+33
+34
+
+
# File 'lib/active_model_serializers/adapter.rb', line 32
+
+def adapter_map
+  ADAPTER_MAP
+end
+
+
+ +
+

+ + + (Array<Symbol>) adapters + + + + + +

+
+ +

Returns list of adapter names

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Array<Symbol>) + + + + — +
    +

    list of adapter names

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+37
+38
+39
+
+
# File 'lib/active_model_serializers/adapter.rb', line 37
+
+def adapters
+  adapter_map.keys.sort
+end
+
+
+ +
+

+ + + (Object) configured_adapter + + + + + +

+
+ +

:nocov:

+ + +
+
+
+ + +
+ + + + +
+
+
+
+16
+17
+18
+
+
# File 'lib/active_model_serializers/adapter.rb', line 16
+
+def configured_adapter
+  lookup(ActiveModelSerializers.config.adapter)
+end
+
+
+ +
+

+ + + (Object) create(resource, options = {}) + + + + + +

+ + + + +
+
+
+
+20
+21
+22
+23
+24
+
+
# File 'lib/active_model_serializers/adapter.rb', line 20
+
+def create(resource, options = {})
+  override = options.delete(:adapter)
+  klass = override ? adapter_class(override) : configured_adapter
+  klass.new(resource, options)
+end
+
+
+ +
+

+ + + (ActiveModelSerializers::Adapter) lookup(adapter) + + + + + +

+
+ +

Returns subclass of Adapter

+ + +
+
+
+

Parameters:

+
    + +
  • + + adapter + + + (String, Symbol, Class) + + + + — +
    +

    name to fetch adapter by

    +
    + +
  • + +
+ +

Returns:

+ +

Raises:

+ + +
+ + + + +
+
+
+
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+
+
# File 'lib/active_model_serializers/adapter.rb', line 63
+
+def lookup(adapter)
+  # 1. return if is a class
+  return adapter if adapter.is_a?(Class)
+  adapter_name = adapter.to_s.underscore
+  # 2. return if registered
+  adapter_map.fetch(adapter_name) do
+    # 3. try to find adapter class from environment
+    adapter_class = find_by_name(adapter_name)
+    register(adapter_name, adapter_class)
+    adapter_class
+  end
+rescue NameError, ArgumentError => e
+  failure_message =
+    "NameError: #{e.message}. Unknown adapter: #{adapter.inspect}. Valid adapters are: #{adapters}"
+  raise UnknownAdapterError, failure_message, e.backtrace
+end
+
+
+ +
+

+ + + (Object) new(*args) + + + + + +

+
+ +

:nocov:

+ + +
+
+
+ + +
+ + + + +
+
+
+
+9
+10
+11
+12
+13
+
+
# File 'lib/active_model_serializers/adapter.rb', line 9
+
+def new(*args)
+  fail ArgumentError, 'Adapters inherit from Adapter::Base.' \
+    "Adapter.new called with args: '#{args.inspect}', from" \
+    "'caller[0]'."
+end
+
+
+ +
+

+ + + (Object) register(name, klass = name) + + + + + +

+
+ +
+ Note: +
+

The registered name strips out 'ActiveModelSerializers::Adapter::' +so that registering 'ActiveModelSerializers::Adapter::Json' and +'Json' will both register as 'json'.

+
+
+ + +

Adds an adapter 'klass' with 'name' to the +'adapter_map' Names are stringified and underscored

+ + +
+
+
+ +
+

Examples:

+ + +
AMS::Adapter.register(:my_adapter, MyAdapter)
+ +
+

Parameters:

+
    + +
  • + + name + + + (Symbol, String, Class) + + + + — +
    +

    name of the registered adapter

    +
    + +
  • + +
  • + + klass + + + (Class) + + + (defaults to: name) + + + — +
    +

    adapter class itself, optional if name is the class

    +
    + +
  • + +
+ + +
+ + + + +
+
+
+
+50
+51
+52
+53
+54
+
+
# File 'lib/active_model_serializers/adapter.rb', line 50
+
+def register(name, klass = name)
+  name = name.to_s.gsub(/\AActiveModelSerializers::Adapter::/, ''.freeze)
+  adapter_map[name.underscore] = klass
+  self
+end
+
+
+ +
+

+ + + (Object) registered_name(adapter_class) + + + + + +

+ + + + +
+
+
+
+56
+57
+58
+
+
# File 'lib/active_model_serializers/adapter.rb', line 56
+
+def registered_name(adapter_class)
+  ADAPTER_MAP.key adapter_class
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/Attributes.html b/ActiveModelSerializers/Adapter/Attributes.html new file mode 100644 index 00000000..7009a7d1 --- /dev/null +++ b/ActiveModelSerializers/Adapter/Attributes.html @@ -0,0 +1,221 @@ + + + + + + Class: ActiveModelSerializers::Adapter::Attributes + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::Attributes + + + +

+ +
+ +
Inherits:
+
+ Base + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/attributes.rb
+ +
+
+ +
+

Direct Known Subclasses

+

ActiveModel::Serializer::Adapter::Attributes

+
+ + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Base

+

#instance_options, #serializer

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods inherited from Base

+

#as_json, cache_key, #cache_key, default_key_transform, #fragment_cache, fragment_cache, inherited, #initialize, transform, transform_key_casing!

+
+

Constructor Details

+ +

This class inherits a constructor from ActiveModelSerializers::Adapter::Base

+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) serializable_hash(options = nil) + + + + + +

+ + + + +
+
+
+
+4
+5
+6
+7
+8
+
+
# File 'lib/active_model_serializers/adapter/attributes.rb', line 4
+
+def serializable_hash(options = nil)
+  options = serialization_options(options)
+  options[:fields] ||= instance_options[:fields]
+  serializer.serializable_hash(instance_options, options, self)
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/Base.html b/ActiveModelSerializers/Adapter/Base.html new file mode 100644 index 00000000..7305c021 --- /dev/null +++ b/ActiveModelSerializers/Adapter/Base.html @@ -0,0 +1,1082 @@ + + + + + + Class: ActiveModelSerializers::Adapter::Base + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::Base + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/base.rb
+ +
+
+ +
+

Direct Known Subclasses

+

ActiveModel::Serializer::Adapter::Base, Attributes, Json, JsonApi, Null

+
+ + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Class Method Summary + (collapse) +

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Base) initialize(serializer, options = {}) + + + + + +

+
+ +

Returns a new instance of Base

+ + +
+
+
+ + +
+ + + + +
+
+
+
+47
+48
+49
+50
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 47
+
+def initialize(serializer, options = {})
+  @serializer = serializer
+  @instance_options = options
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) instance_options (readonly) + + + + + +

+
+ +

Returns the value of attribute instance_options

+ + +
+
+
+ + +
+ + + + +
+
+
+
+45
+46
+47
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 45
+
+def instance_options
+  @instance_options
+end
+
+
+ + + +
+

+ + - (Object) serializer (readonly) + + + + + +

+
+ +

Returns the value of attribute serializer

+ + +
+
+
+ + +
+ + + + +
+
+
+
+45
+46
+47
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 45
+
+def serializer
+  @serializer
+end
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + + (Object) cache_key + + + + + +

+ + + + +
+
+
+
+37
+38
+39
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 37
+
+def self.cache_key
+  @cache_key ||= ActiveModelSerializers::Adapter.registered_name(self)
+end
+
+
+ +
+

+ + + (Symbol) default_key_transform + + + + + +

+
+ +

Sets the default transform for the adapter.

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Symbol) + + + + — +
    +

    the default transform for the adapter

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+14
+15
+16
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 14
+
+def self.default_key_transform
+  :unaltered
+end
+
+
+ +
+

+ + + (Object) fragment_cache(cached_hash, non_cached_hash) + + + + + +

+ + + + +
+
+
+
+41
+42
+43
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 41
+
+def self.fragment_cache(cached_hash, non_cached_hash)
+  non_cached_hash.merge cached_hash
+end
+
+
+ +
+

+ + + (Object) inherited(subclass) + + + + + +

+
+ +

Automatically register adapters when subclassing

+ + +
+
+
+ + +
+ + + + +
+
+
+
+7
+8
+9
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 7
+
+def self.inherited(subclass)
+  ActiveModelSerializers::Adapter.register(subclass)
+end
+
+
+ +
+

+ + + (Symbol) transform(options) + + + + + +

+
+ +

Determines the transform to use in order of precedence:

+ +
adapter option, global config, adapter default.
+ + +
+
+
+

Parameters:

+
    + +
  • + + options + + + (Object) + + + +
  • + +
+ +

Returns:

+
    + +
  • + + + (Symbol) + + + + — +
    +

    the transform to use

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+23
+24
+25
+26
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 23
+
+def self.transform(options)
+  return options[:key_transform] if options && options[:key_transform]
+  ActiveModelSerializers.config.key_transform || default_key_transform
+end
+
+
+ +
+

+ + + (Symbol) transform_key_casing!(value, options) + + + + + +

+
+ +

Transforms the casing of the supplied value.

+ + +
+
+
+

Parameters:

+
    + +
  • + + value + + + (Object) + + + + — +
    +

    the value to be transformed

    +
    + +
  • + +
  • + + options + + + (Object) + + + + — +
    +

    serializable resource options

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (Symbol) + + + + — +
    +

    the default transform for the adapter

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+33
+34
+35
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 33
+
+def self.transform_key_casing!(value, options)
+  KeyTransform.send(transform(options), value)
+end
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + - (Object) as_json(options = nil) + + + + + +

+ + + + +
+
+
+
+58
+59
+60
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 58
+
+def as_json(options = nil)
+  serializable_hash(options)
+end
+
+
+ +
+

+ + - (Object) cache_key + + + + + +

+ + + + +
+
+
+
+62
+63
+64
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 62
+
+def cache_key
+  self.class.cache_key
+end
+
+
+ +
+

+ + - (Object) fragment_cache(cached_hash, non_cached_hash) + + + + + +

+ + + + +
+
+
+
+66
+67
+68
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 66
+
+def fragment_cache(cached_hash, non_cached_hash)
+  self.class.fragment_cache(cached_hash, non_cached_hash)
+end
+
+
+ +
+

+ + - (Object) serializable_hash(_options = nil) + + + + + +

+
+ +

Subclasses that implement this method must first call

+ +
options = serialization_options(options)
+
+ + +
+
+
+ + +
+ + + + +
+
+
+
+54
+55
+56
+
+
# File 'lib/active_model_serializers/adapter/base.rb', line 54
+
+def serializable_hash(_options = nil)
+  fail NotImplementedError, 'This is an abstract method. Should be implemented at the concrete adapter.'
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/Json.html b/ActiveModelSerializers/Adapter/Json.html new file mode 100644 index 00000000..7e5d2834 --- /dev/null +++ b/ActiveModelSerializers/Adapter/Json.html @@ -0,0 +1,329 @@ + + + + + + Class: ActiveModelSerializers::Adapter::Json + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::Json + + + +

+ +
+ +
Inherits:
+
+ Base + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json.rb
+ +
+
+ +
+

Direct Known Subclasses

+

ActiveModel::Serializer::Adapter::Json

+
+ + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Base

+

#instance_options, #serializer

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods inherited from Base

+

#as_json, cache_key, #cache_key, default_key_transform, #fragment_cache, fragment_cache, inherited, #initialize, transform, transform_key_casing!

+
+

Constructor Details

+ +

This class inherits a constructor from ActiveModelSerializers::Adapter::Base

+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) meta + + + + + +

+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/active_model_serializers/adapter/json.rb', line 12
+
+def meta
+  instance_options.fetch(:meta, nil)
+end
+
+
+ +
+

+ + - (Object) meta_key + + + + + +

+ + + + +
+
+
+
+16
+17
+18
+
+
# File 'lib/active_model_serializers/adapter/json.rb', line 16
+
+def meta_key
+  instance_options.fetch(:meta_key, 'meta'.freeze)
+end
+
+
+ +
+

+ + - (Object) serializable_hash(options = nil) + + + + + +

+ + + + +
+
+
+
+4
+5
+6
+7
+8
+9
+10
+
+
# File 'lib/active_model_serializers/adapter/json.rb', line 4
+
+def serializable_hash(options = nil)
+  options = serialization_options(options)
+  serialized_hash = { root => Attributes.new(serializer, instance_options).serializable_hash(options) }
+  serialized_hash[meta_key] = meta unless meta.blank?
+
+  self.class.transform_key_casing!(serialized_hash, instance_options)
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/JsonApi.html b/ActiveModelSerializers/Adapter/JsonApi.html new file mode 100644 index 00000000..6dc51698 --- /dev/null +++ b/ActiveModelSerializers/Adapter/JsonApi.html @@ -0,0 +1,860 @@ + + + + + + Class: ActiveModelSerializers::Adapter::JsonApi + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::JsonApi + + + +

+ +
+ +
Inherits:
+
+ Base + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + +
Extended by:
+
ActiveSupport::Autoload
+ + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json_api.rb,
+ lib/active_model_serializers/adapter/json_api/meta.rb,
lib/active_model_serializers/adapter/json_api/link.rb,
lib/active_model_serializers/adapter/json_api/error.rb,
lib/active_model_serializers/adapter/json_api/jsonapi.rb,
lib/active_model_serializers/adapter/json_api/relationship.rb,
lib/active_model_serializers/adapter/json_api/deserialization.rb,
lib/active_model_serializers/adapter/json_api/pagination_links.rb,
lib/active_model_serializers/adapter/json_api/resource_identifier.rb
+
+ +
+
+ +
+

Direct Known Subclasses

+

ActiveModel::Serializer::Adapter::JsonApi

+
+

Defined Under Namespace

+

+ + + Modules: Deserialization, Error, Jsonapi + + + + Classes: Link, Meta, PaginationLinks, Relationship, ResourceIdentifier + + +

+ + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Base

+

#instance_options, #serializer

+ + + +

+ Class Method Summary + (collapse) +

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + + +

Methods inherited from Base

+

#as_json, #cache_key, cache_key, inherited, transform, transform_key_casing!

+
+

Constructor Details

+ +
+

+ + - (JsonApi) initialize(serializer, options = {}) + + + + + +

+
+ +

Returns a new instance of JsonApi

+ + +
+
+
+ + +
+ + + + +
+
+
+
+49
+50
+51
+52
+53
+
+
# File 'lib/active_model_serializers/adapter/json_api.rb', line 49
+
+def initialize(serializer, options = {})
+  super
+  @include_directive = JSONAPI::IncludeDirective.new(options[:include], allow_wildcard: true)
+  @fieldset = options[:fieldset] || ActiveModel::Serializer::Fieldset.new(options.delete(:fields))
+end
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + + (Object) default_key_transform + + + + + +

+ + + + +
+
+
+
+34
+35
+36
+
+
# File 'lib/active_model_serializers/adapter/json_api.rb', line 34
+
+def self.default_key_transform
+  :dash
+end
+
+
+ +
+

+ + + (Object) fragment_cache(cached_hash, non_cached_hash, root = true) + + + + + +

+ + + + +
+
+
+
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+
+
# File 'lib/active_model_serializers/adapter/json_api.rb', line 38
+
+def self.fragment_cache(cached_hash, non_cached_hash, root = true)
+  core_cached       = cached_hash.first
+  core_non_cached   = non_cached_hash.first
+  no_root_cache     = cached_hash.delete_if { |key, _value| key == core_cached[0] }
+  no_root_non_cache = non_cached_hash.delete_if { |key, _value| key == core_non_cached[0] }
+  cached_resource   = (core_cached[1]) ? core_cached[1].deep_merge(core_non_cached[1]) : core_non_cached[1]
+  hash = root ? { root => cached_resource } : cached_resource
+
+  hash.deep_merge no_root_non_cache.deep_merge no_root_cache
+end
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + - (Object) failure_document + + + + + +

+
+ +

JSON API Errors TODO: look into caching +definition:

+ +
 toplevel_errors array (required)
+ toplevel_meta
+ toplevel_jsonapi
+
+ +

structure:

+ +
{
+  errors: toplevel_errors,
+  meta: toplevel_meta,
+  jsonapi: toplevel_jsonapi
+}.reject! {|_,v| v.nil? }
+
+ +

prs:

+ +
https://github.com/rails-api/active_model_serializers/pull/1004
+
+ + +
+
+
+ + +
+ + + + +
+
+
+
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+
+
# File 'lib/active_model_serializers/adapter/json_api.rb', line 170
+
+def failure_document
+  hash = {}
+  # PR Please :)
+  # Jsonapi.add!(hash)
+
+  # toplevel_errors
+  # definition:
+  #   array of unique items of type 'error'
+  # structure:
+  #   [
+  #     error,
+  #     error
+  #   ]
+  if serializer.respond_to?(:each)
+    hash[:errors] = serializer.flat_map do |error_serializer|
+      Error.resource_errors(error_serializer, instance_options)
+    end
+  else
+    hash[:errors] = Error.resource_errors(serializer, instance_options)
+  end
+  hash
+end
+
+
+ +
+

+ + - (Object) fragment_cache(cached_hash, non_cached_hash) + + + + + +

+ + + + +
+
+
+
+66
+67
+68
+69
+
+
# File 'lib/active_model_serializers/adapter/json_api.rb', line 66
+
+def fragment_cache(cached_hash, non_cached_hash)
+  root = !instance_options.include?(:include)
+  self.class.fragment_cache(cached_hash, non_cached_hash, root)
+end
+
+
+ +
+

+ + - (Object) serializable_hash + + + + + +

+
+ + +
+ + + + +
+
+
+
+57
+58
+59
+60
+61
+62
+63
+64
+
+
# File 'lib/active_model_serializers/adapter/json_api.rb', line 57
+
+def serializable_hash(*)
+  document = if serializer.success?
+               success_document
+             else
+               failure_document
+             end
+  self.class.transform_key_casing!(document, instance_options)
+end
+
+
+ +
+

+ + - (Object) success_document + + + + + +

+
+ +

Primary data definition:

+ +
 toplevel_data (required)
+ toplevel_included
+ toplevel_meta
+ toplevel_links
+ toplevel_jsonapi
+
+ +

structure:

+ +
{
+  data: toplevel_data,
+  included: toplevel_included,
+  meta: toplevel_meta,
+  links: toplevel_links,
+  jsonapi: toplevel_jsonapi
+}.reject! {|_,v| v.nil? }
+
+ +

rubocop:disable Metrics/CyclomaticComplexity

+ + +
+
+
+ + +
+ + + + +
+
+
+
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+
+
# File 'lib/active_model_serializers/adapter/json_api.rb', line 87
+
+def success_document
+  is_collection = serializer.respond_to?(:each)
+  serializers = is_collection ? serializer : [serializer]
+  primary_data, included = resource_objects_for(serializers)
+
+  hash = {}
+  # toplevel_data
+  # definition:
+  #   oneOf
+  #     resource
+  #     array of unique items of type 'resource'
+  #     null
+  #
+  # description:
+  #   The document's "primary data" is a representation of the resource or collection of resources
+  #   targeted by a request.
+  #
+  #   Singular: the resource object.
+  #
+  #   Collection: one of an array of resource objects, an array of resource identifier objects, or
+  #   an empty array ([]), for requests that target resource collections.
+  #
+  #   None: null if the request is one that might correspond to a single resource, but doesn't currently.
+  # structure:
+  #  if serializable_resource.resource?
+  #    resource
+  #  elsif serializable_resource.collection?
+  #    [
+  #      resource,
+  #      resource
+  #    ]
+  #  else
+  #    nil
+  #  end
+  hash[:data] = is_collection ? primary_data : primary_data[0]
+  # toplevel_included
+  #   alias included
+  # definition:
+  #   array of unique items of type 'resource'
+  #
+  # description:
+  #   To reduce the number of HTTP requests, servers **MAY** allow
+  #   responses that include related resources along with the requested primary
+  #   resources. Such responses are called "compound documents".
+  # structure:
+  #     [
+  #       resource,
+  #       resource
+  #     ]
+  hash[:included] = included if included.any?
+
+  Jsonapi.add!(hash)
+
+  if instance_options[:links]
+    hash[:links] ||= {}
+    hash[:links].update(instance_options[:links])
+  end
+
+  if is_collection && serializer.paginated?
+    hash[:links] ||= {}
+    hash[:links].update(pagination_links_for(serializer))
+  end
+
+  hash[:meta] = instance_options[:meta] unless instance_options[:meta].blank?
+
+  hash
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/JsonApi/Deserialization.html b/ActiveModelSerializers/Adapter/JsonApi/Deserialization.html new file mode 100644 index 00000000..16dc0117 --- /dev/null +++ b/ActiveModelSerializers/Adapter/JsonApi/Deserialization.html @@ -0,0 +1,1059 @@ + + + + + + Module: ActiveModelSerializers::Adapter::JsonApi::Deserialization + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Adapter::JsonApi::Deserialization + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json_api/deserialization.rb
+ +
+
+ +

Overview

+
+ +

NOTE(Experimental): This is an experimental feature. Both the interface and +internals could be subject to changes.

+ + +
+
+
+ + +
+

Constant Summary

+ +
+ +
InvalidDocument = + +
+
Class.new(ArgumentError)
+ +
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) field_key(field, options) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+152
+153
+154
+
+
# File 'lib/active_model_serializers/adapter/json_api/deserialization.rb', line 152
+
+def field_key(field, options)
+  (options[:keys] || {}).fetch(field.to_sym, field).to_sym
+end
+
+
+ +
+

+ + + (Object) filter_fields(fields, options) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+143
+144
+145
+146
+147
+148
+149
+
+
# File 'lib/active_model_serializers/adapter/json_api/deserialization.rb', line 143
+
+def filter_fields(fields, options)
+  if (only = options[:only])
+    fields.slice!(*Array(only).map(&:to_s))
+  elsif (except = options[:except])
+    fields.except!(*Array(except).map(&:to_s))
+  end
+end
+
+
+ +
+

+ + + (Object) parse(document, options = {}) + + + + + +

+
+ +

Same as parse!, but returns an empty hash instead of raising +InvalidDocument on invalid payloads.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
+101
+102
+103
+104
+
+
# File 'lib/active_model_serializers/adapter/json_api/deserialization.rb', line 83
+
+def parse(document, options = {})
+  document = document.dup.permit!.to_h if document.is_a?(ActionController::Parameters)
+
+  validate_payload(document) do |invalid_document, reason|
+    yield invalid_document, reason if block_given?
+    return {}
+  end
+
+  primary_data = document['data']
+  attributes = primary_data['attributes'] || {}
+  attributes['id'] = primary_data['id'] if primary_data['id']
+  relationships = primary_data['relationships'] || {}
+
+  filter_fields(attributes, options)
+  filter_fields(relationships, options)
+
+  hash = {}
+  hash.merge!(parse_attributes(attributes, options))
+  hash.merge!(parse_relationships(relationships, options))
+
+  hash
+end
+
+
+ +
+

+ + + (Hash) parse!(document, options = {}) + + + + + +

+
+ +

Transform a JSON API document, containing a single data object, into a hash +that is ready for ActiveRecord::Base.new() and such. Raises InvalidDocument +if the payload is not properly formatted.

+ + +
+
+
+ +
+

Examples:

+ + +
document = {
+  data: {
+    id: 1,
+    type: 'post',
+    attributes: {
+      title: 'Title 1',
+      date: '2015-12-20'
+    },
+    associations: {
+      author: {
+        data: {
+          type: 'user',
+          id: 2
+        }
+      },
+      second_author: {
+        data: nil
+      },
+      comments: {
+        data: [{
+          type: 'comment',
+          id: 3
+        },{
+          type: 'comment',
+          id: 4
+        }]
+      }
+    }
+  }
+}
+
+parse(document) #=>
+  # {
+  #   title: 'Title 1',
+  #   date: '2015-12-20',
+  #   author_id: 2,
+  #   second_author_id: nil
+  #   comment_ids: [3, 4]
+  # }
+
+parse(document, only: [:title, :date, :author],
+                keys: { date: :published_at },
+                polymorphic: [:author]) #=>
+  # {
+  #   title: 'Title 1',
+  #   published_at: '2015-12-20',
+  #   author_id: '2',
+  #   author_type: 'people'
+  # }
+ +
+

Parameters:

+
    + +
  • + + document + + + (Hash|ActionController::Parameters) + + + +
  • + +
  • + + options + + + (Hash) + + + (defaults to: {}) + + + — +
    +

    only: Array of symbols of whitelisted fields. except: Array of symbols of +blacklisted fields. keys: Hash of translated keys (e.g. :author => +:user). polymorphic: Array of symbols of polymorphic fields.

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (Hash) + + + +
  • + +
+ +
+ + + + +
+
+
+
+75
+76
+77
+78
+79
+
+
# File 'lib/active_model_serializers/adapter/json_api/deserialization.rb', line 75
+
+def parse!(document, options = {})
+  parse(document, options) do |invalid_payload, reason|
+    fail InvalidDocument, "Invalid payload (#{reason}): #{invalid_payload}"
+  end
+end
+
+
+ +
+

+ + + (Object) parse_attributes(attributes, options) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+157
+158
+159
+160
+161
+
+
# File 'lib/active_model_serializers/adapter/json_api/deserialization.rb', line 157
+
+def parse_attributes(attributes, options)
+  transform_keys(attributes, options)
+    .map { |(k, v)| { field_key(k, options) => v } }
+    .reduce({}, :merge)
+end
+
+
+ +
+

+ + + (Hash{Symbol, Object}) parse_relationship(assoc_name, assoc_data, options) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ +

Given an association name, and a relationship data attribute, build a hash +mapping the corresponding ActiveRecord attribute to the corresponding +value.

+ + +
+
+
+ +
+

Examples:

+ + +
parse_relationship(:comments, [{ 'id' => '1', 'type' => 'comments' },
+                               { 'id' => '2', 'type' => 'comments' }],
+                              {})
+ # => { :comment_ids => ['1', '2'] }
+parse_relationship(:author, { 'id' => '1', 'type' => 'users' }, {})
+ # => { :author_id => '1' }
+parse_relationship(:author, nil, {})
+ # => { :author_id => nil }
+ +
+

Parameters:

+
    + +
  • + + assoc_name + + + (Symbol) + + + +
  • + +
  • + + assoc_data + + + (Hash) + + + +
  • + +
  • + + options + + + (Hash) + + + +
  • + +
+ +

Returns:

+
    + +
  • + + + (Hash{Symbol, Object}) + + + +
  • + +
+ +
+ + + + +
+
+
+
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+
+
# File 'lib/active_model_serializers/adapter/json_api/deserialization.rb', line 181
+
+def parse_relationship(assoc_name, assoc_data, options)
+  prefix_key = field_key(assoc_name, options).to_s.singularize
+  hash =
+    if assoc_data.is_a?(Array)
+      { "#{prefix_key}_ids".to_sym => assoc_data.map { |ri| ri['id'] } }
+    else
+      { "#{prefix_key}_id".to_sym => assoc_data ? assoc_data['id'] : nil }
+    end
+
+  polymorphic = (options[:polymorphic] || []).include?(assoc_name.to_sym)
+  if polymorphic
+    hash["#{prefix_key}_type".to_sym] = assoc_data.present? ? assoc_data['type'] : nil
+  end
+
+  hash
+end
+
+
+ +
+

+ + + (Object) parse_relationships(relationships, options) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+199
+200
+201
+202
+203
+
+
# File 'lib/active_model_serializers/adapter/json_api/deserialization.rb', line 199
+
+def parse_relationships(relationships, options)
+  transform_keys(relationships, options)
+    .map { |(k, v)| parse_relationship(k, v['data'], options) }
+    .reduce({}, :merge)
+end
+
+
+ +
+

+ + + (Object) transform_keys(hash, options) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ + +
+
+
+ + +
+ + + + +
+
+
+
+206
+207
+208
+209
+
+
# File 'lib/active_model_serializers/adapter/json_api/deserialization.rb', line 206
+
+def transform_keys(hash, options)
+  transform = options[:key_transform] || :underscore
+  KeyTransform.send(transform, hash)
+end
+
+
+ +
+

+ + + (Object) validate_payload(payload) + + + + + +

+
+

+ This method is part of a private API. + You should avoid using this method if possible, as it may be removed or be changed in the future. +

+ +

Checks whether a payload is compliant with the JSON API spec.

+ +

rubocop:disable Metrics/CyclomaticComplexity

+ + +
+
+
+ + +
+ + + + +
+
+
+
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+
+
# File 'lib/active_model_serializers/adapter/json_api/deserialization.rb', line 110
+
+def validate_payload(payload)
+  unless payload.is_a?(Hash)
+    yield payload, 'Expected hash'
+    return
+  end
+
+  primary_data = payload['data']
+  unless primary_data.is_a?(Hash)
+    yield payload, { data: 'Expected hash' }
+    return
+  end
+
+  attributes = primary_data['attributes'] || {}
+  unless attributes.is_a?(Hash)
+    yield payload, { data: { attributes: 'Expected hash or nil' } }
+    return
+  end
+
+  relationships = primary_data['relationships'] || {}
+  unless relationships.is_a?(Hash)
+    yield payload, { data: { relationships: 'Expected hash or nil' } }
+    return
+  end
+
+  relationships.each do |(key, value)|
+    unless value.is_a?(Hash) && value.key?('data')
+      yield payload, { data: { relationships: { key => 'Expected hash with :data key' } } }
+    end
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/JsonApi/Error.html b/ActiveModelSerializers/Adapter/JsonApi/Error.html new file mode 100644 index 00000000..7af45774 --- /dev/null +++ b/ActiveModelSerializers/Adapter/JsonApi/Error.html @@ -0,0 +1,471 @@ + + + + + + Module: ActiveModelSerializers::Adapter::JsonApi::Error + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Adapter::JsonApi::Error + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json_api/error.rb
+ +
+
+ + +

Constant Summary

+ +
+ +
UnknownSourceTypeError = +
+
+ +

rubocop:disable Style/AsciiComments

+ + +
+
+
+ + +
+
+
Class.new(ArgumentError)
+ +
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) attribute_error_objects(attribute_name, attribute_errors) + + + + + +

+
+ +

definition:

+ +
JSON Object
+
+ +

properties:

+ +
☐ id      : String
+☐ status  : String
+☐ code    : String
+☐ title   : String
+☑ detail  : String
+☐ links
+☐ meta
+☑ error_source
+ +

description:

+ +
id     : A unique identifier for this particular occurrence of the problem.
+status : The HTTP status code applicable to this problem, expressed as a string value
+code   : An application-specific error code, expressed as a string value.
+title  : A short, human-readable summary of the problem. It **SHOULD NOT** change from
+  occurrence to occurrence of the problem, except for purposes of localization.
+detail : A human-readable explanation specific to this occurrence of the problem.
+ +

structure:

+ +
{
+  title: 'SystemFailure',
+  detail: 'something went terribly wrong',
+  status: '500'
+}.merge!(errorSource)
+
+ + +
+
+
+ + +
+ + + + +
+
+
+
+47
+48
+49
+50
+51
+52
+53
+54
+
+
# File 'lib/active_model_serializers/adapter/json_api/error.rb', line 47
+
+def self.attribute_error_objects(attribute_name, attribute_errors)
+  attribute_errors.map do |attribute_error|
+    {
+      source: error_source(:pointer, attribute_name),
+      detail: attribute_error
+    }
+  end
+end
+
+
+ +
+

+ + + (Object) error_source(source_type, attribute_name) + + + + + +

+
+ +

errorSource description:

+ +
oneOf
+  ☑ pointer   : String
+  ☑ parameter : String
+ +

description:

+ +
pointer: A JSON Pointer RFC6901 to the associated entity in the request document e.g. "/data"
+for a primary data object, or "/data/attributes/title" for a specific attribute.
+https://tools.ietf.org/html/rfc6901
+
+parameter: A string indicating which query parameter caused the error
+ +

structure:

+ +
if is_attribute?
+  {
+    pointer: '/data/attributes/red-button'
+  }
+else
+  {
+    parameter: 'pres'
+  }
+end
+
+ + +
+
+
+ + +
+ + + + +
+
+
+
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+
+
# File 'lib/active_model_serializers/adapter/json_api/error.rb', line 78
+
+def self.error_source(source_type, attribute_name)
+  case source_type
+  when :pointer
+    {
+      pointer: ActiveModelSerializers::JsonPointer.new(:attribute, attribute_name)
+    }
+  when :parameter
+    {
+      parameter: attribute_name
+    }
+  else
+    fail UnknownSourceTypeError, "Unknown source type '#{source_type}' for attribute_name '#{attribute_name}'"
+  end
+end
+
+
+ +
+

+ + + (Array<Symbol, Array<String>>) resource_errors(error_serializer, options) + + + + + +

+
+ +

Builds a JSON API Errors Object JSON API Errors

+ + +
+
+
+

Parameters:

+ + +

Returns:

+
    + +
  • + + + (Array<Symbol, Array<String>>) + + + + — +
    +

    i.e. attribute_name, [attribute_errors]

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+13
+14
+15
+16
+17
+18
+19
+
+
# File 'lib/active_model_serializers/adapter/json_api/error.rb', line 13
+
+def self.resource_errors(error_serializer, options)
+  error_serializer.as_json.flat_map do |attribute_name, attribute_errors|
+    attribute_name = JsonApi.send(:transform_key_casing!, attribute_name,
+      options)
+    attribute_error_objects(attribute_name, attribute_errors)
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/JsonApi/Jsonapi.html b/ActiveModelSerializers/Adapter/JsonApi/Jsonapi.html new file mode 100644 index 00000000..4b74de13 --- /dev/null +++ b/ActiveModelSerializers/Adapter/JsonApi/Jsonapi.html @@ -0,0 +1,365 @@ + + + + + + Module: ActiveModelSerializers::Adapter::JsonApi::Jsonapi + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Adapter::JsonApi::Jsonapi + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json_api/jsonapi.rb
+ +
+
+ +

Overview

+
+ +

toplevel_jsonapi definition:

+ +
JSON Object
+
+ +

properties:

+ +
version : String
+meta
+ +

description:

+ +
An object describing the server's implementation
+ +

structure:

+ +
{
+  version: ActiveModelSerializers.config.jsonapi_version,
+  meta: ActiveModelSerializers.config.jsonapi_toplevel_meta
+}.reject! { |_, v| v.blank? }
+
+ +

prs:

+ +
https://github.com/rails-api/active_model_serializers/pull/1050
+
+ + +
+
+
+ + +
+ + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) add!(hash) + + + + + +

+ + + + +
+
+
+
+26
+27
+28
+
+
# File 'lib/active_model_serializers/adapter/json_api/jsonapi.rb', line 26
+
+def add!(hash)
+  hash.merge!(object) if include_object?
+end
+
+
+ +
+

+ + + (Boolean) include_object? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+30
+31
+32
+
+
# File 'lib/active_model_serializers/adapter/json_api/jsonapi.rb', line 30
+
+def include_object?
+  ActiveModelSerializers.config.jsonapi_include_toplevel_object
+end
+
+
+ +
+

+ + + (Object) object + + + + + +

+
+ +

TODO: see if we can cache this

+ + +
+
+
+ + +
+ + + + +
+
+
+
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+
+
# File 'lib/active_model_serializers/adapter/json_api/jsonapi.rb', line 35
+
+def object
+  object = {
+    jsonapi: {
+      version: ActiveModelSerializers.config.jsonapi_version,
+      meta: ActiveModelSerializers.config.jsonapi_toplevel_meta
+    }
+  }
+  object[:jsonapi].reject! { |_, v| v.blank? }
+
+  object
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/JsonApi/Link.html b/ActiveModelSerializers/Adapter/JsonApi/Link.html new file mode 100644 index 00000000..44a6a5f7 --- /dev/null +++ b/ActiveModelSerializers/Adapter/JsonApi/Link.html @@ -0,0 +1,475 @@ + + + + + + Class: ActiveModelSerializers::Adapter::JsonApi::Link + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::JsonApi::Link + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + +
Includes:
+
SerializationContext::UrlHelpers
+ + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json_api/link.rb
+ +
+
+ +

Overview

+
+ +

link definition:

+ +
oneOf
+  linkString
+  linkObject
+
+ +

description:

+ +
A link **MUST** be represented as either: a string containing the link's URL or a link
+object."
+ +

structure:

+ +
if href?
+  linkString
+else
+  linkObject
+end
+
+ +

linkString definition:

+ +
URI
+
+ +

description:

+ +
A string containing the link's URL.
+ +

structure:

+ +
'http://example.com/link-string'
+
+ +

linkObject definition:

+ +
JSON Object
+
+ +

properties:

+ +
href (required) : URI
+meta
+ +

structure:

+ +
{
+  href: 'http://example.com/link-object',
+  meta: meta,
+}.reject! {|_,v| v.nil? }
+
+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods included from SerializationContext::UrlHelpers

+

#default_url_options, included

+
+

Constructor Details

+ +
+

+ + - (Link) initialize(serializer, value) + + + + + +

+
+ +

Returns a new instance of Link

+ + +
+
+
+ + +
+ + + + +
+
+
+
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+
+
# File 'lib/active_model_serializers/adapter/json_api/link.rb', line 44
+
+def initialize(serializer, value)
+  @_routes ||= nil # handles warning
+  # actionpack-4.0.13/lib/action_dispatch/routing/route_set.rb:417: warning: instance variable @_routes not initialized
+  @object = serializer.object
+  @scope = serializer.scope
+  # Use the return value of the block unless it is nil.
+  if value.respond_to?(:call)
+    @value = instance_eval(&value)
+  else
+    @value = value
+  end
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) as_json + + + + + +

+ + + + +
+
+
+
+67
+68
+69
+70
+71
+72
+73
+74
+75
+
+
# File 'lib/active_model_serializers/adapter/json_api/link.rb', line 67
+
+def as_json
+  return @value if @value
+
+  hash = {}
+  hash[:href] = @href if defined?(@href)
+  hash[:meta] = @meta if defined?(@meta)
+
+  hash.any? ? hash : nil
+end
+
+
+ +
+

+ + - (Object) href(value) + + + + + +

+ + + + +
+
+
+
+57
+58
+59
+60
+
+
# File 'lib/active_model_serializers/adapter/json_api/link.rb', line 57
+
+def href(value)
+  @href = value
+  nil
+end
+
+
+ +
+

+ + - (Object) meta(value) + + + + + +

+ + + + +
+
+
+
+62
+63
+64
+65
+
+
# File 'lib/active_model_serializers/adapter/json_api/link.rb', line 62
+
+def meta(value)
+  @meta = value
+  nil
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/JsonApi/Meta.html b/ActiveModelSerializers/Adapter/JsonApi/Meta.html new file mode 100644 index 00000000..ea290d96 --- /dev/null +++ b/ActiveModelSerializers/Adapter/JsonApi/Meta.html @@ -0,0 +1,301 @@ + + + + + + Class: ActiveModelSerializers::Adapter::JsonApi::Meta + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::JsonApi::Meta + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json_api/meta.rb
+ +
+
+ +

Overview

+
+ +

meta definition:

+ +
JSON Object
+
+ +

description:

+ +
Non-standard meta-information that can not be represented as an attribute or relationship.
+ +

structure:

+ +
{
+  attitude: 'adjustable'
+}
+
+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Meta) initialize(serializer) + + + + + +

+
+ +

Returns a new instance of Meta

+ + +
+
+
+ + +
+ + + + +
+
+
+
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+
+
# File 'lib/active_model_serializers/adapter/json_api/meta.rb', line 15
+
+def initialize(serializer)
+  @object = serializer.object
+  @scope = serializer.scope
+
+  # Use the return value of the block unless it is nil.
+  if serializer._meta.respond_to?(:call)
+    @value = instance_eval(&serializer._meta)
+  else
+    @value = serializer._meta
+  end
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) as_json + + + + + +

+ + + + +
+
+
+
+27
+28
+29
+
+
# File 'lib/active_model_serializers/adapter/json_api/meta.rb', line 27
+
+def as_json
+  @value
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/JsonApi/PaginationLinks.html b/ActiveModelSerializers/Adapter/JsonApi/PaginationLinks.html new file mode 100644 index 00000000..fd2b17f0 --- /dev/null +++ b/ActiveModelSerializers/Adapter/JsonApi/PaginationLinks.html @@ -0,0 +1,440 @@ + + + + + + Class: ActiveModelSerializers::Adapter::JsonApi::PaginationLinks + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::JsonApi::PaginationLinks + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json_api/pagination_links.rb
+ +
+
+ + +

Constant Summary

+ +
+ +
FIRST_PAGE = + +
+
1
+ +
+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (PaginationLinks) initialize(collection, adapter_options) + + + + + +

+
+ +

Returns a new instance of PaginationLinks

+ + +
+
+
+ + +
+ + + + +
+
+
+
+9
+10
+11
+12
+13
+
+
# File 'lib/active_model_serializers/adapter/json_api/pagination_links.rb', line 9
+
+def initialize(collection, adapter_options)
+  @collection = collection
+  @adapter_options = adapter_options
+  @context = adapter_options.fetch(:serialization_context)
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) collection (readonly) + + + + + +

+
+ +

Returns the value of attribute collection

+ + +
+
+
+ + +
+ + + + +
+
+
+
+7
+8
+9
+
+
# File 'lib/active_model_serializers/adapter/json_api/pagination_links.rb', line 7
+
+def collection
+  @collection
+end
+
+
+ + + +
+

+ + - (Object) context (readonly) + + + + + +

+
+ +

Returns the value of attribute context

+ + +
+
+
+ + +
+ + + + +
+
+
+
+7
+8
+9
+
+
# File 'lib/active_model_serializers/adapter/json_api/pagination_links.rb', line 7
+
+def context
+  @context
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) as_json + + + + + +

+ + + + +
+
+
+
+15
+16
+17
+18
+19
+20
+21
+22
+
+
# File 'lib/active_model_serializers/adapter/json_api/pagination_links.rb', line 15
+
+def as_json
+  per_page = collection.try(:per_page) || collection.try(:limit_value) || collection.size
+  pages_from.each_with_object({}) do |(key, value), hash|
+    params = query_parameters.merge(page: { number: value, size: per_page }).to_query
+
+    hash[key] = "#{url(adapter_options)}?#{params}"
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/JsonApi/Relationship.html b/ActiveModelSerializers/Adapter/JsonApi/Relationship.html new file mode 100644 index 00000000..284cb3a3 --- /dev/null +++ b/ActiveModelSerializers/Adapter/JsonApi/Relationship.html @@ -0,0 +1,296 @@ + + + + + + Class: ActiveModelSerializers::Adapter::JsonApi::Relationship + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::JsonApi::Relationship + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json_api/relationship.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (Relationship) initialize(parent_serializer, serializer, serializable_resource_options, args = {}) + + + + + +

+
+ + +
+ + + + +
+
+
+
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+
+
# File 'lib/active_model_serializers/adapter/json_api/relationship.rb', line 9
+
+def initialize(parent_serializer, serializer, serializable_resource_options, args = {})
+  @object = parent_serializer.object
+  @scope = parent_serializer.scope
+  @association_options = args.fetch(:options, {})
+  @serializable_resource_options = serializable_resource_options
+  @data = data_for(serializer)
+  @links = args.fetch(:links, {}).each_with_object({}) do |(key, value), hash|
+    hash[key] = ActiveModelSerializers::Adapter::JsonApi::Link.new(parent_serializer, value).as_json
+  end
+  meta = args.fetch(:meta, nil)
+  @meta = meta.respond_to?(:call) ? parent_serializer.instance_eval(&meta) : meta
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) as_json + + + + + +

+ + + + +
+
+
+
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+
+
# File 'lib/active_model_serializers/adapter/json_api/relationship.rb', line 22
+
+def as_json
+  hash = {}
+  hash[:data] = data if association_options[:include_data]
+  links = self.links
+  hash[:links] = links if links.any?
+  meta = self.meta
+  hash[:meta] = meta if meta
+
+  hash
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/JsonApi/ResourceIdentifier.html b/ActiveModelSerializers/Adapter/JsonApi/ResourceIdentifier.html new file mode 100644 index 00000000..863e0099 --- /dev/null +++ b/ActiveModelSerializers/Adapter/JsonApi/ResourceIdentifier.html @@ -0,0 +1,264 @@ + + + + + + Class: ActiveModelSerializers::Adapter::JsonApi::ResourceIdentifier + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::JsonApi::ResourceIdentifier + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/json_api/resource_identifier.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (ResourceIdentifier) initialize(serializer, options) + + + + + +

+
+ + +
+ + + + +
+
+
+
+6
+7
+8
+9
+10
+
+
# File 'lib/active_model_serializers/adapter/json_api/resource_identifier.rb', line 6
+
+def initialize(serializer, options)
+  @id   = id_for(serializer)
+  @type = JsonApi.send(:transform_key_casing!, type_for(serializer),
+    options)
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) as_json + + + + + +

+ + + + +
+
+
+
+12
+13
+14
+
+
# File 'lib/active_model_serializers/adapter/json_api/resource_identifier.rb', line 12
+
+def as_json
+  { id: id, type: type }
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Adapter/Null.html b/ActiveModelSerializers/Adapter/Null.html new file mode 100644 index 00000000..3c00620f --- /dev/null +++ b/ActiveModelSerializers/Adapter/Null.html @@ -0,0 +1,217 @@ + + + + + + Class: ActiveModelSerializers::Adapter::Null + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Adapter::Null + + + +

+ +
+ +
Inherits:
+
+ Base + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/adapter/null.rb
+ +
+
+ +
+

Direct Known Subclasses

+

ActiveModel::Serializer::Adapter::Null

+
+ + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from Base

+

#instance_options, #serializer

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods inherited from Base

+

#as_json, cache_key, #cache_key, default_key_transform, #fragment_cache, fragment_cache, inherited, #initialize, transform, transform_key_casing!

+
+

Constructor Details

+ +

This class inherits a constructor from ActiveModelSerializers::Adapter::Base

+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) serializable_hash + + + + + +

+ + + + +
+
+
+
+4
+5
+6
+
+
# File 'lib/active_model_serializers/adapter/null.rb', line 4
+
+def serializable_hash(*)
+  {}
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Callbacks.html b/ActiveModelSerializers/Callbacks.html new file mode 100644 index 00000000..2fe6c73a --- /dev/null +++ b/ActiveModelSerializers/Callbacks.html @@ -0,0 +1,142 @@ + + + + + + Module: ActiveModelSerializers::Callbacks + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Callbacks + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + +
Includes:
+
ActiveSupport::Callbacks
+ + + + + +
Defined in:
+
lib/active_model_serializers/callbacks.rb
+ +
+
+ +

Overview

+
+ +

ActiveModelSerializers Callbacks

+ +

ActiveModelSerializers provides hooks during the life cycle of +serialization and allow you to trigger logic. Available callbacks are:

+
  • +

    around_render

    +
+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + Modules: ClassMethods + + + + +

+ + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Callbacks/ClassMethods.html b/ActiveModelSerializers/Callbacks/ClassMethods.html new file mode 100644 index 00000000..e5f14f46 --- /dev/null +++ b/ActiveModelSerializers/Callbacks/ClassMethods.html @@ -0,0 +1,225 @@ + + + + + + Module: ActiveModelSerializers::Callbacks::ClassMethods + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Callbacks::ClassMethods + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/callbacks.rb
+ +
+
+ +

Overview

+
+ +

These methods will be included into any ActiveModelSerializers object, +adding callbacks for render.

+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) around_render(*filters, &blk) + + + + + +

+
+ +

Defines a callback that will get called around the render method, whether +it is as_json, to_json, or serializable_hash

+ +
class ActiveModelSerializers::SerializableResource
+  include ActiveModelSerializers::Callbacks
+
+  around_render do |args, block|
+    tag_logger do
+      notify_render do
+        block.call(args)
+      end
+    end
+  end
+
+  def as_json
+    run_callbacks :render do
+      adapter.as_json
+    end
+  end
+  # Note: So that we can re-use the instrumenter for as_json, to_json, and
+  # serializable_hash, we aren't using the usual format, which would be:
+  # def render(args)
+  #   adapter.as_json
+  # end
+end
+
+ + +
+
+
+ + +
+ + + + +
+
+
+
+50
+51
+52
+
+
# File 'lib/active_model_serializers/callbacks.rb', line 50
+
+def around_render(*filters, &blk)
+  set_callback(:render, :around, *filters, &blk)
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Deprecate.html b/ActiveModelSerializers/Deprecate.html new file mode 100644 index 00000000..1335fe65 --- /dev/null +++ b/ActiveModelSerializers/Deprecate.html @@ -0,0 +1,271 @@ + + + + + + Module: ActiveModelSerializers::Deprecate + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Deprecate + + + +

+ +
+ + + + + + + +
Included in:
+
ActiveModel::SerializableResource, ActiveModel::Serializer, ActiveModel::Serializer::Adapter, ActiveModel::Serializer::Adapter::Attributes, ActiveModel::Serializer::Adapter::Base, ActiveModel::Serializer::Adapter::Json, ActiveModel::Serializer::Adapter::JsonApi, ActiveModel::Serializer::Adapter::Null, ActiveModel::Serializer::ArraySerializer
+ + + +
Defined in:
+
lib/active_model_serializers/deprecate.rb
+ +
+
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) delegate_and_deprecate(method, delegee) + + + + + +

+ + + + +
+
+
+
+46
+47
+48
+49
+
+
# File 'lib/active_model_serializers/deprecate.rb', line 46
+
+def delegate_and_deprecate(method, delegee)
+  delegate method, to: delegee
+  deprecate method, "#{delegee.name}."
+end
+
+
+ +
+

+ + + (Object) deprecate(name, replacement) + + + + + +

+
+ +

Simple deprecation method that deprecates name by wrapping it +up in a dummy method. It warns on each call to the dummy method telling the +user of replacement (unless replacement is :none) +that it is planned to go away.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+
+
# File 'lib/active_model_serializers/deprecate.rb', line 31
+
+def deprecate(name, replacement)
+  old = "_deprecated_#{name}"
+  alias_method old, name
+  class_eval do
+    define_method(name) do |*args, &block|
+      target = is_a?(Module) ? "#{self}." : "#{self.class}#"
+      msg = ["NOTE: #{target}#{name} is deprecated",
+             replacement == :none ? ' with no replacement' : "; use #{replacement} instead",
+             "\n#{target}#{name} called from #{ActiveModelSerializers.location_of_caller.join(":")}"]
+      warn "#{msg.join}."
+      send old, *args, &block
+    end
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Deserialization.html b/ActiveModelSerializers/Deserialization.html new file mode 100644 index 00000000..2146da32 --- /dev/null +++ b/ActiveModelSerializers/Deserialization.html @@ -0,0 +1,239 @@ + + + + + + Module: ActiveModelSerializers::Deserialization + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Deserialization + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/deserialization.rb
+ +
+
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) jsonapi_parse(*args) + + + + + +

+ + + + +
+
+
+
+5
+6
+7
+
+
# File 'lib/active_model_serializers/deserialization.rb', line 5
+
+def jsonapi_parse(*args)
+  Adapter::JsonApi::Deserialization.parse(*args)
+end
+
+
+ +
+

+ + + (Object) jsonapi_parse!(*args) + + + + + +

+
+ +

:nocov:

+ + +
+
+
+ + +
+ + + + +
+
+
+
+10
+11
+12
+
+
# File 'lib/active_model_serializers/deserialization.rb', line 10
+
+def jsonapi_parse!(*args)
+  Adapter::JsonApi::Deserialization.parse!(*args)
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/JsonPointer.html b/ActiveModelSerializers/JsonPointer.html new file mode 100644 index 00000000..24ce5e46 --- /dev/null +++ b/ActiveModelSerializers/JsonPointer.html @@ -0,0 +1,189 @@ + + + + + + Module: ActiveModelSerializers::JsonPointer + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::JsonPointer + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/json_pointer.rb
+ +
+
+ + +

Constant Summary

+ +
+ +
POINTERS = + +
+
{
+  attribute:    '/data/attributes/%s'.freeze,
+  primary_data: '/data%s'.freeze
+}.freeze
+ +
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) new(pointer_type, value = nil) + + + + + +

+ + + + +
+
+
+
+10
+11
+12
+
+
# File 'lib/active_model_serializers/json_pointer.rb', line 10
+
+def new(pointer_type, value = nil)
+  format(POINTERS[pointer_type], value)
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Jsonapi.html b/ActiveModelSerializers/Jsonapi.html new file mode 100644 index 00000000..30cd6e5c --- /dev/null +++ b/ActiveModelSerializers/Jsonapi.html @@ -0,0 +1,352 @@ + + + + + + Module: ActiveModelSerializers::Jsonapi + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Jsonapi + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/register_jsonapi_renderer.rb
+ +
+
+ +

Overview

+
+ +

Based on discussion in github.com/rails/rails/pull/23712#issuecomment-184977238, +the JSON API media type will have its own format/renderer.

+ +

> We recommend the media type be registered on its own as jsonapi when a +jsonapi Renderer and deserializer (Http::Parameters::DEFAULT_PARSERS) are +added.

+ +

Usage:

+ +

ActiveSupport.on_load(:action_controller) do

+ +
require 'active_model_serializers/register_jsonapi_renderer'
+
+ +

end

+ +

And then in controllers, use `render jsonapi: model` rather than `render +json: model, adapter: :json_api`.

+ +

For example, in a controller action, we can: respond_to do |format|

+ +
format.jsonapi { render jsonapi: model }
+
+ +

end

+ +

or

+ +

render jsonapi: model

+ +

No wrapper format needed as it does not apply (i.e. no `wrap_parameters +format: [jsonapi]`)

+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + Modules: ControllerSupport + + + + +

+ +

Constant Summary

+ +
+ +
MEDIA_TYPE = + +
+
'application/vnd.api+json'.freeze
+ +
HEADERS = + +
+
{
+  response: { 'CONTENT_TYPE'.freeze => MEDIA_TYPE },
+  request:  { 'ACCEPT'.freeze => MEDIA_TYPE }
+}.freeze
+ +
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) install + + + + + +

+ + + + +
+
+
+
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+
+
# File 'lib/active_model_serializers/register_jsonapi_renderer.rb', line 32
+
+def self.install
+  # actionpack/lib/action_dispatch/http/mime_types.rb
+  Mime::Type.register MEDIA_TYPE, :jsonapi
+
+  if Rails::VERSION::MAJOR >= 5
+    ActionDispatch::Request.parameter_parsers[:jsonapi] = parser
+  else
+    ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime[:jsonapi]] = parser
+  end
+
+  # ref https://github.com/rails/rails/pull/21496
+  ActionController::Renderers.add :jsonapi do |json, options|
+    json = serialize_jsonapi(json, options).to_json(options) unless json.is_a?(String)
+    self.content_type ||= Mime[:jsonapi]
+    self.response_body = json
+  end
+end
+
+
+ +
+

+ + + (Object) parser + + + + + +

+
+ +

Proposal: should actually deserialize the JSON API params to the hash +format expected by `ActiveModel::Serializers::JSON` +actionpack/lib/action_dispatch/http/parameters.rb

+ + +
+
+
+ + +
+ + + + +
+
+
+
+53
+54
+55
+56
+57
+58
+59
+
+
# File 'lib/active_model_serializers/register_jsonapi_renderer.rb', line 53
+
+def self.parser
+  lambda do |body|
+    data = JSON.parse(body)
+    data = { :_json => data } unless data.is_a?(Hash)
+    data.with_indifferent_access
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Jsonapi/ControllerSupport.html b/ActiveModelSerializers/Jsonapi/ControllerSupport.html new file mode 100644 index 00000000..ff8f3e85 --- /dev/null +++ b/ActiveModelSerializers/Jsonapi/ControllerSupport.html @@ -0,0 +1,182 @@ + + + + + + Module: ActiveModelSerializers::Jsonapi::ControllerSupport + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Jsonapi::ControllerSupport + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/register_jsonapi_renderer.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) serialize_jsonapi(json, options) + + + + + +

+ + + + +
+
+
+
+62
+63
+64
+65
+66
+67
+68
+
+
# File 'lib/active_model_serializers/register_jsonapi_renderer.rb', line 62
+
+def serialize_jsonapi(json, options)
+  options[:adapter] = :json_api
+  options.fetch(:serialization_context) do
+    options[:serialization_context] = ActiveModelSerializers::SerializationContext.new(request)
+  end
+  get_serializer(json, options)
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/KeyTransform.html b/ActiveModelSerializers/KeyTransform.html new file mode 100644 index 00000000..c8b0c801 --- /dev/null +++ b/ActiveModelSerializers/KeyTransform.html @@ -0,0 +1,533 @@ + + + + + + Module: ActiveModelSerializers::KeyTransform + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::KeyTransform + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/key_transform.rb
+ +
+
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) camel(value) + + + + + +

+
+ +

Transforms values to UpperCamelCase or PascalCase.

+ +

@example:

+ +
"some_key" => "SomeKey",
+ + +
+
+
+ + +

See Also:

+ + +
+ + + + +
+
+
+
+12
+13
+14
+15
+16
+17
+18
+19
+
+
# File 'lib/active_model_serializers/key_transform.rb', line 12
+
+def camel(value)
+  case value
+  when Hash then value.deep_transform_keys! { |key| camel(key) }
+  when Symbol then camel(value.to_s).to_sym
+  when String then value.underscore.camelize
+  else value
+  end
+end
+
+
+ +
+

+ + + (Object) camel_lower(value) + + + + + +

+
+ +

Transforms values to camelCase.

+ +

@example:

+ +
"some_key" => "someKey",
+ + +
+
+
+ + +

See Also:

+ + +
+ + + + +
+
+
+
+26
+27
+28
+29
+30
+31
+32
+33
+
+
# File 'lib/active_model_serializers/key_transform.rb', line 26
+
+def camel_lower(value)
+  case value
+  when Hash then value.deep_transform_keys! { |key| camel_lower(key) }
+  when Symbol then camel_lower(value.to_s).to_sym
+  when String then value.underscore.camelize(:lower)
+  else value
+  end
+end
+
+
+ +
+

+ + + (Object) dash(value) + + + + + +

+
+ +

Transforms values to dashed-case. This is the default case for the JsonApi +adapter.

+ +

@example:

+ +
"some_key" => "some-key",
+ + +
+
+
+ + +

See Also:

+ + +
+ + + + +
+
+
+
+41
+42
+43
+44
+45
+46
+47
+48
+
+
# File 'lib/active_model_serializers/key_transform.rb', line 41
+
+def dash(value)
+  case value
+  when Hash then value.deep_transform_keys! { |key| dash(key) }
+  when Symbol then dash(value.to_s).to_sym
+  when String then value.underscore.dasherize
+  else value
+  end
+end
+
+
+ +
+

+ + + (Object) unaltered(value) + + + + + +

+
+ +

Returns the value unaltered

+ + +
+
+
+ + +
+ + + + +
+
+
+
+66
+67
+68
+
+
# File 'lib/active_model_serializers/key_transform.rb', line 66
+
+def unaltered(value)
+  value
+end
+
+
+ +
+

+ + + (Object) underscore(value) + + + + + +

+
+ +

Transforms values to underscore_case. This is the default case for +deserialization in the JsonApi adapter.

+ +

@example:

+ +
"some-key" => "some_key",
+ + +
+
+
+ + +

See Also:

+ + +
+ + + + +
+
+
+
+56
+57
+58
+59
+60
+61
+62
+63
+
+
# File 'lib/active_model_serializers/key_transform.rb', line 56
+
+def underscore(value)
+  case value
+  when Hash then value.deep_transform_keys! { |key| underscore(key) }
+  when Symbol then underscore(value.to_s).to_sym
+  when String then value.underscore
+  else value
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Logging.html b/ActiveModelSerializers/Logging.html new file mode 100644 index 00000000..a985b01f --- /dev/null +++ b/ActiveModelSerializers/Logging.html @@ -0,0 +1,271 @@ + + + + + + Module: ActiveModelSerializers::Logging + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Logging + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + + + +
Included in:
+
SerializableResource
+ + + +
Defined in:
+
lib/active_model_serializers/logging.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: ClassMethods, Macros + + + + Classes: LogSubscriber + + +

+ +

Constant Summary

+ +
+ +
RENDER_EVENT = + +
+
'render.active_model_serializers'.freeze
+ +
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) notify_render + + + + + +

+ + + + +
+
+
+
+76
+77
+78
+79
+80
+81
+
+
# File 'lib/active_model_serializers/logging.rb', line 76
+
+def notify_render(*)
+  event_name = RENDER_EVENT
+  ActiveSupport::Notifications.instrument(event_name, notify_render_payload) do
+    yield
+  end
+end
+
+
+ +
+

+ + - (Object) notify_render_payload + + + + + +

+ + + + +
+
+
+
+83
+84
+85
+86
+87
+88
+
+
# File 'lib/active_model_serializers/logging.rb', line 83
+
+def notify_render_payload
+  {
+    serializer: serializer || ActiveModel::Serializer::Null,
+    adapter: adapter || ActiveModelSerializers::Adapter::Null
+  }
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Logging/ClassMethods.html b/ActiveModelSerializers/Logging/ClassMethods.html new file mode 100644 index 00000000..75a70892 --- /dev/null +++ b/ActiveModelSerializers/Logging/ClassMethods.html @@ -0,0 +1,186 @@ + + + + + + Module: ActiveModelSerializers::Logging::ClassMethods + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Logging::ClassMethods + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/logging.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) instrument_rendering + + + + + +

+ + + + +
+
+
+
+18
+19
+20
+21
+22
+23
+24
+25
+26
+
+
# File 'lib/active_model_serializers/logging.rb', line 18
+
+def instrument_rendering
+  around_render do |args, block|
+    tag_logger do
+      notify_render do
+        block.call(args)
+      end
+    end
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Logging/LogSubscriber.html b/ActiveModelSerializers/Logging/LogSubscriber.html new file mode 100644 index 00000000..be7d0673 --- /dev/null +++ b/ActiveModelSerializers/Logging/LogSubscriber.html @@ -0,0 +1,254 @@ + + + + + + Class: ActiveModelSerializers::Logging::LogSubscriber + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Logging::LogSubscriber + + + +

+ +
+ +
Inherits:
+
+ ActiveSupport::LogSubscriber + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/logging.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) logger + + + + + +

+ + + + +
+
+
+
+115
+116
+117
+
+
# File 'lib/active_model_serializers/logging.rb', line 115
+
+def logger
+  ActiveModelSerializers.logger
+end
+
+
+ +
+

+ + - (Object) render(event) + + + + + +

+ + + + +
+
+
+
+106
+107
+108
+109
+110
+111
+112
+113
+
+
# File 'lib/active_model_serializers/logging.rb', line 106
+
+def render(event)
+  info do
+    serializer = event.payload[:serializer]
+    adapter = event.payload[:adapter]
+    duration = event.duration.round(2)
+    "Rendered #{serializer.name} with #{adapter.class} (#{duration}ms)"
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Logging/Macros.html b/ActiveModelSerializers/Logging/Macros.html new file mode 100644 index 00000000..79efbd98 --- /dev/null +++ b/ActiveModelSerializers/Logging/Macros.html @@ -0,0 +1,249 @@ + + + + + + Module: ActiveModelSerializers::Logging::Macros + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Logging::Macros + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/logging.rb
+ +
+
+ +

Overview

+
+ +

Macros that can be used to customize the logging of class or instance +methods, by extending the class or its singleton.

+ +

Adapted from:

+ +
https://github.com/rubygems/rubygems/blob/cb28f5e991/lib/rubygems/deprecate.rb
+
+ +

Provides a single method notify to be used to declare when +something a method notifies, with the argument callback_name +of the notification callback.

+ +
class Adapter
+  def self.klass_method
+    # ...
+  end
+
+  def instance_method
+    # ...
+  end
+
+  include ActiveModelSerializers::Logging::Macros
+  notify :instance_method, :render
+
+  class << self
+    extend ActiveModelSerializers::Logging::Macros
+    notify :klass_method, :render
+  end
+end
+
+ + +
+
+
+ + +
+ + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) notify(name, callback_name) + + + + + +

+
+ +

Simple notify method that wraps up name in a dummy method. It +notifies on with the callback_name notifier on each call to +the dummy method, telling what the current serializer and adapter are being +rendered. Adapted from:

+ +
https://github.com/rubygems/rubygems/blob/cb28f5e991/lib/rubygems/deprecate.rb
+
+ + +
+
+
+ + +
+ + + + +
+
+
+
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+
+
# File 'lib/active_model_serializers/logging.rb', line 63
+
+def notify(name, callback_name)
+  class_eval do
+    old = "_notifying_#{callback_name}_#{name}"
+    alias_method old, name
+    define_method name do |*args, &block|
+      run_callbacks callback_name do
+        send old, *args, &block
+      end
+    end
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Model.html b/ActiveModelSerializers/Model.html new file mode 100644 index 00000000..8c1b3d99 --- /dev/null +++ b/ActiveModelSerializers/Model.html @@ -0,0 +1,761 @@ + + + + + + Class: ActiveModelSerializers::Model + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Model + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + +
Includes:
+
ActiveModel::Model, ActiveModel::Serializers::JSON
+ + + + + +
Defined in:
+
lib/active_model_serializers/model.rb
+ +
+
+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Class Method Summary + (collapse) +

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Constructor Details

+ +
+

+ + - (Model) initialize(attributes = {}) + + + + + +

+
+ +

Returns a new instance of Model

+ + +
+
+
+ + +
+ + + + +
+
+
+
+11
+12
+13
+14
+15
+
+
# File 'lib/active_model_serializers/model.rb', line 11
+
+def initialize(attributes = {})
+  @attributes = attributes
+  @errors = ActiveModel::Errors.new(self)
+  super
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) attributes (readonly) + + + + + +

+
+ +

Returns the value of attribute attributes

+ + +
+
+
+ + +
+ + + + +
+
+
+
+9
+10
+11
+
+
# File 'lib/active_model_serializers/model.rb', line 9
+
+def attributes
+  @attributes
+end
+
+
+ + + +
+

+ + - (Object) errors (readonly) + + + + + +

+
+ +

Returns the value of attribute errors

+ + +
+
+
+ + +
+ + + + +
+
+
+
+9
+10
+11
+
+
# File 'lib/active_model_serializers/model.rb', line 9
+
+def errors
+  @errors
+end
+
+
+ +
+ + +
+

Class Method Details

+ + +
+

+ + + (Object) human_attribute_name(attr, _options = {}) + + + + + +

+
+ +

The following methods are needed to be minimally implemented for +ActiveModel::Errors :nocov:

+ + +
+
+
+ + +
+ + + + +
+
+
+
+42
+43
+44
+
+
# File 'lib/active_model_serializers/model.rb', line 42
+
+def self.human_attribute_name(attr, _options = {})
+  attr
+end
+
+
+ +
+

+ + + (Object) lookup_ancestors + + + + + +

+ + + + +
+
+
+
+46
+47
+48
+
+
# File 'lib/active_model_serializers/model.rb', line 46
+
+def self.lookup_ancestors
+  [self]
+end
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + - (Object) cache_key + + + + + +

+
+ +

Defaults to the downcased model name and updated_at

+ + +
+
+
+ + +
+ + + + +
+
+
+
+23
+24
+25
+
+
# File 'lib/active_model_serializers/model.rb', line 23
+
+def cache_key
+  attributes.fetch(:cache_key) { "#{self.class.name.downcase}/#{id}-#{updated_at.strftime("%Y%m%d%H%M%S%9N")}" }
+end
+
+
+ +
+

+ + - (Object) id + + + + + +

+
+ +

Defaults to the downcased model name.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+18
+19
+20
+
+
# File 'lib/active_model_serializers/model.rb', line 18
+
+def id
+  attributes.fetch(:id) { self.class.name.downcase }
+end
+
+
+ +
+

+ + - (Object) read_attribute_for_serialization(key) + + + + + +

+ + + + +
+
+
+
+32
+33
+34
+35
+36
+37
+38
+
+
# File 'lib/active_model_serializers/model.rb', line 32
+
+def read_attribute_for_serialization(key)
+  if key == :id || key == 'id'
+    attributes.fetch(key) { id }
+  else
+    attributes[key]
+  end
+end
+
+
+ +
+

+ + - (Object) updated_at + + + + + +

+
+ +

Defaults to the time the serializer file was modified.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+28
+29
+30
+
+
# File 'lib/active_model_serializers/model.rb', line 28
+
+def updated_at
+  attributes.fetch(:updated_at) { File.mtime(__FILE__) }
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Railtie.html b/ActiveModelSerializers/Railtie.html new file mode 100644 index 00000000..e4391993 --- /dev/null +++ b/ActiveModelSerializers/Railtie.html @@ -0,0 +1,123 @@ + + + + + + Class: ActiveModelSerializers::Railtie + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Railtie + + + +

+ +
+ +
Inherits:
+
+ Rails::Railtie + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/railtie.rb
+ +
+
+ + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/SerializableResource.html b/ActiveModelSerializers/SerializableResource.html new file mode 100644 index 00000000..aba884e8 --- /dev/null +++ b/ActiveModelSerializers/SerializableResource.html @@ -0,0 +1,831 @@ + + + + + + Class: ActiveModelSerializers::SerializableResource + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::SerializableResource + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + +
Includes:
+
Logging
+ + + + + +
Defined in:
+
lib/active_model_serializers/serializable_resource.rb
+ +
+
+ + +

Constant Summary

+ +
+ +
ADAPTER_OPTION_KEYS = + +
+
Set.new([:include, :fields, :adapter, :meta, :meta_key, :links, :serialization_context, :key_transform])
+ +
+ + + + + + +

Constants included + from Logging

+

Logging::RENDER_EVENT

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods included from Logging

+

#notify_render, #notify_render_payload

+ +
+

Constructor Details

+ +
+

+ + - (Object) initialize(resource, options = {}) + + + + + +

+
+ +

Primary interface to composing a resource with a serializer and adapter.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+15
+16
+17
+18
+19
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 15
+
+def initialize(resource, options = {})
+  @resource = resource
+  @adapter_opts, @serializer_opts =
+    options.partition { |k, _| ADAPTER_OPTION_KEYS.include? k }.map { |h| Hash[h] }
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) adapter + + + + Also known as: + adapter_instance + + + + +

+
+ +

NOTE: if no adapter is available, returns the resource itself. (i.e. +adapter is a no-op)

+ + +
+
+
+ + +
+ + + + +
+
+
+
+34
+35
+36
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 34
+
+def adapter
+  @adapter ||= find_adapter
+end
+
+
+ +
+

+ + - (Object) find_adapter + + + + + +

+ + + + +
+
+
+
+39
+40
+41
+42
+43
+44
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 39
+
+def find_adapter
+  return resource unless serializer?
+  ActiveModelSerializers::Adapter.create(serializer_instance, adapter_opts)
+rescue ActiveModel::Serializer::CollectionSerializer::NoSerializerError
+  resource
+end
+
+
+ +
+

+ + - (Object) serialization_scope + + + + + +

+ + + + +
+
+
+
+25
+26
+27
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 25
+
+def serialization_scope
+  serializer_opts[:scope]
+end
+
+
+ +
+

+ + - (Object) serialization_scope=(scope) + + + + + +

+ + + + +
+
+
+
+21
+22
+23
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 21
+
+def serialization_scope=(scope)
+  serializer_opts[:scope] = scope
+end
+
+
+ +
+

+ + - (Object) serialization_scope_name=(scope_name) + + + + + +

+ + + + +
+
+
+
+29
+30
+31
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 29
+
+def serialization_scope_name=(scope_name)
+  serializer_opts[:scope_name] = scope_name
+end
+
+
+ +
+

+ + - (Object) serializer + + + + Also known as: + serializer_class + + + + +

+
+ +

Get serializer either explicitly :serializer or implicitly from resource +Remove :serializer key from serializer_opts Replace :serializer key with +:each_serializer if present

+ + +
+
+
+ + +
+ + + + +
+
+
+
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 53
+
+def serializer
+  @serializer ||=
+    begin
+      @serializer = serializer_opts.delete(:serializer)
+      @serializer ||= ActiveModel::Serializer.serializer_for(resource)
+
+      if serializer_opts.key?(:each_serializer)
+        serializer_opts[:serializer] = serializer_opts.delete(:each_serializer)
+      end
+      @serializer
+    end
+end
+
+
+ +
+

+ + - (Boolean) serializer? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+73
+74
+75
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 73
+
+def serializer?
+  use_adapter? && !serializer.nil?
+end
+
+
+ +
+

+ + - (Object) serializer_instance + + + + + +

+ + + + +
+
+
+
+46
+47
+48
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 46
+
+def serializer_instance
+  @serializer_instance ||= serializer.new(resource, serializer_opts)
+end
+
+
+ +
+

+ + - (Boolean) use_adapter? + + + + + +

+
+ +

True when no explicit adapter given, or explicit appear is truthy (non-nil) +False when explicit adapter is falsy (nil or false)

+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+69
+70
+71
+
+
# File 'lib/active_model_serializers/serializable_resource.rb', line 69
+
+def use_adapter?
+  !(adapter_opts.key?(:adapter) && !adapter_opts[:adapter])
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/SerializationContext.html b/ActiveModelSerializers/SerializationContext.html new file mode 100644 index 00000000..8e773d4f --- /dev/null +++ b/ActiveModelSerializers/SerializationContext.html @@ -0,0 +1,568 @@ + + + + + + Class: ActiveModelSerializers::SerializationContext + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::SerializationContext + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/serialization_context.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: UrlHelpers + + + + +

+ + + + +

Class Attribute Summary (collapse)

+ + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (SerializationContext) initialize(request, options = {}) + + + + + +

+
+ +

Returns a new instance of SerializationContext

+ + +
+
+
+ + +
+ + + + +
+
+
+
+25
+26
+27
+28
+29
+30
+
+
# File 'lib/active_model_serializers/serialization_context.rb', line 25
+
+def initialize(request, options = {})
+  @request_url = request.original_url[/\A[^?]+/]
+  @query_parameters = request.query_parameters
+  @url_helpers = options.delete(:url_helpers) || self.class.url_helpers
+  @default_url_options = options.delete(:default_url_options) || self.class.default_url_options
+end
+
+
+ +
+ +
+

Class Attribute Details

+ + + +
+

+ + + (Object) default_url_options + + + + + +

+ + + + +
+
+
+
+9
+10
+11
+
+
# File 'lib/active_model_serializers/serialization_context.rb', line 9
+
+def default_url_options
+  @default_url_options ||= {}
+end
+
+
+ + + +
+

+ + + (Object) url_helpers + + + + + +

+ + + + +
+
+
+
+5
+6
+7
+
+
# File 'lib/active_model_serializers/serialization_context.rb', line 5
+
+def url_helpers
+  @url_helpers ||= Module.new
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) key_transform (readonly) + + + + + +

+
+ +

Returns the value of attribute key_transform

+ + +
+
+
+ + +
+ + + + +
+
+
+
+23
+24
+25
+
+
# File 'lib/active_model_serializers/serialization_context.rb', line 23
+
+def key_transform
+  @key_transform
+end
+
+
+ + + +
+

+ + - (Object) query_parameters (readonly) + + + + + +

+
+ +

Returns the value of attribute query_parameters

+ + +
+
+
+ + +
+ + + + +
+
+
+
+23
+24
+25
+
+
# File 'lib/active_model_serializers/serialization_context.rb', line 23
+
+def query_parameters
+  @query_parameters
+end
+
+
+ + + +
+

+ + - (Object) request_url (readonly) + + + + + +

+
+ +

Returns the value of attribute request_url

+ + +
+
+
+ + +
+ + + + +
+
+
+
+23
+24
+25
+
+
# File 'lib/active_model_serializers/serialization_context.rb', line 23
+
+def request_url
+  @request_url
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/SerializationContext/UrlHelpers.html b/ActiveModelSerializers/SerializationContext/UrlHelpers.html new file mode 100644 index 00000000..755648b0 --- /dev/null +++ b/ActiveModelSerializers/SerializationContext/UrlHelpers.html @@ -0,0 +1,245 @@ + + + + + + Module: ActiveModelSerializers::SerializationContext::UrlHelpers + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::SerializationContext::UrlHelpers + + + +

+ +
+ + + + + + + +
Included in:
+
Adapter::JsonApi::Link
+ + + +
Defined in:
+
lib/active_model_serializers/serialization_context.rb
+ +
+
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) included(base) + + + + + +

+ + + + +
+
+
+
+14
+15
+16
+
+
# File 'lib/active_model_serializers/serialization_context.rb', line 14
+
+def self.included(base)
+  base.send(:include, SerializationContext.url_helpers)
+end
+
+
+ +
+ +
+

Instance Method Details

+ + +
+

+ + - (Object) default_url_options + + + + + +

+ + + + +
+
+
+
+18
+19
+20
+
+
# File 'lib/active_model_serializers/serialization_context.rb', line 18
+
+def default_url_options
+  SerializationContext.default_url_options
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Test.html b/ActiveModelSerializers/Test.html new file mode 100644 index 00000000..c1cdc782 --- /dev/null +++ b/ActiveModelSerializers/Test.html @@ -0,0 +1,122 @@ + + + + + + Module: ActiveModelSerializers::Test + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Test + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Autoload
+ + + + + + + +
Defined in:
+
lib/active_model_serializers/test.rb,
+ lib/active_model_serializers/test/schema.rb,
lib/active_model_serializers/test/serializer.rb
+
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: Schema, Serializer + + + + +

+ + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Test/Schema.html b/ActiveModelSerializers/Test/Schema.html new file mode 100644 index 00000000..2abae5e9 --- /dev/null +++ b/ActiveModelSerializers/Test/Schema.html @@ -0,0 +1,472 @@ + + + + + + Module: ActiveModelSerializers::Test::Schema + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Test::Schema + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/active_model_serializers/test/schema.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + + + Classes: AssertRequestSchema, AssertResponseSchema, AssertSchema + + +

+ +

Constant Summary

+ +
+ +
MissingSchema = + +
+
Class.new(Minitest::Assertion)
+ +
InvalidSchemaError = + +
+
Class.new(Minitest::Assertion)
+ +
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) assert_request_response_schema(schema_path = nil, message = nil) + + + + + +

+
+ +

May be renamed

+ + +
+
+
+ + +
+ + + + +
+
+
+
+23
+24
+25
+26
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 23
+
+def assert_request_response_schema(schema_path = nil, message = nil)
+  assert_request_schema(schema_path, message)
+  assert_response_schema(schema_path, message)
+end
+
+
+ +
+

+ + - (Object) assert_request_schema(schema_path = nil, message = nil) + + + + + +

+ + + + +
+
+
+
+17
+18
+19
+20
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 17
+
+def assert_request_schema(schema_path = nil, message = nil)
+  matcher = AssertRequestSchema.new(schema_path, request, response, message)
+  assert(matcher.call, matcher.message)
+end
+
+
+ +
+

+ + - (Boolean, Minitest::Assertion) assert_response_schema(schema_path = nil, message = nil) + + + + + +

+
+ +

A Minitest Assertion that test the response is valid against a schema.

+ + +
+
+
+ +
+

Examples:

+ + +
get :index
+assert_response_schema
+ +
+

Parameters:

+
    + +
  • + + schema_path + + + (String) + + + (defaults to: nil) + + + — +
    +

    a custom schema path

    +
    + +
  • + +
  • + + message + + + (String) + + + (defaults to: nil) + + + — +
    +

    a custom error message

    +
    + +
  • + +
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + + — +
    +

    true when the response is valid

    +
    + +
  • + +
  • + + + (Minitest::Assertion) + + + + — +
    +

    when the response is invalid

    +
    + +
  • + +
+ +
+ + + + +
+
+
+
+12
+13
+14
+15
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 12
+
+def assert_response_schema(schema_path = nil, message = nil)
+  matcher = AssertResponseSchema.new(schema_path, request, response, message)
+  assert(matcher.call, matcher.message)
+end
+
+
+ +
+

+ + - (Object) assert_schema(payload, schema_path = nil, message = nil) + + + + + +

+ + + + +
+
+
+
+28
+29
+30
+31
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 28
+
+def assert_schema(payload, schema_path = nil, message = nil)
+  matcher = AssertSchema.new(schema_path, request, response, message, payload)
+  assert(matcher.call, matcher.message)
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Test/Schema/AssertRequestSchema.html b/ActiveModelSerializers/Test/Schema/AssertRequestSchema.html new file mode 100644 index 00000000..489be542 --- /dev/null +++ b/ActiveModelSerializers/Test/Schema/AssertRequestSchema.html @@ -0,0 +1,222 @@ + + + + + + Class: ActiveModelSerializers::Test::Schema::AssertRequestSchema + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Test::Schema::AssertRequestSchema + + + +

+ +
+ +
Inherits:
+
+ AssertSchema + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/test/schema.rb
+ +
+
+ + + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from AssertSchema

+

#message, #payload, #request, #response, #schema_path

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods inherited from AssertSchema

+

#call

+
+

Constructor Details

+ +
+

+ + - (AssertRequestSchema) initialize + + + + + +

+
+ +

Returns a new instance of AssertRequestSchema

+ + +
+
+
+ + +
+ + + + +
+
+
+
+131
+132
+133
+134
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 131
+
+def initialize(*)
+  super
+  @payload = request_params
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Test/Schema/AssertResponseSchema.html b/ActiveModelSerializers/Test/Schema/AssertResponseSchema.html new file mode 100644 index 00000000..851e3801 --- /dev/null +++ b/ActiveModelSerializers/Test/Schema/AssertResponseSchema.html @@ -0,0 +1,222 @@ + + + + + + Class: ActiveModelSerializers::Test::Schema::AssertResponseSchema + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Test::Schema::AssertResponseSchema + + + +

+ +
+ +
Inherits:
+
+ AssertSchema + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/test/schema.rb
+ +
+
+ + + + + + + +

Instance Attribute Summary

+ +

Attributes inherited from AssertSchema

+

#message, #payload, #request, #response, #schema_path

+ + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + + + + + + + +

Methods inherited from AssertSchema

+

#call

+
+

Constructor Details

+ +
+

+ + - (AssertResponseSchema) initialize + + + + + +

+
+ +

Returns a new instance of AssertResponseSchema

+ + +
+
+
+ + +
+ + + + +
+
+
+
+125
+126
+127
+128
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 125
+
+def initialize(*)
+  super
+  @payload = response_body
+end
+
+
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Test/Schema/AssertSchema.html b/ActiveModelSerializers/Test/Schema/AssertSchema.html new file mode 100644 index 00000000..b4f8c1e2 --- /dev/null +++ b/ActiveModelSerializers/Test/Schema/AssertSchema.html @@ -0,0 +1,654 @@ + + + + + + Class: ActiveModelSerializers::Test::Schema::AssertSchema + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Test::Schema::AssertSchema + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/test/schema.rb
+ +
+
+ +
+

Direct Known Subclasses

+

AssertRequestSchema, AssertResponseSchema

+
+ + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (AssertSchema) initialize(schema_path, request, response, message, payload = nil) + + + + + +

+
+ +

Interface may change.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 40
+
+def initialize(schema_path, request, response, message, payload = nil)
+  require_json_schema!
+  @request = request
+  @response = response
+  @payload = payload
+  @schema_path = schema_path || schema_path_default
+  @message = message
+  @document_store = JsonSchema::DocumentStore.new
+  add_schema_to_document_store
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) message (readonly) + + + + + +

+
+ +

Returns the value of attribute message

+ + +
+
+
+ + +
+ + + + +
+
+
+
+37
+38
+39
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 37
+
+def message
+  @message
+end
+
+
+ + + +
+

+ + - (Object) payload (readonly) + + + + + +

+
+ +

Returns the value of attribute payload

+ + +
+
+
+ + +
+ + + + +
+
+
+
+37
+38
+39
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 37
+
+def payload
+  @payload
+end
+
+
+ + + +
+

+ + - (Object) request (readonly) + + + + + +

+
+ +

Returns the value of attribute request

+ + +
+
+
+ + +
+ + + + +
+
+
+
+37
+38
+39
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 37
+
+def request
+  @request
+end
+
+
+ + + +
+

+ + - (Object) response (readonly) + + + + + +

+
+ +

Returns the value of attribute response

+ + +
+
+
+ + +
+ + + + +
+
+
+
+37
+38
+39
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 37
+
+def response
+  @response
+end
+
+
+ + + +
+

+ + - (Object) schema_path (readonly) + + + + + +

+
+ +

Returns the value of attribute schema_path

+ + +
+
+
+ + +
+ + + + +
+
+
+
+37
+38
+39
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 37
+
+def schema_path
+  @schema_path
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) call + + + + + +

+ + + + +
+
+
+
+51
+52
+53
+54
+55
+56
+
+
# File 'lib/active_model_serializers/test/schema.rb', line 51
+
+def call
+  json_schema.expand_references!(store: document_store)
+  status, errors = json_schema.validate(response_body)
+  @message = [message, errors.map(&:to_s).to_sentence].compact.join(': ')
+  status
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Test/Serializer.html b/ActiveModelSerializers/Test/Serializer.html new file mode 100644 index 00000000..b099e01d --- /dev/null +++ b/ActiveModelSerializers/Test/Serializer.html @@ -0,0 +1,227 @@ + + + + + + Module: ActiveModelSerializers::Test::Serializer + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: ActiveModelSerializers::Test::Serializer + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + + + + +
Defined in:
+
lib/active_model_serializers/test/serializer.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + + + Classes: AssertSerializer + + +

+ + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) assert_serializer(expectation, message = nil) + + + + + +

+
+ +

Asserts that the request was rendered with the appropriate serializers.

+ +
# assert that the "PostSerializer" serializer was rendered
+assert_serializer "PostSerializer"
+
+# return a custom error message
+assert_serializer "PostSerializer", "PostSerializer not rendered"
+
+# assert that the instance of PostSerializer was rendered
+assert_serializer PostSerializer
+
+# assert that the "PostSerializer" serializer was rendered
+assert_serializer :post_serializer
+
+# assert that the rendered serializer starts with "Post"
+assert_serializer %r{\APost.+\Z}
+
+# assert that no serializer was rendered
+assert_serializer nil
+
+ + +
+
+
+ + +
+ + + + +
+
+
+
+32
+33
+34
+35
+36
+37
+
+
# File 'lib/active_model_serializers/test/serializer.rb', line 32
+
+def assert_serializer(expectation, message = nil)
+  @assert_serializer.expectation = expectation
+  @assert_serializer.message = message
+  @assert_serializer.response = response
+  assert(@assert_serializer.matches?, @assert_serializer.message)
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/ActiveModelSerializers/Test/Serializer/AssertSerializer.html b/ActiveModelSerializers/Test/Serializer/AssertSerializer.html new file mode 100644 index 00000000..e3fec568 --- /dev/null +++ b/ActiveModelSerializers/Test/Serializer/AssertSerializer.html @@ -0,0 +1,710 @@ + + + + + + Class: ActiveModelSerializers::Test::Serializer::AssertSerializer + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: ActiveModelSerializers::Test::Serializer::AssertSerializer + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/active_model_serializers/test/serializer.rb
+ +
+
+ + + + + +

Instance Attribute Summary (collapse)

+ + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (AssertSerializer) initialize + + + + + +

+
+ +

Returns a new instance of AssertSerializer

+ + +
+
+
+ + +
+ + + + +
+
+
+
+43
+44
+45
+46
+
+
# File 'lib/active_model_serializers/test/serializer.rb', line 43
+
+def initialize
+  @serializers = Set.new
+  @_subscribers = []
+end
+
+
+ +
+ +
+

Instance Attribute Details

+ + + +
+

+ + - (Object) expectation + + + + + +

+
+ +

Returns the value of attribute expectation

+ + +
+
+
+ + +
+ + + + +
+
+
+
+41
+42
+43
+
+
# File 'lib/active_model_serializers/test/serializer.rb', line 41
+
+def expectation
+  @expectation
+end
+
+
+ + + +
+

+ + - (Object) message + + + + + +

+
+ +

Returns the value of attribute message

+ + +
+
+
+ + +
+ + + + +
+
+
+
+40
+41
+42
+
+
# File 'lib/active_model_serializers/test/serializer.rb', line 40
+
+def message
+  @message
+end
+
+
+ + + +
+

+ + - (Object) response + + + + + +

+
+ +

Returns the value of attribute response

+ + +
+
+
+ + +
+ + + + +
+
+
+
+41
+42
+43
+
+
# File 'lib/active_model_serializers/test/serializer.rb', line 41
+
+def response
+  @response
+end
+
+
+ + + +
+

+ + - (Object) serializers (readonly) + + + + + +

+
+ +

Returns the value of attribute serializers

+ + +
+
+
+ + +
+ + + + +
+
+
+
+40
+41
+42
+
+
# File 'lib/active_model_serializers/test/serializer.rb', line 40
+
+def serializers
+  @serializers
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Boolean) matches? + + + + + +

+
+ + +
+
+
+ +

Returns:

+
    + +
  • + + + (Boolean) + + + +
  • + +
+ +
+ + + + +
+
+
+
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+
+
# File 'lib/active_model_serializers/test/serializer.rb', line 52
+
+def matches?
+  # Force body to be read in case the template is being streamed.
+  response.body
+
+  case expectation
+  when a_serializer? then matches_class?
+  when Symbol        then matches_symbol?
+  when String        then matches_string?
+  when Regexp        then matches_regexp?
+  when NilClass      then matches_nil?
+  else fail ArgumentError, 'assert_serializer only accepts a String, Symbol, Regexp, ActiveModel::Serializer, or nil'
+  end
+end
+
+
+ +
+

+ + - (Object) subscribe + + + + + +

+ + + + +
+
+
+
+66
+67
+68
+69
+70
+71
+
+
# File 'lib/active_model_serializers/test/serializer.rb', line 66
+
+def subscribe
+  @_subscribers << ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, payload|
+    serializer = payload[:serializer].name
+    serializers << serializer
+  end
+end
+
+
+ +
+

+ + - (Object) unsubscribe + + + + + +

+ + + + +
+
+
+
+73
+74
+75
+76
+77
+
+
# File 'lib/active_model_serializers/test/serializer.rb', line 73
+
+def unsubscribe
+  @_subscribers.each do |subscriber|
+    ActiveSupport::Notifications.unsubscribe(subscriber)
+  end
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/BulkCacheFetcher.html b/BulkCacheFetcher.html new file mode 100644 index 00000000..30bde12d --- /dev/null +++ b/BulkCacheFetcher.html @@ -0,0 +1,321 @@ + + + + + + Class: BulkCacheFetcher + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: BulkCacheFetcher + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/bulk_cache_fetcher.rb
+ +
+
+ +

Overview

+
+ +

github.com/justinweiss/bulk_cache_fetcher/blob/df1c83e06b9641b7ec3408ec577b37528021190f/lib/bulk_cache_fetcher.rb +Fetches many objects from a cache in order. In the event that some objects +can't be served from the cache, you will have the opportunity to fetch +them in bulk. This allows you to preload and cache entire object +hierarchies, which works particularly well with Rails' nested caching +while avoiding the n+1 queries problem in the uncached case.

+ + +
+
+
+ + +
+

Constant Summary

+ +
+ +
VERSION = + +
+
'1.0.0'.freeze
+ +
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + +
+

Constructor Details

+ +
+

+ + - (BulkCacheFetcher) initialize(cache) + + + + + +

+
+ +

Creates a new bulk cache fetcher, backed by cache. Cache must +respond to the standard Rails cache API, described on guides.rubyonrails.org/caching_with_rails.html

+ + +
+
+
+ + +
+ + + + +
+
+
+
+14
+15
+16
+
+
# File 'lib/bulk_cache_fetcher.rb', line 14
+
+def initialize(cache)
+  @cache = cache
+end
+
+
+ +
+ + +
+

Instance Method Details

+ + +
+

+ + - (Object) fetch(object_identifiers, options = {}, &finder_block) + + + + + +

+
+ +

Returns a list of objects identified by object_identifiers. +fetch will try to find the objects from the cache first. +Identifiers for objects that aren't in the cache will be passed as an +ordered list to finder_block, where you can find the objects +as you see fit. These objects should be returned in the same order as the +identifiers that were passed into the block, because they'll be cached +under their respective keys. The objects returned by fetch +will be returned in the same order as the object_identifiers +passed in.

+ +

options will be passed along unmodified when caching newly +found objects, so you can use it for things like setting cache expiration.

+ + +
+
+
+ + +
+ + + + +
+
+
+
+31
+32
+33
+34
+35
+36
+
+
# File 'lib/bulk_cache_fetcher.rb', line 31
+
+def fetch(object_identifiers, options = {}, &finder_block)
+  object_identifiers = normalize(object_identifiers)
+  cached_keys_with_objects, uncached_identifiers = partition(object_identifiers)
+  found_objects = find(uncached_identifiers, options, &finder_block)
+  coalesce(cache_keys(object_identifiers), cached_keys_with_objects, found_objects)
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/Grape.html b/Grape.html new file mode 100644 index 00000000..1370a0ce --- /dev/null +++ b/Grape.html @@ -0,0 +1,133 @@ + + + + + + Module: Grape + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: Grape + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/grape/helpers/active_model_serializers.rb,
+ lib/grape/formatters/active_model_serializers.rb
+
+ +
+
+ +

Overview

+
+ +

A Grape response formatter that can be used as 'formatter :json, +Grape::Formatters::ActiveModelSerializers'

+ +

Serializer options can be passed as a hash from your Grape endpoint using +env, or better yet user the +render helper in Grape::Helpers::ActiveModelSerializers

+ + +
+
+
+ + +

Defined Under Namespace

+

+ + + Modules: ActiveModelSerializers, Formatters, Helpers + + + + +

+ + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/Grape/ActiveModelSerializers.html b/Grape/ActiveModelSerializers.html new file mode 100644 index 00000000..b989de47 --- /dev/null +++ b/Grape/ActiveModelSerializers.html @@ -0,0 +1,110 @@ + + + + + + Module: Grape::ActiveModelSerializers + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: Grape::ActiveModelSerializers + + + +

+ +
+ + + +
Extended by:
+
ActiveSupport::Concern
+ + + + + + + +
Defined in:
+
lib/grape/active_model_serializers.rb
+ +
+
+ + + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/Grape/Formatters.html b/Grape/Formatters.html new file mode 100644 index 00000000..d6f40f80 --- /dev/null +++ b/Grape/Formatters.html @@ -0,0 +1,115 @@ + + + + + + Module: Grape::Formatters + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: Grape::Formatters + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/grape/formatters/active_model_serializers.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: ActiveModelSerializers + + + + +

+ + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/Grape/Formatters/ActiveModelSerializers.html b/Grape/Formatters/ActiveModelSerializers.html new file mode 100644 index 00000000..18bbd950 --- /dev/null +++ b/Grape/Formatters/ActiveModelSerializers.html @@ -0,0 +1,178 @@ + + + + + + Module: Grape::Formatters::ActiveModelSerializers + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: Grape::Formatters::ActiveModelSerializers + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/grape/formatters/active_model_serializers.rb
+ +
+
+ + + + + + + + + +

+ Class Method Summary + (collapse) +

+ + + + + + +
+

Class Method Details

+ + +
+

+ + + (Object) call(resource, env) + + + + + +

+ + + + +
+
+
+
+8
+9
+10
+11
+12
+
+
# File 'lib/grape/formatters/active_model_serializers.rb', line 8
+
+def self.call(resource, env)
+  serializer_options = {}
+  serializer_options.merge!(env[:active_model_serializer_options]) if env[:active_model_serializer_options]
+  ::ActiveModelSerializers::SerializableResource.new(resource, serializer_options).to_json
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/Grape/Helpers.html b/Grape/Helpers.html new file mode 100644 index 00000000..283ca7af --- /dev/null +++ b/Grape/Helpers.html @@ -0,0 +1,115 @@ + + + + + + Module: Grape::Helpers + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: Grape::Helpers + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/grape/helpers/active_model_serializers.rb
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: ActiveModelSerializers + + + + +

+ + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/Grape/Helpers/ActiveModelSerializers.html b/Grape/Helpers/ActiveModelSerializers.html new file mode 100644 index 00000000..1398c895 --- /dev/null +++ b/Grape/Helpers/ActiveModelSerializers.html @@ -0,0 +1,195 @@ + + + + + + Module: Grape::Helpers::ActiveModelSerializers + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: Grape::Helpers::ActiveModelSerializers + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/grape/helpers/active_model_serializers.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) render(resource, active_model_serializer_options = {}) + + + + + +

+
+ +

A convenience method for passing ActiveModelSerializers serializer options

+ +

Example: To include relationships in the response: render(post, include: +['comments'])

+ +

Example: To include pagination meta data: render(posts, meta: { page: +posts.page, total_pages: posts.total_pages })

+ + +
+
+
+ + +
+ + + + +
+
+
+
+10
+11
+12
+13
+
+
# File 'lib/grape/helpers/active_model_serializers.rb', line 10
+
+def render(resource, active_model_serializer_options = {})
+  env[:active_model_serializer_options] = active_model_serializer_options
+  resource
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/Rails.html b/Rails.html new file mode 100644 index 00000000..7e88d43d --- /dev/null +++ b/Rails.html @@ -0,0 +1,117 @@ + + + + + + Module: Rails + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: Rails + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/generators/rails/resource_override.rb,
+ lib/generators/rails/serializer_generator.rb
+
+ +
+
+ +

Defined Under Namespace

+

+ + + Modules: Generators + + + + +

+ + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/Rails/Generators.html b/Rails/Generators.html new file mode 100644 index 00000000..0d6a96b7 --- /dev/null +++ b/Rails/Generators.html @@ -0,0 +1,117 @@ + + + + + + Module: Rails::Generators + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Module: Rails::Generators + + + +

+ +
+ + + + + + + + +
Defined in:
+
lib/generators/rails/resource_override.rb,
+ lib/generators/rails/serializer_generator.rb
+
+ +
+
+ +

Defined Under Namespace

+

+ + + + + Classes: ResourceGenerator, SerializerGenerator + + +

+ + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/Rails/Generators/ResourceGenerator.html b/Rails/Generators/ResourceGenerator.html new file mode 100644 index 00000000..7b2ef51c --- /dev/null +++ b/Rails/Generators/ResourceGenerator.html @@ -0,0 +1,120 @@ + + + + + + Class: Rails::Generators::ResourceGenerator + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: Rails::Generators::ResourceGenerator + + + +

+ +
+ +
Inherits:
+
+ Object + +
    +
  • Object
  • + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/generators/rails/resource_override.rb
+ +
+
+ + + + + + + + + + +
+ + + + + \ No newline at end of file diff --git a/Rails/Generators/SerializerGenerator.html b/Rails/Generators/SerializerGenerator.html new file mode 100644 index 00000000..e9805067 --- /dev/null +++ b/Rails/Generators/SerializerGenerator.html @@ -0,0 +1,192 @@ + + + + + + Class: Rails::Generators::SerializerGenerator + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Class: Rails::Generators::SerializerGenerator + + + +

+ +
+ +
Inherits:
+
+ NamedBase + +
    +
  • Object
  • + + + + + +
+ show all + +
+ + + + + + + + + +
Defined in:
+
lib/generators/rails/serializer_generator.rb
+ +
+
+ + + + + + + + + +

+ Instance Method Summary + (collapse) +

+ + + + + + + +
+

Instance Method Details

+ + +
+

+ + - (Object) create_serializer_file + + + + + +

+ + + + +
+
+
+
+11
+12
+13
+
+
# File 'lib/generators/rails/serializer_generator.rb', line 11
+
+def create_serializer_file
+  template 'serializer.rb.erb', File.join('app/serializers', class_path, "#{file_name}_serializer.rb")
+end
+
+
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/_index.html b/_index.html new file mode 100644 index 00000000..4d327284 --- /dev/null +++ b/_index.html @@ -0,0 +1,879 @@ + + + + + + Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +

Documentation by YARD 0.8.7.6

+
+

Alphabetic Index

+ +

File Listing

+ + +
+

Namespace Listing A-Z

+ + + + + + + + +
+ + + + + + + + + + + + + + +
    +
  • E
  • +
      + +
    • + Error + + (ActiveModelSerializers::Adapter::JsonApi) + +
    • + +
    • + ErrorSerializer + + (ActiveModel::Serializer) + +
    • + +
    • + ErrorsSerializer + + (ActiveModel::Serializer) + +
    • + +
    +
+ + +
    +
  • F
  • +
      + +
    • + Field + + (ActiveModel::Serializer) + +
    • + +
    • + Fieldset + + (ActiveModel::Serializer) + +
    • + +
    • + Formatters + + (Grape) + +
    • + +
    +
+ + + + + +
+ + + + + +
    +
  • J
  • +
      + +
    • + Json + + (ActiveModel::Serializer::Adapter) + +
    • + +
    • + Json + + (ActiveModelSerializers::Adapter) + +
    • + +
    • + JsonApi + + (ActiveModel::Serializer::Adapter) + +
    • + +
    • + JsonApi + + (ActiveModelSerializers::Adapter) + +
    • + +
    • + JsonPointer + + (ActiveModelSerializers) + +
    • + +
    • + Jsonapi + + (ActiveModelSerializers) + +
    • + +
    • + Jsonapi + + (ActiveModelSerializers::Adapter::JsonApi) + +
    • + +
    +
+ + +
    +
  • K
  • + +
+ + +
    +
  • L
  • +
      + +
    • + Link + + (ActiveModelSerializers::Adapter::JsonApi) + +
    • + +
    • + Links + + (ActiveModel::Serializer) + +
    • + +
    • + Lint + + (ActiveModel::Serializer) + +
    • + +
    • + LogSubscriber + + (ActiveModelSerializers::Logging) + +
    • + +
    • + Logging + + (ActiveModelSerializers) + +
    • + +
    +
+ + +
    +
  • M
  • +
      + +
    • + Macros + + (ActiveModelSerializers::Logging) + +
    • + +
    • + Meta + + (ActiveModelSerializers::Adapter::JsonApi) + +
    • + +
    • + Meta + + (ActiveModel::Serializer) + +
    • + +
    • + Model + + (ActiveModelSerializers) + +
    • + +
    +
+ + +
    +
  • N
  • +
      + +
    • + Null + + (ActiveModelSerializers::Adapter) + +
    • + +
    • + Null + + (ActiveModel::Serializer) + +
    • + +
    • + Null + + (ActiveModel::Serializer::Adapter) + +
    • + +
    +
+ + +
    +
  • P
  • +
      + +
    • + PaginationLinks + + (ActiveModelSerializers::Adapter::JsonApi) + +
    • + +
    +
+ + + + + +
+ + + + + +
    +
  • T
  • +
      + +
    • + Test + + (ActiveModelSerializers) + +
    • + +
    • + Tests + + (ActiveModel::Serializer::Lint) + +
    • + +
    • + Type + + (ActiveModel::Serializer) + +
    • + +
    +
+ + +
    +
  • U
  • +
      + +
    • + UrlHelpers + + (ActiveModelSerializers::SerializationContext) + +
    • + +
    +
+ +
+ +
+ +
+ + + + + \ No newline at end of file diff --git a/class_list.html b/class_list.html new file mode 100644 index 00000000..d5ea34bc --- /dev/null +++ b/class_list.html @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + Class List + + + + +
+

Class List

+ + + + +
+ + diff --git a/css/common.css b/css/common.css new file mode 100644 index 00000000..cf25c452 --- /dev/null +++ b/css/common.css @@ -0,0 +1 @@ +/* Override this file with custom rules */ \ No newline at end of file diff --git a/css/full_list.css b/css/full_list.css new file mode 100644 index 00000000..c918cf19 --- /dev/null +++ b/css/full_list.css @@ -0,0 +1,57 @@ +body { + margin: 0; + font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + font-size: 13px; + height: 101%; + overflow-x: hidden; +} + +h1 { padding: 12px 10px; padding-bottom: 0; margin: 0; font-size: 1.4em; } +.clear { clear: both; } +#search { position: absolute; right: 5px; top: 9px; padding-left: 24px; } +#content.insearch #search, #content.insearch #noresults { background: url(data:image/gif;base64,R0lGODlhEAAQAPYAAP///wAAAPr6+pKSkoiIiO7u7sjIyNjY2J6engAAAI6OjsbGxjIyMlJSUuzs7KamppSUlPLy8oKCghwcHLKysqSkpJqamvT09Pj4+KioqM7OzkRERAwMDGBgYN7e3ujo6Ly8vCoqKjY2NkZGRtTU1MTExDw8PE5OTj4+PkhISNDQ0MrKylpaWrS0tOrq6nBwcKysrLi4uLq6ul5eXlxcXGJiYoaGhuDg4H5+fvz8/KKiohgYGCwsLFZWVgQEBFBQUMzMzDg4OFhYWBoaGvDw8NbW1pycnOLi4ubm5kBAQKqqqiQkJCAgIK6urnJyckpKSjQ0NGpqatLS0sDAwCYmJnx8fEJCQlRUVAoKCggICLCwsOTk5ExMTPb29ra2tmZmZmhoaNzc3KCgoBISEiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCAAAACwAAAAAEAAQAAAHaIAAgoMgIiYlg4kACxIaACEJCSiKggYMCRselwkpghGJBJEcFgsjJyoAGBmfggcNEx0flBiKDhQFlIoCCA+5lAORFb4AJIihCRbDxQAFChAXw9HSqb60iREZ1omqrIPdJCTe0SWI09GBACH5BAkIAAAALAAAAAAQABAAAAdrgACCgwc0NTeDiYozCQkvOTo9GTmDKy8aFy+NOBA7CTswgywJDTIuEjYFIY0JNYMtKTEFiRU8Pjwygy4ws4owPyCKwsMAJSTEgiQlgsbIAMrO0dKDGMTViREZ14kYGRGK38nHguHEJcvTyIEAIfkECQgAAAAsAAAAABAAEAAAB2iAAIKDAggPg4iJAAMJCRUAJRIqiRGCBI0WQEEJJkWDERkYAAUKEBc4Po1GiKKJHkJDNEeKig4URLS0ICImJZAkuQAhjSi/wQyNKcGDCyMnk8u5rYrTgqDVghgZlYjcACTA1sslvtHRgQAh+QQJCAAAACwAAAAAEAAQAAAHZ4AAgoOEhYaCJSWHgxGDJCQARAtOUoQRGRiFD0kJUYWZhUhKT1OLhR8wBaaFBzQ1NwAlkIszCQkvsbOHL7Y4q4IuEjaqq0ZQD5+GEEsJTDCMmIUhtgk1lo6QFUwJVDKLiYJNUd6/hoEAIfkECQgAAAAsAAAAABAAEAAAB2iAAIKDhIWGgiUlh4MRgyQkjIURGRiGGBmNhJWHm4uen4ICCA+IkIsDCQkVACWmhwSpFqAABQoQF6ALTkWFnYMrVlhWvIKTlSAiJiVVPqlGhJkhqShHV1lCW4cMqSkAR1ofiwsjJyqGgQAh+QQJCAAAACwAAAAAEAAQAAAHZ4AAgoOEhYaCJSWHgxGDJCSMhREZGIYYGY2ElYebi56fhyWQniSKAKKfpaCLFlAPhl0gXYNGEwkhGYREUywag1wJwSkHNDU3D0kJYIMZQwk8MjPBLx9eXwuETVEyAC/BOKsuEjYFhoEAIfkECQgAAAAsAAAAABAAEAAAB2eAAIKDhIWGgiUlh4MRgyQkjIURGRiGGBmNhJWHm4ueICImip6CIQkJKJ4kigynKaqKCyMnKqSEK05StgAGQRxPYZaENqccFgIID4KXmQBhXFkzDgOnFYLNgltaSAAEpxa7BQoQF4aBACH5BAkIAAAALAAAAAAQABAAAAdogACCg4SFggJiPUqCJSWGgkZjCUwZACQkgxGEXAmdT4UYGZqCGWQ+IjKGGIUwPzGPhAc0NTewhDOdL7Ykji+dOLuOLhI2BbaFETICx4MlQitdqoUsCQ2vhKGjglNfU0SWmILaj43M5oEAOwAAAAAAAAAAAA==) no-repeat center left; } +#full_list { padding: 0; list-style: none; margin-left: 0; } +#full_list ul { padding: 0; } +#full_list li { padding: 5px; padding-left: 12px; margin: 0; font-size: 1.1em; list-style: none; } +#noresults { padding: 7px 12px; } +#content.insearch #noresults { margin-left: 7px; } +ul.collapsed ul, ul.collapsed li { display: none; } +ul.collapsed.search_uncollapsed { display: block; } +ul.collapsed.search_uncollapsed li { display: list-item; } +li a.toggle { cursor: default; position: relative; left: -5px; top: 4px; text-indent: -999px; width: 10px; height: 9px; margin-left: -10px; display: block; float: left; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAK8AAACvABQqw0mAAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTM5jWRgMAAAAVdEVYdENyZWF0aW9uIFRpbWUAMy8xNC8wOeNZPpQAAAE2SURBVDiNrZTBccIwEEXfelIAHUA6CZ24BGaWO+FuzZAK4k6gg5QAdGAq+Bxs2Yqx7BzyL7Llp/VfzZeQhCTc/ezuGzKKnKSzpCxXJM8fwNXda3df5RZETlIt6YUzSQDs93sl8w3wBZxCCE10GM1OcWbWjB2mWgEH4Mfdyxm3PSepBHibgQE2wLe7r4HjEidpnXMYdQPKEMJcsZ4zs2POYQOcaPfwMVOo58zsAdMt18BuoVDPxUJRacELbXv3hUIX2vYmOUvi8C8ydz/ThjXrqKqqLbDIAdsCKBd+Wo7GWa7o9qzOQHVVVXeAbs+yHHCH4aTsaCOQqunmUy1yBUAXkdMIfMlgF5EXLo2OpV/c/Up7jG4hhHcYLgWzAZXUc2b2ixsfvc/RmNNfOXD3Q/oeL9axJE1yT9IOoUu6MGUkAAAAAElFTkSuQmCC) no-repeat bottom left; } +li.collapsed a.toggle { opacity: 0.5; cursor: default; background-position: top left; } +li { color: #888; cursor: pointer; } +li.deprecated { text-decoration: line-through; font-style: italic; } +li.r1 { background: #f0f0f0; } +li.r2 { background: #fafafa; } +li:hover { background: #ddd; } +li small:before { content: "("; } +li small:after { content: ")"; } +li small.search_info { display: none; } +a:link, a:visited { text-decoration: none; color: #05a; } +li.clicked { background: #05a; color: #ccc; } +li.clicked a:link, li.clicked a:visited { color: #eee; } +li.clicked a.toggle { opacity: 0.5; background-position: bottom right; } +li.collapsed.clicked a.toggle { background-position: top right; } +#search input { border: 1px solid #bbb; -moz-border-radius: 3px; -webkit-border-radius: 3px; } +#nav { margin-left: 10px; font-size: 0.9em; display: none; color: #aaa; } +#nav a:link, #nav a:visited { color: #358; } +#nav a:hover { background: transparent; color: #5af; } +.frames #nav span:after { content: ' | '; } +.frames #nav span:last-child:after { content: ''; } + +.frames #content h1 { margin-top: 0; } +.frames li { white-space: nowrap; cursor: normal; } +.frames li small { display: block; font-size: 0.8em; } +.frames li small:before { content: ""; } +.frames li small:after { content: ""; } +.frames li small.search_info { display: none; } +.frames #search { width: 170px; position: static; margin: 3px; margin-left: 10px; font-size: 0.9em; color: #888; padding-left: 0; padding-right: 24px; } +.frames #content.insearch #search { background-position: center right; } +.frames #search input { width: 110px; } +.frames #nav { display: block; } + +#full_list.insearch li { display: none; } +#full_list.insearch li.found { display: list-item; padding-left: 10px; } +#full_list.insearch li a.toggle { display: none; } +#full_list.insearch li small.search_info { display: block; } diff --git a/css/style.css b/css/style.css new file mode 100644 index 00000000..96307c56 --- /dev/null +++ b/css/style.css @@ -0,0 +1,339 @@ +body { + padding: 0 20px; + font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + font-size: 13px; +} +body.frames { padding: 0 5px; } +h1 { font-size: 25px; margin: 1em 0 0.5em; padding-top: 4px; border-top: 1px dotted #d5d5d5; } +h1.noborder { border-top: 0px; margin-top: 0; padding-top: 4px; } +h1.title { margin-bottom: 10px; } +h1.alphaindex { margin-top: 0; font-size: 22px; } +h2 { + padding: 0; + padding-bottom: 3px; + border-bottom: 1px #aaa solid; + font-size: 1.4em; + margin: 1.8em 0 0.5em; +} +h2 small { font-weight: normal; font-size: 0.7em; display: block; float: right; } +.clear { clear: both; } +.inline { display: inline; } +.inline p:first-child { display: inline; } +.docstring h1, .docstring h2, .docstring h3, .docstring h4 { padding: 0; border: 0; border-bottom: 1px dotted #bbb; } +.docstring h1 { font-size: 1.2em; } +.docstring h2 { font-size: 1.1em; } +.docstring h3, .docstring h4 { font-size: 1em; border-bottom: 0; padding-top: 10px; } +.summary_desc .object_link, .docstring .object_link { font-family: monospace; } +.rdoc-term { padding-right: 25px; font-weight: bold; } +.rdoc-list p { margin: 0; padding: 0; margin-bottom: 4px; } + +/* style for */ +#filecontents table, .docstring table { border-collapse: collapse; } +#filecontents table th, #filecontents table td, +.docstring table th, .docstring table td { border: 1px solid #ccc; padding: 8px; padding-right: 17px; } +#filecontents table tr:nth-child(odd), +.docstring table tr:nth-child(odd) { background: #eee; } +#filecontents table tr:nth-child(even), +.docstring table tr:nth-child(even) { background: #fff; } +#filecontents table th, .docstring table th { background: #fff; } + +/* style for
+ + + + + + + + + + + + +
Build Status + Build Status + Build status +
Code Quality + Code Quality + codebeat + Test Coverage +
Issue Stats + Pulse +
+

About

+ +

ActiveModelSerializers brings convention over configuration to your JSON +generation.

+ +

ActiveModelSerializers works through two components: +serializers and adapters.

+ +

Serializers describe which attributes and relationships should be +serialized.

+ +

Adapters describe how attributes and relationships should be +serialized.

+ +

SerializableResource co-ordinates the resource, Adapter and Serializer to +produce the resource serialization. The serialization has the +#as_json, #to_json and +#serializable_hash methods used by the Rails JSON Renderer. +(SerializableResource actually delegates these methods to the adapter.)

+ +

By default ActiveModelSerializers will use the Attributes +Adapter (no JSON root). But we strongly advise you to use +JsonApi Adapter, which follows 1.0 of the format specified +in jsonapi.org/format. Check how to +change the adapter in the sections below.

+ +

0.10.x is not backward compatible with +0.9.x nor 0.8.x.

+ +

0.10.x is based on the 0.8.0 code, but with a +more flexible architecture. We'd love your help. Learn how you can help here.

+ +

It is generally safe and recommended to use the master branch.

+ +

Installation

+ +

Add this line to your application's Gemfile:

+ +
gem 'active_model_serializers', '~> 0.10.0'
+
+ +

And then execute:

+ +
$ bundle
+ +

Getting Started

+ +

See Getting Started for the +nuts and bolts.

+ +

More information is available in the Guides and High-level behavior.

+ +

Getting Help

+ +

If you find a bug, please report an Issue +and see our contributing guide.

+ +

If you have a question, please post +to Stack Overflow.

+ +

If you'd like to chat, we have a community slack.

+ +

Thanks!

+ +

Documentation

+ + +

High-level behavior

+ +

Choose an adapter from adapters:

+ +
ActiveModelSerializers.config.adapter = :json_api # Default: `:attributes`
+
+ +

Given a serializable +model:

+ +
# either
+class SomeResource < ActiveRecord::Base
+  # columns: title, body
+end
+# or
+class SomeResource < ActiveModelSerializers::Model
+  attr_accessor :title, :body
+end
+
+ +

And initialized as:

+ +
resource = SomeResource.new(title: 'ActiveModelSerializers', body: 'Convention over configuration')
+
+ +

Given a serializer for the serializable model:

+ +
class SomeSerializer < ActiveModel::Serializer
+  attribute :title, key: :name
+  attributes :body
+end
+
+ +

The model can be serialized as:

+ +
options = {}
+serialization = ActiveModelSerializers::SerializableResource.new(resource, options)
+serialization.to_json
+serialization.as_json
+
+ +

SerializableResource delegates to the adapter, which it builds as:

+ +
adapter_options = {}
+adapter = ActiveModelSerializers::Adapter.create(serializer, adapter_options)
+adapter.to_json
+adapter.as_json
+adapter.serializable_hash
+
+ +

The adapter formats the serializer's attributes and associations +(a.k.a. includes):

+ +
serializer_options = {}
+serializer = SomeSerializer.new(resource, serializer_options)
+serializer.attributes
+serializer.associations
+
+ +

See ARCHITECTURE.md for more +information.

+ +

Contributing

+ +

See CONTRIBUTING.md

+ + + + + + \ No newline at end of file diff --git a/file_list.html b/file_list.html new file mode 100644 index 00000000..6bf67e5a --- /dev/null +++ b/file_list.html @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + File List + + + + +
+

File List

+ + + + +
+ + diff --git a/frames.html b/frames.html new file mode 100644 index 00000000..87a4a6df --- /dev/null +++ b/frames.html @@ -0,0 +1,26 @@ + + + + + + Documentation by YARD 0.8.7.6 + + + + diff --git a/index.html b/index.html new file mode 100644 index 00000000..c6383cde --- /dev/null +++ b/index.html @@ -0,0 +1,262 @@ + + + + + + File: README + + — Documentation by YARD 0.8.7.6 + + + + + + + + + + + + + + + + + + + + + +
+

ActiveModelSerializers

+ + + + + + + + + + + + + +
Build Status + Build Status + Build status +
Code Quality + Code Quality + codebeat + Test Coverage +
Issue Stats + Pulse +
+

About

+ +

ActiveModelSerializers brings convention over configuration to your JSON +generation.

+ +

ActiveModelSerializers works through two components: +serializers and adapters.

+ +

Serializers describe which attributes and relationships should be +serialized.

+ +

Adapters describe how attributes and relationships should be +serialized.

+ +

SerializableResource co-ordinates the resource, Adapter and Serializer to +produce the resource serialization. The serialization has the +#as_json, #to_json and +#serializable_hash methods used by the Rails JSON Renderer. +(SerializableResource actually delegates these methods to the adapter.)

+ +

By default ActiveModelSerializers will use the Attributes +Adapter (no JSON root). But we strongly advise you to use +JsonApi Adapter, which follows 1.0 of the format specified +in jsonapi.org/format. Check how to +change the adapter in the sections below.

+ +

0.10.x is not backward compatible with +0.9.x nor 0.8.x.

+ +

0.10.x is based on the 0.8.0 code, but with a +more flexible architecture. We'd love your help. Learn how you can help here.

+ +

It is generally safe and recommended to use the master branch.

+ +

Installation

+ +

Add this line to your application's Gemfile:

+ +
gem 'active_model_serializers', '~> 0.10.0'
+
+ +

And then execute:

+ +
$ bundle
+ +

Getting Started

+ +

See Getting Started for the +nuts and bolts.

+ +

More information is available in the Guides and High-level behavior.

+ +

Getting Help

+ +

If you find a bug, please report an Issue +and see our contributing guide.

+ +

If you have a question, please post +to Stack Overflow.

+ +

If you'd like to chat, we have a community slack.

+ +

Thanks!

+ +

Documentation

+ + +

High-level behavior

+ +

Choose an adapter from adapters:

+ +
ActiveModelSerializers.config.adapter = :json_api # Default: `:attributes`
+
+ +

Given a serializable +model:

+ +
# either
+class SomeResource < ActiveRecord::Base
+  # columns: title, body
+end
+# or
+class SomeResource < ActiveModelSerializers::Model
+  attr_accessor :title, :body
+end
+
+ +

And initialized as:

+ +
resource = SomeResource.new(title: 'ActiveModelSerializers', body: 'Convention over configuration')
+
+ +

Given a serializer for the serializable model:

+ +
class SomeSerializer < ActiveModel::Serializer
+  attribute :title, key: :name
+  attributes :body
+end
+
+ +

The model can be serialized as:

+ +
options = {}
+serialization = ActiveModelSerializers::SerializableResource.new(resource, options)
+serialization.to_json
+serialization.as_json
+
+ +

SerializableResource delegates to the adapter, which it builds as:

+ +
adapter_options = {}
+adapter = ActiveModelSerializers::Adapter.create(serializer, adapter_options)
+adapter.to_json
+adapter.as_json
+adapter.serializable_hash
+
+ +

The adapter formats the serializer's attributes and associations +(a.k.a. includes):

+ +
serializer_options = {}
+serializer = SomeSerializer.new(resource, serializer_options)
+serializer.attributes
+serializer.associations
+
+ +

See ARCHITECTURE.md for more +information.

+ +

Contributing

+ +

See CONTRIBUTING.md

+
+ + + + + \ No newline at end of file diff --git a/js/app.js b/js/app.js new file mode 100644 index 00000000..d933ebcf --- /dev/null +++ b/js/app.js @@ -0,0 +1,219 @@ +function createSourceLinks() { + $('.method_details_list .source_code'). + before("[View source]"); + $('.toggleSource').toggle(function() { + $(this).parent().nextAll('.source_code').slideDown(100); + $(this).text("Hide source"); + }, + function() { + $(this).parent().nextAll('.source_code').slideUp(100); + $(this).text("View source"); + }); +} + +function createDefineLinks() { + var tHeight = 0; + $('.defines').after(" more..."); + $('.toggleDefines').toggle(function() { + tHeight = $(this).parent().prev().height(); + $(this).prev().show(); + $(this).parent().prev().height($(this).parent().height()); + $(this).text("(less)"); + }, + function() { + $(this).prev().hide(); + $(this).parent().prev().height(tHeight); + $(this).text("more..."); + }); +} + +function createFullTreeLinks() { + var tHeight = 0; + $('.inheritanceTree').toggle(function() { + tHeight = $(this).parent().prev().height(); + $(this).parent().toggleClass('showAll'); + $(this).text("(hide)"); + $(this).parent().prev().height($(this).parent().height()); + }, + function() { + $(this).parent().toggleClass('showAll'); + $(this).parent().prev().height(tHeight); + $(this).text("show all"); + }); +} + +function fixBoxInfoHeights() { + $('dl.box dd.r1, dl.box dd.r2').each(function() { + $(this).prev().height($(this).height()); + }); +} + +function searchFrameLinks() { + $('.full_list_link').click(function() { + toggleSearchFrame(this, $(this).attr('href')); + return false; + }); +} + +function toggleSearchFrame(id, link) { + var frame = $('#search_frame'); + $('#search a').removeClass('active').addClass('inactive'); + if (frame.attr('src') == link && frame.css('display') != "none") { + frame.slideUp(100); + $('#search a').removeClass('active inactive'); + } + else { + $(id).addClass('active').removeClass('inactive'); + frame.attr('src', link).slideDown(100); + } +} + +function linkSummaries() { + $('.summary_signature').click(function() { + document.location = $(this).find('a').attr('href'); + }); +} + +function framesInit() { + if (hasFrames) { + document.body.className = 'frames'; + $('#menu .noframes a').attr('href', document.location); + try { + window.top.document.title = $('html head title').text(); + } catch(error) { + // some browsers will not allow this when serving from file:// + // but we don't want to stop the world. + } + } + else { + $('#menu .noframes a').text('frames').attr('href', framesUrl); + } +} + +function keyboardShortcuts() { + if (window.top.frames.main) return; + $(document).keypress(function(evt) { + if (evt.altKey || evt.ctrlKey || evt.metaKey || evt.shiftKey) return; + if (typeof evt.target !== "undefined" && + (evt.target.nodeName == "INPUT" || + evt.target.nodeName == "TEXTAREA")) return; + switch (evt.charCode) { + case 67: case 99: $('#class_list_link').click(); break; // 'c' + case 77: case 109: $('#method_list_link').click(); break; // 'm' + case 70: case 102: $('#file_list_link').click(); break; // 'f' + default: break; + } + }); +} + +function summaryToggle() { + $('.summary_toggle').click(function() { + if (localStorage) { + localStorage.summaryCollapsed = $(this).text(); + } + $('.summary_toggle').each(function() { + $(this).text($(this).text() == "collapse" ? "expand" : "collapse"); + var next = $(this).parent().parent().nextAll('ul.summary').first(); + if (next.hasClass('compact')) { + next.toggle(); + next.nextAll('ul.summary').first().toggle(); + } + else if (next.hasClass('summary')) { + var list = $('