Module: Ui::Actionable

Included in:
Card, Collapse::Panel, DescriptiveList, Empty, List, Notification, PageHeader, Table
Defined in:
lib/ui/actionable.rb

Constant Summary collapse

Actions =
Types::Array.default([].freeze).of(Types::Callable)

Instance Method Summary collapse

Instance Method Details

#actions(object = model) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/ui/actionable.rb', line 5

def actions(object = model)
  (:nav, class: 'ui-actions', role: 'navigation') do
    render_group(
      actions_list.map do |action|
        action.call(object)
      end
    )
  end
end

#actions_lengthObject



26
27
28
# File 'lib/ui/actionable.rb', line 26

def actions_length
  options.fetch(:actions, Array.new).size
end

#actions_listObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/ui/actionable.rb', line 15

def actions_list
  begin
    Actions[options.fetch(:actions, Array.new)]
  rescue Dry::Types::ConstraintError
    raise Ui::Errors::InvalidActions.new(
      "Actions for #{self.class.to_s} are invalid. Ensure you are passing " \
      "an array of callable objects that will be passed a model"
    )
  end
end

#has_actions?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ui/actionable.rb', line 30

def has_actions?
  actions_list.any?
end