class Outil::OCS::Index
Attributes
path[R]
Public Class Methods
new(params={})
click to toggle source
# File lib/outil/ocs/index.rb, line 7 def initialize params={} @path = params[:path] end
Public Instance Methods
all()
click to toggle source
# File lib/outil/ocs/index.rb, line 45 def all indexed_names.map do |name| read name end end
append(name, ast)
click to toggle source
# File lib/outil/ocs/index.rb, line 15 def append name, ast write_serialize name, ast update_index name end
hard_reset!()
click to toggle source
# File lib/outil/ocs/index.rb, line 57 def hard_reset! Dir["#{@path}/*.ast"].each do |path| File.delete path end File.open(index_path, 'w+') do |file| file.write String.new end end
index_path()
click to toggle source
# File lib/outil/ocs/index.rb, line 11 def index_path @index_path ||= "#{@path}/index" end
indexed_names()
click to toggle source
# File lib/outil/ocs/index.rb, line 26 def indexed_names File.open(index_path, 'r') do |f| f.read.split(/\n/) end.map(&:strip) end
read(name)
click to toggle source
# File lib/outil/ocs/index.rb, line 39 def read(name) File.open("#{@path}/#{name}.ast", 'r') do |file| YAML.load(file.read) end end
read_exec(name)
click to toggle source
# File lib/outil/ocs/index.rb, line 51 def read_exec(name) instance_eval <<-RUBY_EVAL #{Unparser.unparse(read(name))} RUBY_EVAL end
update_index(name)
click to toggle source
# File lib/outil/ocs/index.rb, line 32 def update_index name return if indexed_names.include?(name.to_s) File.open(index_path, 'a') do |file| file.write name.to_s << "\n" end end
write_serialize(name, ast)
click to toggle source
# File lib/outil/ocs/index.rb, line 20 def write_serialize name, ast File.open("#{@path}/#{name}.ast", 'w+') do |file| file.write ast.to_yaml end end