Class: SknRegistry::Content

Inherits:
Object show all
Defined in:
lib/skn_registry.rb

Overview

Child to contain contents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, options = {}) ⇒ Content

Returns a new instance of Content.



75
76
77
78
# File 'lib/skn_registry.rb', line 75

def initialize(item, options = {})
  @item    = item
  @options = { call: item.is_a?(::Proc) }.merge(options)
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



73
74
75
# File 'lib/skn_registry.rb', line 73

def item
  @item
end

#optionsObject (readonly)

Returns the value of attribute options.



73
74
75
# File 'lib/skn_registry.rb', line 73

def options
  @options
end

Instance Method Details

#call(render_proc = true) ⇒ Object

Determine if call is required, without changing original values

  • yes, determine if depends are available – yes, call with depends: #item.call(depends) – no, just #item.call()

  • no, return #item



85
86
87
88
89
90
# File 'lib/skn_registry.rb', line 85

def call(render_proc=true)
  _opts    = options.reject {|k,v| k === :call }
  _do_call = render_proc && options[:call]

  _do_call ? (_opts.empty? ? item.call : item.call( _opts )) : item
end