Class: ElderDocs::Config
- Inherits:
-
Object
- Object
- ElderDocs::Config
- Defined in:
- lib/elder_docs/config.rb
Instance Attribute Summary collapse
-
#admin_password ⇒ Object
Returns the value of attribute admin_password.
-
#api_server ⇒ Object
Returns the value of attribute api_server.
-
#api_servers ⇒ Object
readonly
Returns the value of attribute api_servers.
-
#articles_file ⇒ Object
Returns the value of attribute articles_file.
-
#auth_types ⇒ Object
Returns the value of attribute auth_types.
-
#definitions_file ⇒ Object
Returns the value of attribute definitions_file.
-
#mount_path ⇒ Object
Returns the value of attribute mount_path.
-
#output_path ⇒ Object
Returns the value of attribute output_path.
-
#ui_config ⇒ Object
Returns the value of attribute ui_config.
Class Method Summary collapse
Instance Method Summary collapse
- #default_output_path ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_config_file ⇒ Object
Constructor Details
#initialize ⇒ Config
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_password ⇒ Object
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_server ⇒ Object
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_servers ⇒ Object (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_file ⇒ Object
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_types ⇒ Object
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_file ⇒ Object
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_path ⇒ Object
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_path ⇒ Object
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_config ⇒ Object
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
.instance ⇒ Object
68 69 70 |
# File 'lib/elder_docs/config.rb', line 68 def self.instance @instance ||= new end |
Instance Method Details
#default_output_path ⇒ Object
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_file ⇒ Object
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.(config['output_path'], config_dir) end rescue => e warn "Warning: Could not load elderdocs.yml: #{e.message}" end end |