Class: SimplestStatus::StatusCollection

Inherits:
Hash
  • Object
show all
Defined in:
lib/simplest_status/status_collection.rb

Defined Under Namespace

Classes: NullStatus

Instance Method Summary collapse

Instance Method Details

#[](status_name) ⇒ Object Also known as: value_for



13
14
15
# File 'lib/simplest_status/status_collection.rb', line 13

def [](status_name)
  status_for(status_name).value
end

#add(status, value = self.size) ⇒ Object



22
23
24
# File 'lib/simplest_status/status_collection.rb', line 22

def add(status, value = self.size)
  self.merge!(status => value)
end

#configure_for(model) ⇒ Object



34
35
36
# File 'lib/simplest_status/status_collection.rb', line 34

def configure_for(model)
  tap { ModelMethods.new(model, self).add }
end

#eachObject



7
8
9
10
11
# File 'lib/simplest_status/status_collection.rb', line 7

def each
  super do |status|
    yield Status.new(status)
  end
end

#for_selectObject



30
31
32
# File 'lib/simplest_status/status_collection.rb', line 30

def for_select
  map(&:for_select)
end

#label_for(value) ⇒ Object



26
27
28
# File 'lib/simplest_status/status_collection.rb', line 26

def label_for(value)
  status_for(value).label
end

#model_accessorObject



42
43
44
# File 'lib/simplest_status/status_collection.rb', line 42

def model_accessor
  status_name.to_s.pluralize
end

#status_for(input) ⇒ Object



18
19
20
# File 'lib/simplest_status/status_collection.rb', line 18

def status_for(input)
  find { |status| status.matches?(input) } || NullStatus.new
end

#status_nameObject



38
39
40
# File 'lib/simplest_status/status_collection.rb', line 38

def status_name
  default
end