Class: ActiveScaffold::DataStructures::Actions

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/active_scaffold/data_structures/actions.rb

Instance Method Summary collapse

Constructor Details

#initializeActions

Returns a new instance of Actions.



6
7
8
9
# File 'lib/active_scaffold/data_structures/actions.rb', line 6

def initialize(*)
  @set = []
  add(*)
end

Instance Method Details

#add(*args) ⇒ Object Also known as: <<



16
17
18
# File 'lib/active_scaffold/data_structures/actions.rb', line 16

def add(*args)
  args.each { |arg| @set << arg.to_sym unless @set.include? arg.to_sym }
end

#eachObject



21
22
23
# File 'lib/active_scaffold/data_structures/actions.rb', line 21

def each(&)
  @set.each(&)
end

#exclude(*args) ⇒ Object



11
12
13
14
# File 'lib/active_scaffold/data_structures/actions.rb', line 11

def exclude(*args)
  args.collect!(&:to_sym) # symbolize the args
  @set.reject! { |m| args.include? m } # reject all actions specified
end

#include?(val) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/active_scaffold/data_structures/actions.rb', line 25

def include?(val)
  val.is_a?(Symbol) ? super : @set.any? { |item| item.to_s == val.to_s }
end

#swap(one, two) ⇒ Object

swaps one element in the list with the other. accepts arguments in any order. it just figures out which one is in the list and which one is not.



31
32
33
34
35
36
37
38
39
# File 'lib/active_scaffold/data_structures/actions.rb', line 31

def swap(one, two)
  if include? one
    exclude one
    add two
  else
    exclude two
    add one
  end
end