Module: Integral::ActsAsIntegral

Defined in:
lib/integral/acts_as_integral.rb

Overview

Handles adding Integral behaviour to a class

Constant Summary collapse

DEFAULT_OPTIONS =
{
  icon: 'bi bi-speedometer',
  notifications: { enabled: true },
  tracking: { enabled: true },
  cards: { at_a_glance: true },
  backend_main_menu: { enabled: true, order: 11 },
  backend_create_menu: { enabled: true, order: 1 },
  listable: { enabled: false }
}.freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.backend_at_a_glance_card_itemsObject

Accessor for at a glance card items



31
32
33
# File 'lib/integral/acts_as_integral.rb', line 31

def self.backend_at_a_glance_card_items
  @backend_at_a_glance_card_items ||= []
end

.backend_create_menu_itemsObject

Accessor for backend create menu items



26
27
28
# File 'lib/integral/acts_as_integral.rb', line 26

def self.backend_create_menu_items
  @backend_create_menu_items ||= []
end

.backend_main_menu_itemsObject

Accessor for backend main menu items



21
22
23
# File 'lib/integral/acts_as_integral.rb', line 21

def self.backend_main_menu_items
  @backend_main_menu_items ||= []
end

Class Method Details

.add_backend_at_a_glance_card_item(item) ⇒ Object

Adds item to main backend dashboard at a glance chart

Parameters:

  • item (Class)


48
49
50
# File 'lib/integral/acts_as_integral.rb', line 48

def self.add_backend_at_a_glance_card_item(item)
  backend_at_a_glance_card_items << item unless duplicate_menu_item?(item, backend_at_a_glance_card_items)
end

.add_backend_create_menu_item(item) ⇒ Object

Adds item to create menu, expects Hash or Class



53
54
55
# File 'lib/integral/acts_as_integral.rb', line 53

def self.add_backend_create_menu_item(item)
  backend_create_menu_items << item unless duplicate_menu_item?(item, backend_create_menu_items)
end

.add_backend_main_menu_item(item) ⇒ Object

Adds item to main menu, expects Hash or Class



58
59
60
# File 'lib/integral/acts_as_integral.rb', line 58

def self.add_backend_main_menu_item(item)
  backend_main_menu_items << item unless duplicate_menu_item?(item, backend_main_menu_items)
end

.add_tracked_class(item) ⇒ Object

Adds class to tracked classes

Parameters:

  • item (Class)


42
43
44
# File 'lib/integral/acts_as_integral.rb', line 42

def self.add_tracked_class(item)
  tracked_classes << item unless duplicate_menu_item?(item, tracked_classes)
end

.duplicate_menu_item?(item, menu) ⇒ Boolean

Checks for existing duplicates in menu. Useful in development when app reloads

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/integral/acts_as_integral.rb', line 63

def self.duplicate_menu_item?(item, menu)
  duplicate_found = if item.class == Class
                      menu.map(&:to_s).include?(item.to_s)
                    else
                      menu.select { |item| item.is_a?(Hash) }.map {|item| item[:id] }.include?(item[:id])
                    end

  if duplicate_found
    # Rails.logger.debug("ActsAsIntegral: Item '#{item.to_s}' not added to menu as it already exists.")
    true
  else
    false
  end
end

.tracked_classesObject

Accessor for tracked classes



36
37
38
# File 'lib/integral/acts_as_integral.rb', line 36

def self.tracked_classes
  @tracked_classes ||= []
end