Class: Collavre::Integration

Inherits:
Object
  • Object
show all
Defined in:
lib/collavre/integration_registry.rb

Overview

Represents a registered integration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config) ⇒ Integration

Returns a new instance of Integration.



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/collavre/integration_registry.rb', line 96

def initialize(name, config)
  @name = name.to_sym
  @label = config[:label] || name.to_s.titleize
  @icon = config[:icon]
  @description = config[:description]
  @routes = config[:routes]
  @creative_menu_partial = config[:creative_menu_partial]
  @settings_partial = config[:settings_partial]
  @enabled_for = config[:enabled_for] || ->(_creative) { true }

  validate!
end

Instance Attribute Details

#creative_menu_partialObject (readonly)

Returns the value of attribute creative_menu_partial.



93
94
95
# File 'lib/collavre/integration_registry.rb', line 93

def creative_menu_partial
  @creative_menu_partial
end

#descriptionObject (readonly)

Returns the value of attribute description.



93
94
95
# File 'lib/collavre/integration_registry.rb', line 93

def description
  @description
end

#enabled_forObject (readonly)

Returns the value of attribute enabled_for.



93
94
95
# File 'lib/collavre/integration_registry.rb', line 93

def enabled_for
  @enabled_for
end

#iconObject (readonly)

Returns the value of attribute icon.



93
94
95
# File 'lib/collavre/integration_registry.rb', line 93

def icon
  @icon
end

#labelObject (readonly)

Returns the value of attribute label.



93
94
95
# File 'lib/collavre/integration_registry.rb', line 93

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



93
94
95
# File 'lib/collavre/integration_registry.rb', line 93

def name
  @name
end

#routesObject (readonly)

Returns the value of attribute routes.



93
94
95
# File 'lib/collavre/integration_registry.rb', line 93

def routes
  @routes
end

#settings_partialObject (readonly)

Returns the value of attribute settings_partial.



93
94
95
# File 'lib/collavre/integration_registry.rb', line 93

def settings_partial
  @settings_partial
end

Instance Method Details

#enabled_for?(creative) ⇒ Boolean

Check if this integration is enabled for a specific creative

Returns:

  • (Boolean)


110
111
112
113
# File 'lib/collavre/integration_registry.rb', line 110

def enabled_for?(creative)
  return true unless @enabled_for.respond_to?(:call)
  @enabled_for.call(creative)
end

#path_for(method_name, **args) ⇒ Object

Generate a path using the integration’s routes



116
117
118
119
120
# File 'lib/collavre/integration_registry.rb', line 116

def path_for(method_name, **args)
  return nil unless @routes
  return nil unless @routes.respond_to?(method_name)
  @routes.public_send(method_name, **args)
end