Sha256: 74855522c42f371165d14ef3be0b1db47a1b45d66673be16dabe5b36544515b0

Contents?: true

Size: 1001 Bytes

Versions: 29

Compression:

Stored size: 1001 Bytes

Contents

class ActiveScaffold::DataStructures::Actions
  include Enumerable

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

  def exclude(*args)
    args.collect!(&: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

29 entries across 29 versions & 1 rubygems

Version Path
active_scaffold-3.4.43 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.42 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.41.1 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.41 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.40 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.39 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.38 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.37 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.36 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.35 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.34 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.33 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.32 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.31 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.30 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.29 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.28 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.27 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.26 lib/active_scaffold/data_structures/actions.rb
active_scaffold-3.4.25 lib/active_scaffold/data_structures/actions.rb