Module: Serega::SeregaPlugins::Metadata::MetaAttribute::InstanceMethods

Included in:
Serega::SeregaPlugins::Metadata::MetaAttribute
Defined in:
lib/serega/plugins/metadata/meta_attribute.rb

Overview

Stores Attribute instance methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blockProc (readonly)

Returns Meta attribute originally added block.

Returns:

  • (Proc)

    Meta attribute originally added block



24
25
26
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 24

def block
  @block
end

#nameSymbol (readonly)

Returns Meta attribute name.

Returns:

  • (Symbol)

    Meta attribute name



15
16
17
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 15

def name
  @name
end

#optsProc (readonly)

Returns Meta attribute options.

Returns:

  • (Proc)

    Meta attribute options



21
22
23
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 21

def opts
  @opts
end

#pathSymbol (readonly)

Returns Meta attribute full path.

Returns:

  • (Symbol)

    Meta attribute full path



18
19
20
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 18

def path
  @path
end

Instance Method Details

#hide?(value) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 56

def hide?(value)
  (opts[:hide_nil] && value.nil?) || (opts[:hide_empty] && value.empty?)
end

#initialize(path:, opts:, block:) ⇒ Object

Initializes new meta attribute

Parameters:

  • path (Array<Symbol, String>)

    Path for metadata of attribute

  • opts (Hash)

    metadata attribute options

  • block (Proc)

    Proc that receives object(s) and context and finds value



35
36
37
38
39
40
41
42
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 35

def initialize(path:, opts:, block:)
  check(path, opts, block)

  @name = path.join(".").to_sym
  @path = SeregaUtils::EnumDeepDup.call(path)
  @opts = SeregaUtils::EnumDeepDup.call(opts)
  @block = block
end

#value(object, context) ⇒ Object

Finds attribute value

Parameters:

  • object (Object)

    Serialized object(s)

  • context (Hash, nil)

    Serialization context

Returns:

  • (Object)

    Serialized meta attribute value



52
53
54
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 52

def value(object, context)
  block.call(object, context)
end