Class: ActiveProject::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/active_project/configuration.rb

Overview

Handles configuration for the ActiveProject gem, including adapter settings.

Constant Summary collapse

ADAPTER_CONFIG_CLASSES =

Maps adapter names (symbols) to their specific configuration classes. Add other adapters here when they need specific config classes.

{
  trello: Configurations::TrelloConfiguration,
  jira: Configurations::JiraConfiguration,
  basecamp: Configurations::BasecampConfiguration,
  github_repo: Configurations::GithubConfiguration,
  github_project: Configurations::GithubConfiguration,
  fizzy: Configurations::FizzyConfiguration
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



20
21
22
23
# File 'lib/active_project/configuration.rb', line 20

def initialize
  @adapter_configs = {}
  @user_agent = "ActiveProject Gem (github.com/seuros/active_project)"
end

Instance Attribute Details

#adapter_configsObject (readonly)

Returns the value of attribute adapter_configs.



6
7
8
# File 'lib/active_project/configuration.rb', line 6

def adapter_configs
  @adapter_configs
end

#user_agentObject

Returns the value of attribute user_agent.



7
8
9
# File 'lib/active_project/configuration.rb', line 7

def user_agent
  @user_agent
end

Instance Method Details

#adapter_config(adapter_type, instance_name = :primary) ⇒ BaseAdapterConfiguration?

Retrieves the configuration object for a specific adapter.

Parameters:

  • adapter_type (Symbol)

    The name of the adapter (e.g., :jira, :trello).

  • instance_name (Symbol) (defaults to: :primary)

    The name of the adapter instance (default: :primary).

Returns:

  • (BaseAdapterConfiguration, nil)

    The configuration object or nil if not found.



63
64
65
66
# File 'lib/active_project/configuration.rb', line 63

def adapter_config(adapter_type, instance_name = :primary)
  key = "#{adapter_type}_#{instance_name}".to_sym
  @adapter_configs[key]
end

#add_adapter(adapter_type, instance_name = :primary, options = {}) {|BaseAdapterConfiguration| ... } ⇒ Object

Adds or updates the configuration for a specific adapter. If a block is given and a specific configuration class exists for the adapter, an instance of that class is yielded to the block. Otherwise, a basic configuration object is created from the options hash.

Parameters:

  • adapter_type (Symbol)

    The name of the adapter (e.g., :basecamp, :jira, :trello).

  • instance_name (Symbol, Hash) (defaults to: :primary)

    The name of the adapter instance (default: :primary) or options hash.

  • options (Hash) (defaults to: {})

    Configuration options for the adapter (e.g., site, api_key, token).

Yields:

  • (BaseAdapterConfiguration)

    Yields an adapter-specific configuration object if a block is given.

Raises:

  • (ArgumentError)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/active_project/configuration.rb', line 34

def add_adapter(adapter_type, instance_name = :primary, options = {}, &block)
  raise ArgumentError, "Adapter type must be a Symbol (e.g., :basecamp)" unless adapter_type.is_a?(Symbol)

  # Handle the case where instance_name is actually the options hash
  if instance_name.is_a?(Hash) && options.empty?
    options = instance_name
    instance_name = :primary
  end

  key = "#{adapter_type}_#{instance_name}".to_sym

  config_class = ADAPTER_CONFIG_CLASSES[adapter_type]

  if block && config_class
    adapter_config_obj = config_class.new(options)
    yield adapter_config_obj
    @adapter_configs[key] = adapter_config_obj.freeze
  elsif config_class
    adapter_config_obj = config_class.new(options)
    @adapter_configs[key] = adapter_config_obj.freeze
  else
    @adapter_configs[key] = Configurations::BaseAdapterConfiguration.new(options).freeze
  end
end