Class: Village::Config

Inherits:
Object
  • Object
show all
Extended by:
Attributes
Defined in:
lib/village/config.rb

Instance Attribute Summary

Attributes included from Attributes

#attributes

Class Method Summary collapse

Class Method Details

.clone(*keys) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/village/config.rb', line 30

def self.clone(*keys)
  unless @attributes.nil?
    options = @attributes.clone
    options.keep_if { |key,value| keys.include?(key.to_sym) } unless keys.nil?
    options
  else
    {}
  end
end

.default_attributesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/village/config.rb', line 14

def self.default_attributes
  { 
    :permalink_regex => 
    { 
      :day => %r[\d{4}/\d{2}/\d{2}/[^/]+],
      :month => %r[\d{4}/\d{2}/[^/]+],
      :year => %r[\d{4}/[^/]+],
      :slug => %r[[^/]+]
      },
    :permalink_format => :day,
    :file_extensions => ["markdown", "erb", "haml"],
    :layout => "village",
    :page_size => 10
    }
end

.initialize_configurations(path = "#{Rails.root}/config/village_config.yml") ⇒ Object



7
8
9
10
11
12
# File 'lib/village/config.rb', line 7

def self.initialize_configurations(path = "#{Rails.root}/config/village_config.yml")
  if File.exists? path and @attributes.nil?
    @attributes = YAML::load(IO.read(path)).with_indifferent_access
    @attributes.reverse_merge!(default_attributes)
  end
end


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

def self.village_permalink_regex(options)
  @attributes[:permalink_format] = options[:permalink_format]
  @attributes[:permalink_regex].try(:[], options[:permalink_format]) or raise_village_permalink_error
end