Class: Moku6::Config
- Inherits:
-
Object
- Object
- Moku6::Config
- Defined in:
- lib/moku6/config.rb
Constant Summary collapse
- DEFAULTS =
{ "catalog_dir" => "catalog", "output_dir" => "generated", "naming" => {"pattern" => '^[a-z0-9_]+(\.[a-z0-9_]+)+$'}, "rules" => {"strict" => false, "warn_pii_field_names" => true} }.freeze
- DEFAULT_CONFIG_PATH =
: Hash[String, untyped]
".moku6.yml"
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
: Hash[String, untyped].
-
#options ⇒ Object
readonly
: Hash[Symbol, untyped].
Class Method Summary collapse
-
.deep_merge(base, override) ⇒ Object
: (Hash[String, untyped] base, Hash[String, untyped] override) -> Hash[String, untyped].
-
.load(options = {}) ⇒ Object
: (?Hash[Symbol, untyped] options) -> Config.
Instance Method Summary collapse
-
#catalog_dir ⇒ Object
: () -> String?.
-
#examples_dir ⇒ Object
: () -> String.
-
#generator_out(name) ⇒ Object
: (String | Symbol name) -> String?.
-
#initialize(data, options = {}) ⇒ Config
constructor
: (Hash[String, untyped] data, ?Hash[Symbol, untyped] options) -> void.
-
#naming_pattern ⇒ Object
: () -> String?.
-
#output_dir ⇒ Object
: () -> String?.
-
#strict? ⇒ Boolean
: () -> bool.
-
#warn_pii_field_names? ⇒ Boolean
: () -> bool.
Constructor Details
#initialize(data, options = {}) ⇒ Config
: (Hash[String, untyped] data, ?Hash[Symbol, untyped] options) -> void
35 36 37 38 |
# File 'lib/moku6/config.rb', line 35 def initialize(data, = {}) @data = data @options = end |
Instance Attribute Details
#data ⇒ Object (readonly)
: Hash[String, untyped]
31 32 33 |
# File 'lib/moku6/config.rb', line 31 def data @data end |
#options ⇒ Object (readonly)
: Hash[Symbol, untyped]
32 33 34 |
# File 'lib/moku6/config.rb', line 32 def @options end |
Class Method Details
.deep_merge(base, override) ⇒ Object
: (Hash[String, untyped] base, Hash[String, untyped] override) -> Hash[String, untyped]
25 26 27 28 29 |
# File 'lib/moku6/config.rb', line 25 def self.deep_merge(base, override) base.merge(override) do |_key, b, o| (b.is_a?(Hash) && o.is_a?(Hash)) ? deep_merge(b, o) : o end end |
.load(options = {}) ⇒ Object
: (?Hash[Symbol, untyped] options) -> Config
18 19 20 21 22 |
# File 'lib/moku6/config.rb', line 18 def self.load( = {}) path = [:config] || DEFAULT_CONFIG_PATH file = File.exist?(path) ? (YAML.safe_load_file(path) || {}) : {} new(deep_merge(DEFAULTS, file), ) end |
Instance Method Details
#catalog_dir ⇒ Object
: () -> String?
41 |
# File 'lib/moku6/config.rb', line 41 def catalog_dir = [:catalog] || data["catalog_dir"] |
#examples_dir ⇒ Object
: () -> String
56 |
# File 'lib/moku6/config.rb', line 56 def examples_dir = data["examples_dir"] || "examples/valid" |
#generator_out(name) ⇒ Object
: (String | Symbol name) -> String?
59 |
# File 'lib/moku6/config.rb', line 59 def generator_out(name) = data.dig("generators", name.to_s, "out") |
#naming_pattern ⇒ Object
: () -> String?
47 |
# File 'lib/moku6/config.rb', line 47 def naming_pattern = data.dig("naming", "pattern") |
#output_dir ⇒ Object
: () -> String?
44 |
# File 'lib/moku6/config.rb', line 44 def output_dir = data["output_dir"] |
#strict? ⇒ Boolean
: () -> bool
50 |
# File 'lib/moku6/config.rb', line 50 def strict? = .fetch(:strict) { !!data.dig("rules", "strict") } |
#warn_pii_field_names? ⇒ Boolean
: () -> bool
53 |
# File 'lib/moku6/config.rb', line 53 def warn_pii_field_names? = !!data.dig("rules", "warn_pii_field_names") |