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
-
.backend_at_a_glance_card_items ⇒ Object
Accessor for at a glance card items.
-
.backend_create_menu_items ⇒ Object
Accessor for backend create menu items.
-
.backend_main_menu_items ⇒ Object
Accessor for backend main menu items.
Class Method Summary collapse
-
.add_backend_at_a_glance_card_item(item) ⇒ Object
Adds item to main backend dashboard at a glance chart.
-
.add_backend_create_menu_item(item) ⇒ Object
Adds item to create menu, expects Hash or Class.
-
.add_backend_main_menu_item(item) ⇒ Object
Adds item to main menu, expects Hash or Class.
-
.add_tracked_class(item) ⇒ Object
Adds class to tracked classes.
-
.duplicate_menu_item?(item, menu) ⇒ Boolean
Checks for existing duplicates in menu.
-
.tracked_classes ⇒ Object
Accessor for tracked classes.
Class Attribute Details
.backend_at_a_glance_card_items ⇒ Object
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_items ⇒ Object
Accessor for backend create menu items
26 27 28 |
# File 'lib/integral/acts_as_integral.rb', line 26 def self. @backend_create_menu_items ||= [] end |
.backend_main_menu_items ⇒ Object
Accessor for backend main menu items
21 22 23 |
# File 'lib/integral/acts_as_integral.rb', line 21 def self. @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
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 (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.(item) << item unless (item, ) 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.(item) << item unless (item, ) end |
.add_tracked_class(item) ⇒ Object
Adds class to tracked classes
42 43 44 |
# File 'lib/integral/acts_as_integral.rb', line 42 def self.add_tracked_class(item) tracked_classes << item unless (item, tracked_classes) end |
.duplicate_menu_item?(item, menu) ⇒ Boolean
Checks for existing duplicates in menu. Useful in development when app reloads
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.(item, ) duplicate_found = if item.class == Class .map(&:to_s).include?(item.to_s) else .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_classes ⇒ Object
Accessor for tracked classes
36 37 38 |
# File 'lib/integral/acts_as_integral.rb', line 36 def self.tracked_classes @tracked_classes ||= [] end |