Class: Howitzer::Web::SectionDsl::ClassMethods::SectionScope

Inherits:
Object
  • Object
show all
Defined in:
lib/howitzer/web/section_dsl.rb

Overview

This class is for private usage only

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *args, **options, &block) ⇒ SectionScope

Instantiates an anynomous or named section and executes block code in the section scope


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/howitzer/web/section_dsl.rb', line 20

def initialize(name, *args, **options, &block)
  @args = args
  @options = options
  self.section_class =
    if block
      Class.new(Howitzer::Web::BaseSection)
    else
      "#{name}_section".classify.constantize
    end
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#section_classObject

Returns the value of attribute section_class.


16
17
18
# File 'lib/howitzer/web/section_dsl.rb', line 16

def section_class
  @section_class
end

Instance Method Details

#element(*args, **options) ⇒ Object

# Defines an element on the section # @see Howitzer::Web::ElementDsl::ClassMethods#element


35
36
37
# File 'lib/howitzer/web/section_dsl.rb', line 35

def element(*args, **options)
  section_class.send(:element, *args, **options)
end

#finder_argsArray

Note:

If anonymous section uses, then inline selector should be specified. Otherwise arguments should be defined with `.me` dsl method in named section

Returns selector arguments for the section.

Returns:

  • (Array)

Raises:

  • (ArgumentError)

    when finder arguments were not specified


51
52
53
54
55
# File 'lib/howitzer/web/section_dsl.rb', line 51

def finder_args
  return @args if @args.present?

  @finder_args ||= (section_class.default_finder_args || raise(ArgumentError, 'Missing finder arguments'))
end

#finder_optionsArray

Note:

If anonymous section uses, then inline selector should be specified. Otherwise arguments should be defined with `.me` dsl method in named section

Returns selector options for the section.

Returns:

  • (Array)

Raises:

  • (ArgumentError)

    when finder arguments were not specified


63
64
65
66
67
# File 'lib/howitzer/web/section_dsl.rb', line 63

def finder_options
  @options if @args.present? # it is ok to have blank options, so we rely here on the argments

  @finder_options ||= (section_class.default_finder_options || {})
end

#section(name, *args, **options, &block) ⇒ Object

Delegates a section describing to the section class


41
42
43
# File 'lib/howitzer/web/section_dsl.rb', line 41

def section(name, *args, **options, &block)
  section_class.send(:section, name, *args, **options, &block)
end