Class: Codebot::IntegrationManager
- Inherits:
-
Object
- Object
- Codebot::IntegrationManager
- Defined in:
- lib/codebot/integration_manager.rb
Overview
This class manages the integrations associated with a configuration.
Instance Attribute Summary collapse
-
#config ⇒ Config
readonly
The configuration managed by this class.
Instance Method Summary collapse
-
#create(params) ⇒ Object
Creates a new integration from the given parameters.
-
#destroy(name, params) ⇒ Object
Destroys an integration.
-
#find_integration(name) ⇒ Integration?
Finds an integration given its name.
-
#find_integration!(name) ⇒ Integration
Finds an integration given its name.
-
#find_integration_by_endpoint(endpoint) ⇒ Integration?
Finds an integration given its endpoint.
-
#initialize(config) ⇒ IntegrationManager
constructor
Constructs a new integration manager for a specified configuration.
-
#list(search) ⇒ Object
Lists all integrations, or integrations with names containing the given search term.
-
#update(name, params) ⇒ Object
Updates an integration with the given parameters.
Constructor Details
#initialize(config) ⇒ IntegrationManager
Constructs a new integration manager for a specified configuration.
15 16 17 |
# File 'lib/codebot/integration_manager.rb', line 15 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Config (readonly)
Returns the configuration managed by this class.
10 11 12 |
# File 'lib/codebot/integration_manager.rb', line 10 def config @config end |
Instance Method Details
#create(params) ⇒ Object
Creates a new integration from the given parameters.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/codebot/integration_manager.rb', line 22 def create(params) integration = Integration.new( params.merge(config: { networks: @config.networks }) ) @config.transaction do check_available!(integration.name, integration.endpoint) NetworkManager.new(@config).check_channels!(integration) @config.integrations << integration integration_feedback(integration, :created) unless params[:quiet] end end |
#destroy(name, params) ⇒ Object
Destroys an integration.
53 54 55 56 57 58 59 |
# File 'lib/codebot/integration_manager.rb', line 53 def destroy(name, params) @config.transaction do integration = find_integration!(name) @config.integrations.delete integration integration_feedback(integration, :destroyed) unless params[:quiet] end end |
#find_integration(name) ⇒ Integration?
Finds an integration given its name.
82 83 84 |
# File 'lib/codebot/integration_manager.rb', line 82 def find_integration(name) @config.integrations.find { |intg| intg.name_eql? name } end |
#find_integration!(name) ⇒ Integration
Finds an integration given its name.
99 100 101 102 103 104 105 |
# File 'lib/codebot/integration_manager.rb', line 99 def find_integration!(name) integration = find_integration(name) return integration unless integration.nil? raise CommandError, "an integration with the name #{name.inspect} " \ 'does not exist' end |
#find_integration_by_endpoint(endpoint) ⇒ Integration?
Finds an integration given its endpoint.
90 91 92 |
# File 'lib/codebot/integration_manager.rb', line 90 def find_integration_by_endpoint(endpoint) @config.integrations.find { |intg| intg.endpoint_eql? endpoint } end |
#list(search) ⇒ Object
Lists all integrations, or integrations with names containing the given search term.
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/codebot/integration_manager.rb', line 65 def list(search) @config.transaction do integrations = @config.integrations.dup unless search.nil? integrations.select! do |intg| intg.name.downcase.include? search.downcase end end puts 'No integrations found' if integrations.empty? integrations.each { |intg| show_integration intg } end end |
#update(name, params) ⇒ Object
Updates an integration with the given parameters.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/codebot/integration_manager.rb', line 38 def update(name, params) @config.transaction do integration = find_integration!(name) check_available_except!(params[:name], params[:endpoint], integration) update_channels!(integration, params) NetworkManager.new(@config).check_channels!(integration) integration.update!(params) integration_feedback(integration, :updated) unless params[:quiet] end end |