Class: StateMethods::Partition

Inherits:
Object
  • Object
show all
Defined in:
lib/state_methods/partition.rb

Instance Method Summary collapse

Constructor Details

#initialize(partition = {}, ancestor = nil) ⇒ Partition

Returns a new instance of Partition.



9
10
11
12
13
# File 'lib/state_methods/partition.rb', line 9

def initialize(partition = {}, ancestor = nil)
  partition = {} if partition == [] || partition == :default
  partition = { :all => partition } unless partition.is_a?(Hash) && (ancestor || partition[:all] || partition['all'])
  @index = process(partition, ancestor ? ancestor.index.dup : {}, ancestor ? nil : [])
end

Instance Method Details

#==(p) ⇒ Object



5
6
7
# File 'lib/state_methods/partition.rb', line 5

def ==(p)
  index == p.index
end

#ancestors(s) ⇒ Object



15
16
17
18
19
# File 'lib/state_methods/partition.rb', line 15

def ancestors(s)
  s = s.to_sym
  # unsafe to prepend s but it catches undeclared state
  index[s] || (index[:*] && [s, *(index[:*])]) || [s, :all]
end

#indexObject



21
22
23
# File 'lib/state_methods/partition.rb', line 21

def index
  @index
end