Sha256: 7f91d904f0336c764d668b963a575d90b0d5fc1858defafb53fce4c421192222

Contents?: true

Size: 1007 Bytes

Versions: 17

Compression:

Stored size: 1007 Bytes

Contents

class ActiveScaffold::DataStructures::Actions
  include Enumerable

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

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

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

  def each
    @set.each {|item| yield item}
  end

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

  # 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.
  def swap(one, two)
    if include? one
      exclude one
      add two
    else
      exclude two
      add one
    end
  end

  protected

  # called during clone or dup. makes the clone/dup deeper.
  def initialize_copy(from)
    @set = from.instance_variable_get('@set').clone
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
active_scaffold-3.4.17 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.16 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.14 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.13 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.12 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.11 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.10 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.9 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.8 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.7 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.5 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.4 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.3 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.2 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.1 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.0.1 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.0 lib/active_scaffold/data_structures/actions.rb