Class: Moku6::Config

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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, options = {})
  @data = data
  @options = options
end

Instance Attribute Details

#dataObject (readonly)

: Hash[String, untyped]



31
32
33
# File 'lib/moku6/config.rb', line 31

def data
  @data
end

#optionsObject (readonly)

: Hash[Symbol, untyped]



32
33
34
# File 'lib/moku6/config.rb', line 32

def options
  @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(options = {})
  path = options[:config] || DEFAULT_CONFIG_PATH
  file = File.exist?(path) ? (YAML.safe_load_file(path) || {}) : {}
  new(deep_merge(DEFAULTS, file), options)
end

Instance Method Details

#catalog_dirObject

: () -> String?



41
# File 'lib/moku6/config.rb', line 41

def catalog_dir = options[:catalog] || data["catalog_dir"]

#examples_dirObject

: () -> 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_patternObject

: () -> String?



47
# File 'lib/moku6/config.rb', line 47

def naming_pattern = data.dig("naming", "pattern")

#output_dirObject

: () -> String?



44
# File 'lib/moku6/config.rb', line 44

def output_dir = data["output_dir"]

#strict?Boolean

: () -> bool

Returns:

  • (Boolean)


50
# File 'lib/moku6/config.rb', line 50

def strict? = options.fetch(:strict) { !!data.dig("rules", "strict") }

#warn_pii_field_names?Boolean

: () -> bool

Returns:

  • (Boolean)


53
# File 'lib/moku6/config.rb', line 53

def warn_pii_field_names? = !!data.dig("rules", "warn_pii_field_names")