Class: MetabaseQuerySync::Config
- Inherits:
-
Object
- Object
- MetabaseQuerySync::Config
- Defined in:
- lib/metabase_query_sync/config.rb
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(credentials:, paths:) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(credentials:, paths:) ⇒ Config
Returns a new instance of Config.
11 12 13 14 |
# File 'lib/metabase_query_sync/config.rb', line 11 def initialize(credentials:, paths:) @credentials = credentials @paths = paths end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
7 8 9 |
# File 'lib/metabase_query_sync/config.rb', line 7 def credentials @credentials end |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
7 8 9 |
# File 'lib/metabase_query_sync/config.rb', line 7 def paths @paths end |
Class Method Details
.from_file(path, paths: [], host: nil, user: nil, pass: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/metabase_query_sync/config.rb', line 16 def self.from_file(path, paths: [], host: nil, user: nil, pass: nil) if File.exists? path data = YAML.load(ERB.new(File.read(path)).result) result = Dry::Schema.JSON do required(:paths).value(array[:string], min_size?: 1) required(:credentials).hash do required(:host).filled(:string) required(:user).filled(:string) required(:pass).filled(:string) end end.(data) raise "Invalid data provided in config file: #{result.errors.to_h}" if result.failure? end new( credentials: MetabaseCredentials.new( host: host || data["credentials"]["host"], user: user || data["credentials"]["user"], pass: pass || data["credentials"]["pass"] ), paths: paths.empty? ? data["paths"] : paths ) end |