Class: Fairy::VFile

Inherits:
Object
  • Object
show all
Defined in:
lib/fairy/share/vfile.rb

Constant Summary collapse

VFILE_EXT =
".vf"
VFILE_HEADER =
"#!fairy vfile"
VFILE_MAGIC =
/^#{Regexp.escape(VFILE_HEADER)}/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVFile

Returns a new instance of VFile.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fairy/share/vfile.rb', line 48

def initialize
  @vfile_name = nil

  @real_file_names = []
  @real_file_names_mutex = Mutex.new
  @real_file_names_cv = XThread::ConditionVariable.new

  @base_name = nil

  @BASE_NAME_CONVERTER = nil
  if CONF.VF_BASE_NAME_CONVERTER
  @BASE_NAME_CONVERTER = eval(CONF.VF_BASE_NAME_CONVERTER)
  end
end

Instance Attribute Details

#base_nameObject (readonly)

Returns the value of attribute base_name.



64
65
66
# File 'lib/fairy/share/vfile.rb', line 64

def base_name
  @base_name
end

#vfile_nameObject

Returns the value of attribute vfile_name.



63
64
65
# File 'lib/fairy/share/vfile.rb', line 63

def vfile_name
  @vfile_name
end

Class Method Details

.real_files(real_files) ⇒ Object



42
43
44
45
46
# File 'lib/fairy/share/vfile.rb', line 42

def VFile.real_files(real_files)
  vfile = new
  vfile.real_file_names = real_files
  vfile
end

.vfile(path) ⇒ Object



36
37
38
39
40
# File 'lib/fairy/share/vfile.rb', line 36

def VFile.vfile(path)
  vfile = new
  vfile.vfile(path)
  vfile
end

.vfile?(path) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fairy/share/vfile.rb', line 18

def VFile.vfile?(path)
  if File.extname(path) == VFILE_EXT
  return true
  end
  if !File.exist?(path)
  return false
  end
  
  File.open(path) do |io|
  l = io.gets
  begin
    return VFILE_MAGIC =~ l
  rescue ArgumentError
    return false
  end
  end
end

Instance Method Details

#create_vfileObject



122
123
124
125
126
127
128
129
130
131
132
# File 'lib/fairy/share/vfile.rb', line 122

def create_vfile
  File.open(@vfile_name, "w") do |io|
  io.puts VFILE_HEADER
  io.puts
  @real_file_names_mutex.synchronize do
    @real_file_names.each do |fn|
 io.puts fn
    end
  end
  end
end

#each_real_file_name(&block) ⇒ Object Also known as: each



117
118
119
# File 'lib/fairy/share/vfile.rb', line 117

def each_real_file_name(&block)
  real_file_names.dup.each &block
end

#marshal_dumpObject

Ruby 1.9 mershal 対応

- Ruby 1.9 


173
174
175
# File 'lib/fairy/share/vfile.rb', line 173

def marshal_dump
  [@vfile_name, @real_file_names]
end

#marshal_load(ary) ⇒ Object



177
178
179
180
181
182
# File 'lib/fairy/share/vfile.rb', line 177

def marshal_load(ary)
  @vfile_name = ary[0]
  @real_file_names = ary[1]
  @real_file_names_mutex = Mutex.new
  @real_file_names_cv = XThread::ConditionVariable.new
end

#real_file_namesObject



83
84
85
86
87
# File 'lib/fairy/share/vfile.rb', line 83

def real_file_names
  @real_file_names_mutex.synchronize do
  @real_file_names
  end
end

#real_file_names=(val) ⇒ Object



90
91
92
93
94
# File 'lib/fairy/share/vfile.rb', line 90

def real_file_names=(val)
  @real_file_names_mutex.synchronize do
  @real_file_names=val
  end
end

#set_real_file(no, url) ⇒ Object

base_regexp = /^#Regexp.escape(base)/

fn = nil
@real_file_names_mutex.synchronize do

ary = @real_file_names.select{|e| base_regexp =~ e}.sort if ary.empty? fn = “#base-000” else fn = ary.last.succ end @real_file_names.push fn

  end
  fn
end


165
166
167
168
169
# File 'lib/fairy/share/vfile.rb', line 165

def set_real_file(no, url)
  @real_file_names_mutex.synchronize do
  @real_file_names[no] = url
  end
end

#vfile(path) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/fairy/share/vfile.rb', line 96

def vfile(path)
  File.open(path) do |io|
  l = io.gets
  unless VFILE_MAGIC =~ l
    ERR::Raise NoVFile, path
  end

  files = []
  for l in io
    l.chomp!
    next if l =~ /^\s*$/
    next if l =~ /^\s*#.*$/
    files.push l
  end
  
  @real_file_names_mutex.synchronize do
    @real_file_names = files
  end
  end
end