Class: Prospectus::State

Inherits:
Object
  • Object
show all
Defined in:
lib/prospectus/state.rb

Overview

Define a state object that supports modular checks

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ State



7
8
9
# File 'lib/prospectus/state.rb', line 7

def initialize(params = {})
  @options = params
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/prospectus/state.rb', line 5

def value
  @value
end

Class Method Details

.from_block(params = {}, state = nil, &block) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/prospectus/state.rb', line 11

def self.from_block(params = {}, state = nil, &block)
  state ||= State.new(params)
  dsl = StateDSL.new(state, params)
  dsl.instance_eval(&block)
  dsl.load!
  state
end

Instance Method Details

#=~(other) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/prospectus/state.rb', line 19

def =~(other)
  return super unless other.is_a? Prospectus::State
  ov = other.value
  return ov.include?(@value) if ov.is_a? Enumerable
  return @value =~ ov if ov.is_a? Regexp
  @value == ov
end

#to_sObject



27
28
29
# File 'lib/prospectus/state.rb', line 27

def to_s
  @value.to_s
end