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.
-
#auth_types ⇒ Object
Returns the value of attribute auth_types.
-
#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 |
# 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 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.
62 63 64 |
# File 'lib/elder_docs/config.rb', line 62 def api_servers @api_servers 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 |
#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
64 65 66 |
# File 'lib/elder_docs/config.rb', line 64 def self.instance @instance ||= new end |
Instance Method Details
#default_output_path ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/elder_docs/config.rb', line 51 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
21 22 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 |
# File 'lib/elder_docs/config.rb', line 21 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'] if config['output_path'] @output_path = File.(config['output_path'], config_dir) end rescue => e warn "Warning: Could not load elderdocs.yml: #{e.}" end end |