Module: Endeco

Defined in:
lib/endeco.rb,
lib/endeco/cache.rb,
lib/endeco/rails.rb,
lib/endeco/config.rb,
lib/endeco/version.rb

Defined Under Namespace

Modules: Cache, Config Classes: Railtie

Constant Summary collapse

VERSION =
'0.0.5'

Class Method Summary collapse

Class Method Details

.[](key, options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/endeco.rb', line 12

def self.[](key, options = {})
  safe_key = key.sub(/[!\?]$/, '')
  value = if Cache.enable and !options[:force] and Cache.key?(safe_key)
    Cache[safe_key]
  else
    fullpath = expand_path safe_key
    if exists? safe_key
      Cache[safe_key] = File.read fullpath
    else
      if key == safe_key
        nil
      else
        raise Errno::ENOENT, "Errno::ENOENT: No such file or directory - #{fullpath}"
      end
    end
  end
  value.chomp! if value && (!options[:chomp].nil? ? options[:chomp] : Config.default_chomp)
  value
end

.method_missing(symbol, *args) ⇒ Object



6
7
8
9
10
# File 'lib/endeco.rb', line 6

def self.method_missing(symbol, *args)
  safe_name = symbol.to_s.sub /[!\?]$/, ''
  def_methods safe_name
  __send__ symbol, *args
end