Module: Moku::Config

Defined in:
lib/moku/config.rb

Overview

This sets basic configuration for the top-level Moku object. Primarily, separating this out of moku.rb allows for dependents to get what they need without also bringing in the entire project, mostly for testing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object


21
22
23
24
25
26
27
# File 'lib/moku/config.rb', line 21

def method_missing(method, *args, &block)
  if config.respond_to?(method)
    config.send(method, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#configObject


29
30
31
32
33
# File 'lib/moku/config.rb', line 29

def config
  @config ||= Canister.new.tap do |canister|
    settings.each {|k, v| canister.register(k) { v } }
  end
end

#envObject


53
54
55
# File 'lib/moku/config.rb', line 53

def env
  @env ||= ENV["MOKU_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
end

Instance Method Details

#load_settings!(overrides = {}) ⇒ Object


35
36
37
# File 'lib/moku/config.rb', line 35

def load_settings!(overrides = {})
  @settings = Ettin.for(Ettin.settings_files(root/"config", env)).merge!(overrides)
end

#reset!Object


48
49
50
51
# File 'lib/moku/config.rb', line 48

def reset!
  @settings = nil
  @config = nil
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/moku/config.rb', line 17

def respond_to_missing?(method_name, include_private = false)
  config.respond_to?(method_name) || super
end

#rootObject


44
45
46
# File 'lib/moku/config.rb', line 44

def root
  @root ||= Pathname.new(__dir__).parent.parent
end

#settingsObject


39
40
41
42
# File 'lib/moku/config.rb', line 39

def settings
  load_settings! unless @settings
  @settings
end