Class: Nesta::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/nesta/config.rb

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (Object) author_settings

Returns the value of attribute author_settings



12
13
14
# File 'lib/nesta/config.rb', line 12

def author_settings
  @author_settings
end

+ (Object) settings

Returns the value of attribute settings



12
13
14
# File 'lib/nesta/config.rb', line 12

def settings
  @settings
end

+ (Object) yaml_conf

Returns the value of attribute yaml_conf



12
13
14
# File 'lib/nesta/config.rb', line 12

def yaml_conf
  @yaml_conf
end

Class Method Details

+ (Object) attachment_path(basename = nil)



41
42
43
# File 'lib/nesta/config.rb', line 41

def self.attachment_path(basename = nil)
  get_path(File.join(content_path, "attachments"), basename)
end

+ (Object) author



24
25
26
27
28
29
30
31
# File 'lib/nesta/config.rb', line 24

def self.author
  environment_config = {}
  %w[name uri email].each do |setting|
    variable = "NESTA_AUTHOR__#{setting.upcase}"
    ENV[variable] && environment_config[setting] = ENV[variable]
  end
  environment_config.empty? ? from_yaml("author") : environment_config
end

+ (Boolean) can_use_yaml?

Returns:

  • (Boolean)


66
67
68
# File 'lib/nesta/config.rb', line 66

def self.can_use_yaml?
  ENV.keys.grep(/^NESTA/).empty? && yaml_exists?
end

+ (Object) content_path(basename = nil)



33
34
35
# File 'lib/nesta/config.rb', line 33

def self.content_path(basename = nil)
  get_path(content, basename)
end

+ (Object) from_environment(setting)



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

def self.from_environment(setting)
  value = ENV["NESTA_#{setting.upcase}"]
  overrides = { "true" => true, "false" => false }
  overrides.has_key?(value) ? overrides[value] : value
end

+ (Object) from_yaml(setting)



71
72
73
74
75
76
77
78
79
80
# File 'lib/nesta/config.rb', line 71

def self.from_yaml(setting)
  if can_use_yaml?
    self.yaml_conf ||= YAML::load(ERB.new(IO.read(yaml_path)).result)
    rack_env_conf = self.yaml_conf[Nesta::App.environment.to_s]
    (rack_env_conf && rack_env_conf[setting]) || self.yaml_conf[setting]
  end
rescue Errno::ENOENT  # config file not found
  raise unless Nesta::App.environment == :test
  nil
end

+ (Object) get_path(dirname, basename)



83
84
85
# File 'lib/nesta/config.rb', line 83

def self.get_path(dirname, basename)
  basename.nil? ? dirname : File.join(dirname, basename)
end

+ (Object) method_missing(method, *args)



15
16
17
18
19
20
21
22
# File 'lib/nesta/config.rb', line 15

def self.method_missing(method, *args)
  setting = method.to_s
  if settings.include?(setting)
    from_environment(setting) || from_yaml(setting)
  else
    super
  end
end

+ (Object) page_path(basename = nil)



37
38
39
# File 'lib/nesta/config.rb', line 37

def self.page_path(basename = nil)
  get_path(File.join(content_path, "pages"), basename)
end

+ (Object) read_more



49
50
51
52
# File 'lib/nesta/config.rb', line 49

def self.read_more
  default = 'Continue reading'
  from_environment('read_more') || from_yaml('read_more') || default
end

+ (Boolean) yaml_exists?

Returns:

  • (Boolean)


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

def self.yaml_exists?
  File.exist?(yaml_path)
end

+ (Object) yaml_path



45
46
47
# File 'lib/nesta/config.rb', line 45

def self.yaml_path
  File.expand_path('config/config.yml', Nesta::App.root)
end