Class: SmallCage::UpdateList

Inherits:
Object
  • Object
show all
Defined in:
lib/smallcage/update_list.rb

Overview

Updated files list model.

UpdateList doesn’t access file system except list.yml.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list_file, target_uri) ⇒ UpdateList

target_uri must be ended with / when the target is a directory.



18
19
20
21
22
23
24
25
# File 'lib/smallcage/update_list.rb', line 18

def initialize(list_file, target_uri)
  @list_file = list_file
  @target_uri = target_uri
  @expired_src = {}
  @expired_dst = {}
  @update_count = 0
  load
end

Instance Attribute Details

#load_errorObject (readonly)

Returns the value of attribute load_error.



8
9
10
# File 'lib/smallcage/update_list.rb', line 8

def load_error
  @load_error
end

#update_countObject (readonly)

Returns the value of attribute update_count.



8
9
10
# File 'lib/smallcage/update_list.rb', line 8

def update_count
  @update_count
end

Class Method Details

.create(root_path, target_path) ⇒ Object



10
11
12
13
14
15
# File 'lib/smallcage/update_list.rb', line 10

def self.create(root_path, target_path)
  docpath = DocumentPath.new(root_path, target_path)
  uri = docpath.uri
  uri += '/' if docpath.path.directory? && uri[-1, 1] != '/'
  new(root_path + '_smc/tmp/list.yml', uri)
end

Instance Method Details

#expireObject



126
127
128
129
# File 'lib/smallcage/update_list.rb', line 126

def expire
  expire_src
  expire_dst
end

#filter_by_template(template) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/smallcage/update_list.rb', line 84

def filter_by_template(template)
  result = []
  @src_item_map.each do |src, item|
    result << src if item['template'] == template
  end
  result
end

#mtime(srcuri) ⇒ Object



78
79
80
81
82
# File 'lib/smallcage/update_list.rb', line 78

def mtime(srcuri)
  item = @src_item_map[srcuri]
  return -1 unless item
  item['mtime'].to_i
end

#mtimesObject

return src_uri => mtime hash.



74
75
76
# File 'lib/smallcage/update_list.rb', line 74

def mtimes
  Hash[@src_item_map.map { |k,v| [k, v['mtime'].to_i] }]
end

#saveObject



61
62
63
64
65
66
67
# File 'lib/smallcage/update_list.rb', line 61

def save
  FileUtils.mkpath(@list_file.parent)
  @yaml['version'] = VERSION
  open(@list_file, 'w') do |io|
    io << to_yaml
  end
end

#to_yamlObject



69
70
71
# File 'lib/smallcage/update_list.rb', line 69

def to_yaml
  @yaml.to_yaml
end

#update(srcuri, mtime, dsturi, template = nil) ⇒ Object



92
93
94
95
96
# File 'lib/smallcage/update_list.rb', line 92

def update(srcuri, mtime, dsturi, template = nil)
  update_list(srcuri, mtime, dsturi, template)
  stop_expiration(srcuri, dsturi)
  @update_count += 1
end