Sha256: 81895fd1947b62b5230bb056bba1bbc2d86be2a0625134405ccebc71fa465159

Contents?: true

Size: 1.31 KB

Versions: 101

Compression:

Stored size: 1.31 KB

Contents

module ActiveScaffold::DataStructures
  class ActionLinks
    include Enumerable

    def initialize
      @set = []
    end

    # adds an ActionLink, creating one from the arguments if need be
    def add(action, options = {})
      link = action.is_a?(ActiveScaffold::DataStructures::ActionLink) ? action : ActiveScaffold::DataStructures::ActionLink.new(action, options)
      # NOTE: this duplicate check should be done by defining the comparison operator for an Action data structure
      @set << link unless @set.any? {|a| a.action == link.action and a.controller == link.controller and a.parameters == link.parameters}
    end
    alias_method :<<, :add

    # finds an ActionLink by matching the action
    def [](val)
      @set.find {|item| item.action == val.to_s}
    end

    def delete(val)
      @set.delete_if{|item| item.action == val.to_s}
    end

    # iterates over the links, possibly by type
    def each(type = nil)
      type = type.to_sym if type
      @set.each {|item|
        next if type and item.type != type
        yield item
      }
    end

    def empty?
      @set.size == 0
    end

    protected

    # called during clone or dup. makes the clone/dup deeper.
    def initialize_copy(from)
      @set = []
      from.instance_variable_get('@set').each { |link| @set << link.clone }
    end
  end
end

Version data entries

101 entries across 101 versions & 3 rubygems

Version Path
brisk-bills-0.8.2 vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
brisk-bills-0.8.1 vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.15 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.14 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.13 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.12 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.11 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.10 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.9 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.8 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.7 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.6 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.5 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
brisk-bills-0.7.0 vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.4 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.3 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.2 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.1 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.24.0 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb
six-updater-web-0.23.7 lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb