Class: MaxPage::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/max_page/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



5
6
7
8
9
10
# File 'lib/max_page/configuration.rb', line 5

def initialize
  @groups = []
  @metrics = []
  @success_message = "It's all right!"
  @warning_message = "Something is wrong!"
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



3
4
5
# File 'lib/max_page/configuration.rb', line 3

def groups
  @groups
end

#metricsObject (readonly)

Returns the value of attribute metrics.



3
4
5
# File 'lib/max_page/configuration.rb', line 3

def metrics
  @metrics
end

Instance Method Details

#before_action(&block) ⇒ Object

Same method to set and get the before_action block.



20
21
22
23
24
# File 'lib/max_page/configuration.rb', line 20

def before_action(&block)
  return @before_action if block.nil?

  @before_action ||= block
end

#group(name = nil, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/max_page/configuration.rb', line 56

def group(name=nil, &block)
  group = Group.new
  group.name = name
  group.metrics = []

  @current_group = group
  instance_eval(&block)
  @current_group = nil

  @groups << group
end

#metric(name, description: nil, verify: nil, &block) ⇒ Object

Add a metric.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/max_page/configuration.rb', line 41

def metric(name, description: nil, verify: nil, &block)
  metric = Metric.new
  metric.name = name
  metric.description = description
  metric.verify = verify
  metric.block = block

  if @current_group
    metric.group = @current_group
    @current_group.metrics << metric
  end

  @metrics << metric
end

#success_message(message = nil) ⇒ Object

Same method to set and get the title.



27
28
29
30
31
# File 'lib/max_page/configuration.rb', line 27

def success_message(message=nil)
  return @success_message if message.nil?

  @success_message = message
end

#title(title = nil) ⇒ Object

Same method to set and get the title.



13
14
15
16
17
# File 'lib/max_page/configuration.rb', line 13

def title(title=nil)
  return @title if title.nil?

  @title = title
end

#warning_message(message = nil) ⇒ Object

Same method to set and get the title.



34
35
36
37
38
# File 'lib/max_page/configuration.rb', line 34

def warning_message(message=nil)
  return @warning_message if message.nil?

  @warning_message = message
end