Class: Slither::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/slither/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Definition

Returns a new instance of Definition.



5
6
7
8
9
# File 'lib/slither/definition.rb', line 5

def initialize(options = {})
  @sections = []
  @templates = {}
  @options = { :align => :right }.merge(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



29
30
31
# File 'lib/slither/definition.rb', line 29

def method_missing(method, *args, &block)
  section(method, *args, &block)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/slither/definition.rb', line 3

def options
  @options
end

#sectionsObject (readonly)

Returns the value of attribute sections.



3
4
5
# File 'lib/slither/definition.rb', line 3

def sections
  @sections
end

#templatesObject (readonly)

Returns the value of attribute templates.



3
4
5
# File 'lib/slither/definition.rb', line 3

def templates
  @templates
end

Instance Method Details

#section(name, options = {}) {|section| ... } ⇒ Object

Yields:

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/slither/definition.rb', line 11

def section(name, options = {}, &block)
  raise( ArgumentError, "Reserved or duplicate section name: '#{name}'") if  
  Section::RESERVED_NAMES.include?( name ) || 
  (@sections.size > 0 && @sections.map{ |s| s.name }.include?( name ))

  section = Slither::Section.new(name, @options.merge(options))
  section.definition = self
  yield(section)
  @sections << section
  section
end

#template(name, options = {}) {|section| ... } ⇒ Object

Yields:



23
24
25
26
27
# File 'lib/slither/definition.rb', line 23

def template(name, options = {}, &block)
  section = Slither::Section.new(name, @options.merge(options))
  yield(section)
  @templates[name] = section
end