Class: ActiveScaffold::DataStructures::ActionLinks

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb

Instance Method Summary collapse

Constructor Details

#initializeActionLinks

Returns a new instance of ActionLinks.



5
6
7
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb', line 5

def initialize
  @set = []
end

Instance Method Details

#[](val) ⇒ Object

finds an ActionLink by matching the action



18
19
20
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb', line 18

def [](val)
  @set.find {|item| item.action == val.to_s}
end

#add(action, options = {}) ⇒ Object Also known as: <<

adds an ActionLink, creating one from the arguments if need be



10
11
12
13
14
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb', line 10

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

#delete(val) ⇒ Object



22
23
24
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb', line 22

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

#each(type = nil) ⇒ Object

iterates over the links, possibly by type



27
28
29
30
31
32
33
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb', line 27

def each(type = nil)
  type = type.to_sym if type
  @set.each {|item|
    next if type and item.type != type
    yield item
  }
end

#empty?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/action_links.rb', line 35

def empty?
  @set.size == 0
end