Class: ElderDocs::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/elder_docs/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/elder_docs/config.rb', line 10

def initialize
  @mount_path = nil
  @api_server = nil
  @auth_types = ['bearer', 'api_key', 'basic', 'oauth2']
  @ui_config = {}
  @admin_password = nil
  @api_servers = []
  @output_path = default_output_path
  @definitions_file = nil
  @articles_file = nil
  load_config_file
end

Instance Attribute Details

#admin_passwordObject

Returns the value of attribute admin_password.



8
9
10
# File 'lib/elder_docs/config.rb', line 8

def admin_password
  @admin_password
end

#api_serverObject

Returns the value of attribute api_server.



8
9
10
# File 'lib/elder_docs/config.rb', line 8

def api_server
  @api_server
end

#api_serversObject (readonly)

Returns the value of attribute api_servers.



66
67
68
# File 'lib/elder_docs/config.rb', line 66

def api_servers
  @api_servers
end

#articles_fileObject

Returns the value of attribute articles_file.



8
9
10
# File 'lib/elder_docs/config.rb', line 8

def articles_file
  @articles_file
end

#auth_typesObject

Returns the value of attribute auth_types.



8
9
10
# File 'lib/elder_docs/config.rb', line 8

def auth_types
  @auth_types
end

#definitions_fileObject

Returns the value of attribute definitions_file.



8
9
10
# File 'lib/elder_docs/config.rb', line 8

def definitions_file
  @definitions_file
end

#mount_pathObject

Returns the value of attribute mount_path.



8
9
10
# File 'lib/elder_docs/config.rb', line 8

def mount_path
  @mount_path
end

#output_pathObject

Returns the value of attribute output_path.



8
9
10
# File 'lib/elder_docs/config.rb', line 8

def output_path
  @output_path
end

#ui_configObject

Returns the value of attribute ui_config.



8
9
10
# File 'lib/elder_docs/config.rb', line 8

def ui_config
  @ui_config
end

Class Method Details

.instanceObject



68
69
70
# File 'lib/elder_docs/config.rb', line 68

def self.instance
  @instance ||= new
end

Instance Method Details

#default_output_pathObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/elder_docs/config.rb', line 55

def default_output_path
  base_path =
    if defined?(Rails) && Rails.root
      Rails.root
    else
      Pathname.new(Dir.pwd)
    end
  
  base_path.join('public', 'elderdocs').to_s
end

#load_config_fileObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/elder_docs/config.rb', line 23

def load_config_file
  # Try to find config file in Rails root or current directory
  config_paths = []
  
  if defined?(Rails) && Rails.root
    config_paths << Rails.root.join('elderdocs.yml').to_s
  end
  
  config_paths << File.join(Dir.pwd, 'elderdocs.yml')
  
  config_path = config_paths.find { |path| File.exist?(path) }
  return unless config_path
  
  begin
    config = YAML.load_file(config_path)
    config_dir = File.dirname(config_path)
    @mount_path = config['mount_path'] if config['mount_path']
    @api_server = config['api_server'] if config['api_server']
    @api_servers = config['api_servers'] if config['api_servers']
    @auth_types = config['auth_types'] if config['auth_types']
    @ui_config = config['ui'] if config['ui']  # YAML uses 'ui' key, but we store as ui_config
    @admin_password = config['admin_password'] if config['admin_password']
    @definitions_file = config['definitions_file'] if config['definitions_file']
    @articles_file = config['articles_file'] if config['articles_file']
    if config['output_path']
      @output_path = File.expand_path(config['output_path'], config_dir)
    end
  rescue => e
    warn "Warning: Could not load elderdocs.yml: #{e.message}"
  end
end