Class: Java::NetSfEhcacheConfig::Configuration

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

Overview

Enhance net.sf.ehcache.config.Configuration with a more Rubyesque API, and add support for using YAML for configuration.

Constant Summary collapse

Factory =
Java::NetSfEhcacheConfig::ConfigurationFactory

Class Method Summary collapse

Class Method Details

.create(*args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ehcache/config.rb', line 26

def self.create(*args)
  result = nil
  case args.size
  when 0
    result = Factory.parseConfiguration()
  when 1
    arg = args.first

    if arg.is_a?(String)
      raise ArgumentError, "Cannot read config file '#{arg}'" unless File.readable?(arg)
      if arg =~ /\.yml$/
        result = Ehcache::Config::YamlConfig.parse_yaml_config(arg)
      else
        result = Factory.parseConfiguration(java.io.File.new(arg))
      end
    else
      result = Factory.parseConfiguration(arg)
    end
  end

  unless result.is_a?(self)
    raise ArgumentError, "Could not create Configuration from: #{args.inspect}"
  end
  result
end

.find(*dirs) ⇒ Object

Searches for an Ehcache configuration file and, if found, returns a Configuration object created from it. The search algorithm looks for files named “ehcache.yml” or “ehcache.xml”, first looking in the provided directories in order, and if not found there then looking in the Ruby $LOAD_PATH. Returns nil if no configuration file is found.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ehcache/config.rb', line 14

def self.find(*dirs)
  file_names = %w[ehcache.yml ehcache.xml]
  dirs += $LOAD_PATH
  dirs.each do |dir|
    file_names.each do |name|
      candidate = File.join(dir, name)
      return create(candidate) if File.exist?(candidate)
    end
  end
  nil
end