Class: ActiveGuide::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/active_guide/item.rb

Direct Known Subclasses

Group, Question, Test

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, name, options = {}) ⇒ Item

Returns a new instance of Item.


5
6
7
8
9
10
11
# File 'lib/active_guide/item.rb', line 5

def initialize(parent, name, options = {})
  @parent = parent
  @name = name
  before(&options.delete(:before)) if options[:before].respond_to?(:call)
  after(&options.delete(:after)) if options[:after].respond_to?(:call)
  accept(&options.delete(:if)) if options[:if].respond_to?(:call)
end

Instance Attribute Details

#accept_blockObject (readonly)

Returns the value of attribute accept_block


3
4
5
# File 'lib/active_guide/item.rb', line 3

def accept_block
  @accept_block
end

#after_blockObject (readonly)

Returns the value of attribute after_block


3
4
5
# File 'lib/active_guide/item.rb', line 3

def after_block
  @after_block
end

#before_blockObject (readonly)

Returns the value of attribute before_block


3
4
5
# File 'lib/active_guide/item.rb', line 3

def before_block
  @before_block
end

#nameObject (readonly)

Returns the value of attribute name


3
4
5
# File 'lib/active_guide/item.rb', line 3

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent


3
4
5
# File 'lib/active_guide/item.rb', line 3

def parent
  @parent
end

Instance Method Details

#accept(&block) ⇒ Object


21
22
23
24
# File 'lib/active_guide/item.rb', line 21

def accept(&block)
  raise 'Missing block' unless block_given?
  @accept_block = block
end

#after(&block) ⇒ Object


31
32
33
34
# File 'lib/active_guide/item.rb', line 31

def after(&block)
  raise 'Missing block' unless block_given?
  @after_block = block
end

#before(&block) ⇒ Object


26
27
28
29
# File 'lib/active_guide/item.rb', line 26

def before(&block)
  raise 'Missing block' unless block_given?
  @before_block = block
end

#guideObject


17
18
19
# File 'lib/active_guide/item.rb', line 17

def guide
  @parent.guide
end

#unique_nameObject


13
14
15
# File 'lib/active_guide/item.rb', line 13

def unique_name
  @unique_name ||= (@parent ? @parent.unique_name.to_s + ':' + @name.to_s : @name.to_s)
end