Class: Amp::Repositories::Stores::BasicStore
- Defined in:
- lib/amp/repository/store.rb
Overview
BasicStore
This class is the one from which all other stores derive. It implements basic methods #walk, #join, #datafiles, and #copy_list which are the public methods for all stores. All others are basically internal.
Direct Known Subclasses
Constant Summary collapse
- BASIC_DATA_FILES =
%W(data 00manifest.d 00manifest.i 00changelog.d 00changelog.i)
Instance Attribute Summary collapse
-
#create_mode ⇒ Object
readonly
Returns the value of attribute create_mode.
-
#opener ⇒ Object
readonly
Returns the value of attribute opener.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#path_joiner ⇒ Object
Returns the value of attribute path_joiner.
Instance Method Summary collapse
-
#calculate_mode(path) ⇒ Fixnum
Calculates the mode for the user on the file at the given path.
-
#copy_list ⇒ Array<String>
Returns the list of basic files that are crucial for the store to function.
-
#datafiles ⇒ Object
Returns all the data files in the store.
-
#do_walk(relpath, recurse = false) ⇒ (String, String, Fixnum)
Basic walker that is not very smart at all.
-
#initialize(path, openerklass, pathjoiner) ⇒ BasicStore
constructor
A new instance of BasicStore.
-
#join(f) ⇒ Object
Joins the file f to the store’s base path using the path-joiner.
-
#walk {|file| ... } ⇒ Object
Iterates over every file tracked in the store and yield it.
Constructor Details
#initialize(path, openerklass, pathjoiner) ⇒ BasicStore
Returns a new instance of BasicStore.
33 34 35 36 37 38 39 |
# File 'lib/amp/repository/store.rb', line 33 def initialize(path, openerklass, pathjoiner) @path_joiner, @path = pathjoiner, path @create_mode = calculate_mode path @opener = openerklass.new(@path) @opener.create_mode = @create_mode #@opener.default = :open_hg end |
Instance Attribute Details
#create_mode ⇒ Object (readonly)
Returns the value of attribute create_mode.
31 32 33 |
# File 'lib/amp/repository/store.rb', line 31 def create_mode @create_mode end |
#opener ⇒ Object (readonly)
Returns the value of attribute opener.
30 31 32 |
# File 'lib/amp/repository/store.rb', line 30 def opener @opener end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
29 30 31 |
# File 'lib/amp/repository/store.rb', line 29 def path @path end |
#path_joiner ⇒ Object
Returns the value of attribute path_joiner.
28 29 30 |
# File 'lib/amp/repository/store.rb', line 28 def path_joiner @path_joiner end |
Instance Method Details
#calculate_mode(path) ⇒ Fixnum
Calculates the mode for the user on the file at the given path. I guess this saves some wasted chmods.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/amp/repository/store.rb', line 109 def calculate_mode(path) begin mode = File.stat(path).mode if (0777 & ~Amp::Support.UMASK) == (0777 & mode) mode = nil end rescue mode = nil end mode end |
#copy_list ⇒ Array<String>
Returns the list of basic files that are crucial for the store to function.
126 127 128 |
# File 'lib/amp/repository/store.rb', line 126 def copy_list ['requires'] + BASIC_DATA_FILES end |
#datafiles ⇒ Object
Returns all the data files in the store.
68 69 70 |
# File 'lib/amp/repository/store.rb', line 68 def datafiles do_walk('data', true) end |
#do_walk(relpath, recurse = false) ⇒ (String, String, Fixnum)
Basic walker that is not very smart at all. It can recursively search for data files, but it actually uses a queue to do its searching.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/amp/repository/store.rb', line 81 def do_walk(relpath, recurse=false) path = join relpath stripped_len = path.size + File::SEPARATOR.size - 1 list = [] if File.directory?(path) to_visit = [path] while to_visit.any? p = to_visit.shift Dir.stat_list(p, true) do |file, kind, stat| fp = join(file) if kind =~ /file/ && ['.d','.i'].include?(file[-2..-1]) n = fp[stripped_len..-1] list << [n, n, stat.size] elsif kind =~ /directory/ && recurse to_visit << fp end end end end list.sort end |
#join(f) ⇒ Object
Joins the file f to the store’s base path using the path-joiner.
46 47 48 |
# File 'lib/amp/repository/store.rb', line 46 def join(f) @path_joiner.call(@path, f) end |
#walk {|file| ... } ⇒ Object
Iterates over every file tracked in the store and yield it.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/amp/repository/store.rb', line 55 def walk datafiles do |x| yield x end = do_walk '', false .reverse.each do |x| yield x end end |