Module: Serega::SeregaPlugins::StringModifiers

Defined in:
lib/serega/plugins/string_modifiers/parse_string_modifiers.rb,
lib/serega/plugins/string_modifiers/string_modifiers.rb

Overview

Plugin :string_modifiers

Allows to specify modifiers as strings.

Serialized attributes must be split with ‘,` and nested attributes can be defined inside brackets `(`, `)`.

Examples:

PostSerializer.plugin :string_modifiers
PostSerializer.new(only: "id,user(id,username)").to_h(post)
PostSerializer.new(except: "user(username,email)").to_h(post)
PostSerializer.new(with: "user(email)").to_h(post)

# Modifiers can still be provided old way with nested hashes or arrays.
PostSerializer.new(with: {user: %i[email, username]}).to_h(post)

Defined Under Namespace

Modules: InstanceMethods Classes: ParseStringModifiers

Class Method Summary collapse

Class Method Details

.load_plugin(serializer_class, **_opts) ⇒ void

This method returns an undefined value.

Applies plugin code to specific serializer

Parameters:

  • serializer_class (Class<Serega>)

    Current serializer class

  • _opts (Hash)

    Plugin options



19
20
21
22
# File 'lib/serega/plugins/string_modifiers/string_modifiers.rb', line 19

def self.load_plugin(serializer_class, **_opts)
  serializer_class.include(InstanceMethods)
  require_relative "parse_string_modifiers"
end

.plugin_nameSymbol

Returns Plugin name.

Returns:

  • (Symbol)

    Plugin name



7
8
9
# File 'lib/serega/plugins/string_modifiers/string_modifiers.rb', line 7

def self.plugin_name
  :string_modifiers
end