Class: TestIds::Configuration

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

Defined Under Namespace

Classes: Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Configuration

Returns a new instance of Configuration.



36
37
38
39
# File 'lib/test_ids/configuration.rb', line 36

def initialize(id)
  @id = id
  @allocator = Allocator.new(self)
end

Instance Attribute Details

#allocatorObject (readonly)

Returns the value of attribute allocator.



34
35
36
# File 'lib/test_ids/configuration.rb', line 34

def allocator
  @allocator
end

Instance Method Details

#binsObject



45
46
47
# File 'lib/test_ids/configuration.rb', line 45

def bins
  @bins ||= Item.new
end

#empty?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/test_ids/configuration.rb', line 88

def empty?
  bins.empty? && softbins.empty? && numbers.empty?
end

#freezeObject



96
97
98
99
100
101
# File 'lib/test_ids/configuration.rb', line 96

def freeze
  bins.freeze
  softbins.freeze
  numbers.freeze
  super
end

#idObject



41
42
43
# File 'lib/test_ids/configuration.rb', line 41

def id
  @id
end

#numbers(&block) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/test_ids/configuration.rb', line 62

def numbers(&block)
  @numbers ||= Item.new
  if block_given?
    @numbers.callback(&block)
  end
  @numbers
end

#numbers=(val) ⇒ Object

An alias for config.numbers.algorithm=



71
72
73
# File 'lib/test_ids/configuration.rb', line 71

def numbers=(val)
  numbers.algorithm = val
end

#softbinsObject



49
50
51
52
53
54
55
# File 'lib/test_ids/configuration.rb', line 49

def softbins
  @softbins ||= Item.new
  if block_given?
    @softbins.callback(&block)
  end
  @softbins
end

#softbins=(val) ⇒ Object

An alias for config.softbins.algorithm=



58
59
60
# File 'lib/test_ids/configuration.rb', line 58

def softbins=(val)
  softbins.algorithm = val
end

#validate!Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/test_ids/configuration.rb', line 75

def validate!
  unless validated?
    if bins.algorithm
      fail 'The TestIds bins configuration cannot be set to an algorithm, only a range set by bins.include and bins.exclude is permitted'
    end
    if bins.callback
      fail 'The TestIds bins configuration cannot be set by a callback, only a range set by bins.include and bins.exclude is permitted'
    end
    @validated = true
    freeze
  end
end

#validated?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/test_ids/configuration.rb', line 92

def validated?
  @validated
end