Module: Kinbote::Kinfile

Included in:
Attribute, Value
Defined in:
lib/kinbote/kinfile.rb

Instance Method Summary collapse

Instance Method Details

#create_file(type) ⇒ Object



26
27
28
29
# File 'lib/kinbote/kinfile.rb', line 26

def create_file(type)
  FileUtils.mkdir_p(file_path(type, true)) if !File.exist?(file_path(type, true))
  File.open(file_path(type), "w") if !File.exist?(file_path(type))
end

#create_files(types) ⇒ Object



22
23
24
# File 'lib/kinbote/kinfile.rb', line 22

def create_files(types)
  types.each {|type| create_file(type) }
end

#delete_file(type) ⇒ Object



35
36
37
# File 'lib/kinbote/kinfile.rb', line 35

def delete_file(type)
  FileUtils.rm_f(file_path(type))
end

#delete_files(types) ⇒ Object



31
32
33
# File 'lib/kinbote/kinfile.rb', line 31

def delete_files(types)
  types.each {|type| delete_file(type) }
end

#file_size(type) ⇒ Object



39
40
41
42
# File 'lib/kinbote/kinfile.rb', line 39

def file_size(type)
  @file_sizes[type] = File.size(file_path(type)) if !@file_sizes.has_key?(type)
  @file_sizes[type] 
end

#files(type) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/kinbote/kinfile.rb', line 8

def files(type)
  files = []
  if self.is_a?(Attribute)
    files << "/css/attributes/#{@name}/_all" if has_file?(:css)
    @values.each{|v| files += v.files(:css)}
  elsif self.is_a?(Value)
    files << "/css/attributes/#{@attribute}/#{@value}" if has_file?(:css)
  elsif self.is_a?(Page)
    files << "/css/pages/#{@slug}" if has_file?(:css)
    @attributes.each{|a| files += a.files(type) }
  end
  files
end

#has_file?(type) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/kinbote/kinfile.rb', line 48

def has_file?(type)
  File.exist?(file_path(type))
end

#init_filesObject



4
5
6
# File 'lib/kinbote/kinfile.rb', line 4

def init_files
  @file_sizes = {}
end

#reset_file_size(type) ⇒ Object



44
45
46
# File 'lib/kinbote/kinfile.rb', line 44

def reset_file_size(type)
  @file_sizes[type] = File.size(file_path(type))
end