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
-
#block ⇒ Proc?
readonly
Meta attribute originally added block.
-
#name ⇒ Symbol
readonly
Meta attribute name.
-
#opts ⇒ Proc
readonly
Meta attribute options.
-
#path ⇒ Symbol
readonly
Meta attribute full path.
Instance Method Summary collapse
- #hide?(value) ⇒ Boolean
-
#initialize(path:, opts:, block:) ⇒ Object
Initializes new meta attribute.
-
#value(object, context) ⇒ Object
Finds attribute value.
Instance Attribute Details
#block ⇒ Proc? (readonly)
Returns Meta attribute originally added block.
24 25 26 |
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 24 def block @block end |
#name ⇒ Symbol (readonly)
Returns Meta attribute name.
15 16 17 |
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 15 def name @name end |
#opts ⇒ Proc (readonly)
Returns Meta attribute options.
21 22 23 |
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 21 def opts @opts end |
#path ⇒ Symbol (readonly)
Returns 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
57 58 59 |
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 57 def hide?(value) (!!opts[:hide_nil] && value.nil?) || (!!opts[:hide_empty] && (value.nil? || (value.respond_to?(:empty?) && value.empty?))) end |
#initialize(path:, opts:, block:) ⇒ Object
Initializes new meta attribute
35 36 37 38 39 40 41 42 43 |
# 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 @normalized_block = normalize_block(opts[:value], opts[:const], block) end |
#value(object, context) ⇒ Object
Finds attribute value
53 54 55 |
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 53 def value(object, context) normalized_block.call(object, context) end |