Module: RDF::Serializers

Defined in:
lib/rdf/serializers.rb,
lib/rdf/serializers/config.rb,
lib/rdf/serializers/scalar.rb,
lib/rdf/serializers/renderers.rb,
lib/rdf/serializers/lookup_chain.rb,
lib/rdf/serializers/relationship.rb,
lib/rdf/serializers/hdnjson_parser.rb,
lib/rdf/serializers/nil_serializer.rb,
lib/rdf/serializers/list_serializer.rb,
lib/rdf/serializers/data_type_helper.rb,
lib/rdf/serializers/object_serializer.rb,
lib/rdf/serializers/serialization_core.rb,
lib/rdf/serializers/hextuple_serializer.rb

Defined Under Namespace

Modules: DataTypeHelper, HextupleSerializer, LookupChain, ObjectSerializer, Relationship, Renderers, Scalar, SerializationCore Classes: Configuration, HndJSONParser, ListSerializer, NilSerializer

Class Method Summary collapse

Class Method Details

.configObject



9
10
11
# File 'lib/rdf/serializers/config.rb', line 9

def self.config
  @config
end

.configure {|@config ||= RDF::Serializers::Configuration.new| ... } ⇒ Object



5
6
7
# File 'lib/rdf/serializers/config.rb', line 5

def self.configure
  yield @config ||= RDF::Serializers::Configuration.new
end

.serializer_for(resource_or_class, options = {}) ⇒ ActiveModel::Serializer

Extracted from active_model_serializers

Parameters:

  • resource (ActiveRecord::Base, ActiveModelSerializers::Model)

Returns:

  • (ActiveModel::Serializer)

    Preferentially returns

    1. resource.serializer_class

    2. ArraySerializer when resource is a collection

    3. options

    4. lookup serializer when resource is a Class



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rdf/serializers.rb', line 28

def serializer_for(resource_or_class, options = {})
  if resource_or_class.respond_to?(:serializer_class)
    resource_or_class.serializer_class
  elsif resource_or_class.respond_to?(:to_ary)
    unless resource_or_class.all? { |resource| resource.is_a?(resource_or_class.first.class) }
      return ListSerializer
    end

    serializer_for(resource_or_class.first)
  else
    resource_class = resource_or_class.class == Class ? resource_or_class : resource_or_class.class
    options.fetch(:serializer) { get_serializer_for(resource_class, options[:namespace]) }
  end
end