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
63 64 65 |
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 63 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 44 45 |
# 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) @normalized_block_signature = SeregaUtils::MethodSignature.call(@normalized_block, pos_limit: 2, keyword_args: []) end |
#value(object, context) ⇒ Object
Finds attribute value
55 56 57 58 59 60 61 |
# File 'lib/serega/plugins/metadata/meta_attribute.rb', line 55 def value(object, context) case normalized_block_signature when "0" then normalized_block.call when "1" then normalized_block.call(object) else normalized_block.call(object, context) end end |