Class: Rosette::Core::SerializerConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/rosette/core/extractor/serializer_config.rb

Overview

Configuration for a serializer. Should generally be configured using an instance of RepoConfig.

Examples:

RepoConfig.new('my_repo')
  .add_serializer('rails', 'yaml/rails') do |ser|
    ser.add_preprocessor('normalization') do |pre|
      pre.set_normalization_form(:nfc)
    end
  end

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, klass, serializer_id) ⇒ SerializerConfig

Creates a new serializer config.

Parameters:

  • name (String)

    The semantic name of this serializer.

  • klass (Class)

    The serializer's class.

  • serializer_id (String)

    The id of the serializer.


35
36
37
38
39
40
# File 'lib/rosette/core/extractor/serializer_config.rb', line 35

def initialize(name, klass, serializer_id)
  @name = name
  @klass = klass
  @serializer_id = serializer_id
  @preprocessors = []
end

Instance Attribute Details

#klassClass (readonly)

Returns the serializer's class.

Returns:

  • (Class)

    the serializer's class.


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rosette/core/extractor/serializer_config.rb', line 27

class SerializerConfig
  attr_reader :name, :klass, :serializer_id, :preprocessors

  # Creates a new serializer config.
  #
  # @param [String] name The semantic name of this serializer.
  # @param [Class] klass The serializer's class.
  # @param [String] serializer_id The id of the serializer.
  def initialize(name, klass, serializer_id)
    @name = name
    @klass = klass
    @serializer_id = serializer_id
    @preprocessors = []
  end

  # Adds a pre-processor to this serializer config. The given block
  # will be passed to the pre-processor's configurator, which will
  # in turn yield the configurator to you.
  #
  # @param [String] preprocessor_id The id of the preprocessor to add.
  # @return [void]
  def add_preprocessor(preprocessor_id, &block)
    klass = PreprocessorId.resolve(preprocessor_id)
    preprocessors << klass.configure(&block)
  end
end

#nameString (readonly)

Returns the semantic name of this serializer.

Returns:

  • (String)

    the semantic name of this serializer.


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rosette/core/extractor/serializer_config.rb', line 27

class SerializerConfig
  attr_reader :name, :klass, :serializer_id, :preprocessors

  # Creates a new serializer config.
  #
  # @param [String] name The semantic name of this serializer.
  # @param [Class] klass The serializer's class.
  # @param [String] serializer_id The id of the serializer.
  def initialize(name, klass, serializer_id)
    @name = name
    @klass = klass
    @serializer_id = serializer_id
    @preprocessors = []
  end

  # Adds a pre-processor to this serializer config. The given block
  # will be passed to the pre-processor's configurator, which will
  # in turn yield the configurator to you.
  #
  # @param [String] preprocessor_id The id of the preprocessor to add.
  # @return [void]
  def add_preprocessor(preprocessor_id, &block)
    klass = PreprocessorId.resolve(preprocessor_id)
    preprocessors << klass.configure(&block)
  end
end

#preprocessorsArray (readonly)

Returns a list of preprocessor configurations.

Returns:

  • (Array)

    a list of preprocessor configurations.


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rosette/core/extractor/serializer_config.rb', line 27

class SerializerConfig
  attr_reader :name, :klass, :serializer_id, :preprocessors

  # Creates a new serializer config.
  #
  # @param [String] name The semantic name of this serializer.
  # @param [Class] klass The serializer's class.
  # @param [String] serializer_id The id of the serializer.
  def initialize(name, klass, serializer_id)
    @name = name
    @klass = klass
    @serializer_id = serializer_id
    @preprocessors = []
  end

  # Adds a pre-processor to this serializer config. The given block
  # will be passed to the pre-processor's configurator, which will
  # in turn yield the configurator to you.
  #
  # @param [String] preprocessor_id The id of the preprocessor to add.
  # @return [void]
  def add_preprocessor(preprocessor_id, &block)
    klass = PreprocessorId.resolve(preprocessor_id)
    preprocessors << klass.configure(&block)
  end
end

#serializer_idString (readonly)

Returns the id of the serializer.

Returns:

  • (String)

    the id of the serializer.


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rosette/core/extractor/serializer_config.rb', line 27

class SerializerConfig
  attr_reader :name, :klass, :serializer_id, :preprocessors

  # Creates a new serializer config.
  #
  # @param [String] name The semantic name of this serializer.
  # @param [Class] klass The serializer's class.
  # @param [String] serializer_id The id of the serializer.
  def initialize(name, klass, serializer_id)
    @name = name
    @klass = klass
    @serializer_id = serializer_id
    @preprocessors = []
  end

  # Adds a pre-processor to this serializer config. The given block
  # will be passed to the pre-processor's configurator, which will
  # in turn yield the configurator to you.
  #
  # @param [String] preprocessor_id The id of the preprocessor to add.
  # @return [void]
  def add_preprocessor(preprocessor_id, &block)
    klass = PreprocessorId.resolve(preprocessor_id)
    preprocessors << klass.configure(&block)
  end
end

Instance Method Details

#add_preprocessor(preprocessor_id, &block) ⇒ void

This method returns an undefined value.

Adds a pre-processor to this serializer config. The given block will be passed to the pre-processor's configurator, which will in turn yield the configurator to you.

Parameters:

  • preprocessor_id (String)

    The id of the preprocessor to add.


48
49
50
51
# File 'lib/rosette/core/extractor/serializer_config.rb', line 48

def add_preprocessor(preprocessor_id, &block)
  klass = PreprocessorId.resolve(preprocessor_id)
  preprocessors << klass.configure(&block)
end