Class: Nesta::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/nesta/config.rb

Defined Under Namespace

Classes: NotDefined

Constant Summary collapse

SETTINGS =
%w[
  author
  build
  content
  disqus_short_name
  domain
  google_analytics_code
  read_more
  subtitle
  theme
  title
]

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) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/nesta/config.rb', line 44

def method_missing(method, *args)
  if SETTINGS.include?(method.to_s)
    fetch(method.to_s, nil)
  else
    super
  end
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



30
31
32
# File 'lib/nesta/config.rb', line 30

def config
  @config
end

Instance Method Details

#buildObject



56
57
58
# File 'lib/nesta/config.rb', line 56

def build
  fetch('build', {})
end

#fetch(setting, *default) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/nesta/config.rb', line 32

def fetch(setting, *default)
  setting = setting.to_s
  self.config ||= read_config_file(setting)
  env_config = config.fetch(Nesta::App.environment.to_s, {})
  env_config.fetch(
    setting,
    config.fetch(setting) { raise NotDefined.new(setting) }
  )
rescue NotDefined
  default.empty? && raise || (return default.first)
end

#read_moreObject



60
61
62
# File 'lib/nesta/config.rb', line 60

def read_more
  fetch('read_more', 'Continue reading')
end

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

Returns:

  • (Boolean)


52
53
54
# File 'lib/nesta/config.rb', line 52

def respond_to_missing?(method, include_private = false)
  SETTINGS.include?(method.to_s) || super
end