Class: Railstar::CodeHolder

Inherits:
Hash
  • Object
show all
Defined in:
lib/code_holder.rb

Instance Method Summary collapse

Constructor Details

#initialize(code_dir = nil) ⇒ CodeHolder

Returns a new instance of CodeHolder.



9
10
11
# File 'lib/code_holder.rb', line 9

def initialize(code_dir=nil)
  @code_dir = code_dir || "./config/code_holder"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



13
14
15
# File 'lib/code_holder.rb', line 13

def method_missing(name, *args)
  self[name] ||= load(name, *args)
end

Instance Method Details

#codesObject



21
22
23
24
25
26
27
28
# File 'lib/code_holder.rb', line 21

def codes
  dirs = Dir.glob(File.join(@code_dir, "*.csv"))
  files = []
  dirs.each do |dir|
    files << dir.split("/").last
  end
  files.sort.uniq.map{|a| a.sub(/.csv$/, "")}
end

#load(name, options = {}) ⇒ Object



17
18
19
# File 'lib/code_holder.rb', line 17

def load(name, options={})
  CodeList.new(name, @code_dir)
end