Module: Path

Extended by:
Annotation
Defined in:
lib/scout/path.rb,
lib/scout/path/find.rb,
lib/scout/path/util.rb,
lib/scout/path/digest.rb,
lib/scout/persist/path.rb,
lib/scout/resource/path.rb

Constant Summary collapse

HOME =
SLASH =
DOT =

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Annotation

extended, is_annotated?, purge, setup

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, prev = nil, *args, &block) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/scout/path.rb', line 45

def method_missing(name, prev = nil, *args, &block)
  if block_given? || name.to_s.start_with?('to_')
    super name, prev, *args, &block
  else
    join(name, prev)
  end
end

Class Method Details

.add_path(name, map) ⇒ Object



121
122
123
124
# File 'lib/scout/path/find.rb', line 121

def self.add_path(name, map)
  path_maps[name] = map
  @@map_order = nil
end

.append_path(name, map) ⇒ Object



131
132
133
134
# File 'lib/scout/path/find.rb', line 131

def self.append_path(name, map)
  path_maps[name] = map
  map_order.push(name.to_sym)
end

.basic_map_orderObject



103
104
105
# File 'lib/scout/path/find.rb', line 103

def self.basic_map_order
  @@basic_map_order ||= %w(current workflow user home local global usr lib fast cache bulk).collect{|m| m.to_sym }
end

.caller_file(file = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/scout/path/find.rb', line 4

def self.caller_file(file = nil)
  if file.nil?
    caller_dup = caller.dup
    while file = caller_dup.shift
      break unless file =~ /(?:scout|rbbt)\/(?:resource\.rb|workflow\.rb)/ or
        file =~ /(?:scout|rbbt)\/(?:.*\/)?(path|open|final|tsv|refactor|hook|parser)\.rb/ or
        file =~ /(?:scout|rbbt)\/(?:.*\/)?path\/(?:find|refactor|util)\.rb/ or
        file =~ /(?:scout|rbbt)\/persist.rb/ or
        file =~ /(?:scout|rbbt)\/(persist|workflow)\// or
        file =~ /scout\/resource\/produce.rb/ or
        file =~ /modules\/rbbt-util/ or
        file =~ /^<internal:/
    end

    return nil if file.nil?
    file = file.sub(/\.rb[^\w].*/,'.rb')
  end
  file
end

.caller_lib_dir(file = nil, relative_to = ['lib', 'bin', 'README.md']) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/scout/path/find.rb', line 24

def self.caller_lib_dir(file = nil, relative_to = ['lib', 'bin', 'README.md'])

  file = caller_file(file)

  return nil if file.nil?

  file = File.expand_path(file)

  return File.dirname(file) if not relative_to

  relative_to = [relative_to] unless Array === relative_to

  if relative_to.select{|d| File.exist? File.join(file, d)}.any? 
    return Path.setup(file)
  end

  while file != '/'
    dir = File.dirname file

    return dir if relative_to.select{|d| File.exist? File.join(dir, d)}.any?

    file = File.dirname file
  end

  return nil
end

.can_read?(string) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'lib/scout/path/util.rb', line 18

def self.can_read?(string)
  return true if Open.remote?(string)
  return false unless Path.is_filename?(string)
  string = string.find if Path === string
  return false if File.directory?(string)
  return true
end

.can_write?(string) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
# File 'lib/scout/path/util.rb', line 26

def self.can_write?(string)
  return false if Open.remote?(string)
  return false unless Path.is_filename?(string)
  string = string.find if Path === string
  return false if File.directory?(string)
  return File.writable?(string) if File.exist?(string)
  return File.writable?(File.dirname(string))
end

.default_pkgdirObject



10
11
12
# File 'lib/scout/path.rb', line 10

def self.default_pkgdir
  @@default_pkgdir ||= 'scout'
end

.default_pkgdir=(pkgdir) ⇒ Object



14
15
16
# File 'lib/scout/path.rb', line 14

def self.default_pkgdir=(pkgdir)
  @@default_pkgdir = pkgdir
end

.exists_file_or_alternatives(file) ⇒ Object



237
238
239
240
241
242
243
244
245
# File 'lib/scout/path/find.rb', line 237

def self.exists_file_or_alternatives(file)
  file = file.dup if Path === file
  return file if Open.exist?(file) or Open.directory?(file)
  %w(gz bgz zip).each do |extension|
    alt_file = file + '.' + extension
    return alt_file if Open.exist?(alt_file) or Open.directory?(alt_file)
  end
  nil
end

.follow(path, map, map_name = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/scout/path/find.rb', line 51

def self.follow(path, map, map_name = nil)
  map = File.join(map, '{PATH}') unless map.include?("{")
  if path.respond_to?(:pkgdir)
    pkgdir = path.pkgdir
    pkgdir = pkgdir.pkgdir while pkgdir.respond_to?(:pkgdir)
  end
  pkgdir = Path.default_pkgdir if pkgdir.nil?
  file = map.sub('{PKGDIR}', pkgdir).
    sub('{HOME}', ENV["HOME"]).
    sub('{RESOURCE}', path.pkgdir.to_s).
    sub('{PWD}'){ FileUtils.pwd }.
    sub('{TOPLEVEL}'){ path._toplevel }.
    sub('{SUBPATH}'){ path._subpath }.
    sub('{BASENAME}'){ File.basename(path)}.
    sub('{PATH}', path).
    sub('{LIBDIR}'){ path.libdir || (path.pkgdir.respond_to?(:libdir) && path.pkgdir.libdir) || Path.caller_lib_dir || "NOLIBDIR" }.
    sub('{MAPNAME}', map_name.to_s).
    sub('{REMOVE}/', '').
    sub('{REMOVE}', '')

  file.sub!(/\/$/,'') if path._subpath.nil?

  while true
    file.gsub!(/\{(.+)(?<!\\)\/(.+)(?<!\\)\/(.+)\}/) do |m|
      key, orig, replace = m.split(/(?<!\\)\//).collect{|p| p.gsub('\/','/') }
      key_text = follow(path, "#{key}}", map_name)
      key_text[orig] = replace[0..-2] if key_text.include?(orig)
      key_text
    end || break
  end

  file
end

.is_filename?(string, need_to_exists = true) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
# File 'lib/scout/path/util.rb', line 8

def self.is_filename?(string, need_to_exists = true)
  return false if string.nil?
  return true if Path === string
  return true if String === string and
    ! string.include?("\n") and
    (string.length < 265 || string.split("/").select{|p| p.length > 265 }.empty?) and
    (! need_to_exists || File.exist?(string))
  return false
end

.load_path_maps(filename) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/scout/path/find.rb', line 161

def self.load_path_maps(filename)
  Path.setup(filename) unless Path === filename
  if filename.exist?
    filename = filename.find
    begin
      Log.debug "Loading search_paths from #{filename}"
      YAML.load(filename.read).each do |where, location|
        add_path where.to_sym, location
      end
    rescue
      Log.error "Error loading search_paths from #{filename}: " << $!.message
    end
  else
    Log.debug "Could not find search_paths file #{filename}"
  end
end

.located?(path) ⇒ Boolean

Returns:

  • (Boolean)


193
194
195
196
197
198
# File 'lib/scout/path/find.rb', line 193

def self.located?(path)
  # OPEN RESOURCE
  path.slice(0,1) == SLASH || 
    (path.slice(0,1) == HOME && path.slice(1,1) == SLASH) ||
    (path.slice(0,1) == DOT && path.slice(1,1) == SLASH)
end

.map_orderObject



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/scout/path/find.rb', line 107

def self.map_order
  @@map_order ||= 
    begin
      all_maps = path_maps.keys.collect{|m| m.to_s }.reverse
      basic_map_order = self.basic_map_order.collect{|m| m.to_s }

      lib_maps = all_maps.select{|m| m.end_with?('_lib') }
      basic_map_order[basic_map_order.index 'lib'] = lib_maps + ['lib']
      basic_map_order.flatten!

      (basic_map_order & all_maps) + (all_maps - basic_map_order)
    end.collect{|m| m.to_sym }
end

.newer?(path, file, by_link = false) ⇒ Boolean

Is 'file' newer than 'path'? return false if path is newer than file

Returns:

  • (Boolean)


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/scout/path/util.rb', line 179

def self.newer?(path, file, by_link = false)
  return true if not Open.exists?(file)
  path = path.find if Path === path
  file = file.find if Path === file
  if by_link
    patht = File.exist?(path) ? File.lstat(path).mtime : nil
    filet = File.exist?(file) ? File.lstat(file).mtime : nil
  else
    patht = Open.mtime(path)
    filet = Open.mtime(file)
  end
  return true if patht.nil? || filet.nil?
  diff = patht - filet
  return diff if diff < 0
  return false
end

.path_mapsObject



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/scout/path/find.rb', line 85

def self.path_maps
  @@path_maps ||= IndiferentHash.setup({
    :current => "{PWD}/{TOPLEVEL}/{SUBPATH}",
    :home    => "{HOME}/{TOPLEVEL}/{PKGDIR}/{SUBPATH}",
    :user    => "{HOME}/.{PKGDIR}/{TOPLEVEL}/{SUBPATH}",
    :global  => '/{TOPLEVEL}/{PKGDIR}/{SUBPATH}',
    :usr     => '/usr/{TOPLEVEL}/{PKGDIR}/{SUBPATH}',
    :local   => '/usr/local/{TOPLEVEL}/{PKGDIR}/{SUBPATH}',
    :fast    => '/fast/{TOPLEVEL}/{PKGDIR}/{SUBPATH}',
    :cache   => '/cache/{TOPLEVEL}/{PKGDIR}/{SUBPATH}',
    :bulk    => '/bulk/{TOPLEVEL}/{PKGDIR}/{SUBPATH}',
    :lib     => '{LIBDIR}/{TOPLEVEL}/{SUBPATH}',
    :scout_essentials_lib => File.join(Path.caller_lib_dir(__FILE__), "{TOPLEVEL}/{SUBPATH}"),
    :tmp     => '/tmp/{PKGDIR}/{TOPLEVEL}/{SUBPATH}',
    :default => :user
  })
end

.prepend_path(name, map) ⇒ Object



126
127
128
129
# File 'lib/scout/path/find.rb', line 126

def self.prepend_path(name, map)
  path_maps[name] = map
  map_order.unshift(name.to_sym)
end

.sanitize_filename(filename, length = 254) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/scout/path/util.rb', line 35

def self.sanitize_filename(filename, length = 254)
  if filename.length > length
    if filename =~ /(\..{2,9})$/
      extension = $1
    else
      extension = ''
    end

    post_fix = "--#{filename.length}--#{Misc.digest(filename)[0..4]}" + extension

    filename = filename[0..(length - post_fix.length - 1)] << post_fix
  else
    filename
  end
  filename
end

Instance Method Details

#_partsObject



178
179
180
# File 'lib/scout/path/find.rb', line 178

def _parts
  @_parts ||= self.split("/")
end

#_subpathObject



182
183
184
# File 'lib/scout/path/find.rb', line 182

def _subpath
  @subpath ||= _parts.length > 1 ? _parts[1..-1] * "/" : nil
end

#_toplevelObject



186
187
188
# File 'lib/scout/path/find.rb', line 186

def _toplevel
  @toplevel ||= _parts[0]
end

#add_path(name, map) ⇒ Object



146
147
148
149
# File 'lib/scout/path/find.rb', line 146

def add_path(name, map)
  path_maps[name] = map
  @map_order = nil
end

#annotate_found_where(found, where) ⇒ Object



204
205
206
207
208
209
# File 'lib/scout/path/find.rb', line 204

def annotate_found_where(found, where)
  self.annotate(found).tap{|p| 
    p.instance_variable_set("@where", where) 
    p.instance_variable_set("@original", self.annotate(self.dup))
  }
end

#append_path(name, map) ⇒ Object



156
157
158
159
# File 'lib/scout/path/find.rb', line 156

def append_path(name, map)
  path_maps[name] = map
  map_order.push(name.to_sym)
end

#basenameObject



73
74
75
# File 'lib/scout/path/util.rb', line 73

def basename
  self.annotate(File.basename(self))
end

#digest_strObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/scout/path/digest.rb', line 3

def digest_str
  case
  when File.directory?(self)
    files = self.glob("*")

    files = files.reject{|f| File.directory?(f) }

    files = Annotation.purge files

    if files.length > 10
      "Directory MD5: #{files.length} #{Misc.digest_str(files*"\n")}"
    else
      "Directory MD5: #{Misc.digest_str(files)}"
    end
  when self.located? && File.exist?(self)
    "File MD5: #{Misc.digest_file(self)}"
  else
    '\'' + self << '\''
  end
end

#directory?Boolean

Returns:

  • (Boolean)


52
53
54
55
# File 'lib/scout/path/util.rb', line 52

def directory?
  return nil unless self.exist?
  File.directory?(self.find)
end

#dirnameObject



69
70
71
# File 'lib/scout/path/util.rb', line 69

def dirname
  self.annotate(File.dirname(self))
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


276
277
278
279
280
# File 'lib/scout/path/find.rb', line 276

def exist?
  # OPEN
  found = self.find
  File.exist?(found) || File.directory?(found)
end

#final_pkgdirObject



196
197
198
199
200
# File 'lib/scout/path/util.rb', line 196

def final_pkgdir
  final_pkgdir = self.pkgdir
  final_pkgdir = final_pkgdir.pkgdir while final_pkgdir.respond_to?(:pkgdir)
  final_pkgdir
end

#find(where = nil) ⇒ Object



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/scout/path/find.rb', line 247

def find(where = nil)
  if located?
    if File.exist?(File.expand_path(self))
      return self.annotate(File.expand_path(self))
    else
      found = Path.exists_file_or_alternatives(self)
      if found
        return self.annotate(found)
      else
        return self
      end
    end
  end

  return find_all if where == 'all' || where == :all

  return follow(where) if where

  map_order.each do |map_name|
    next unless path_maps.include?(map_name)
    found = follow(map_name, false)

    found = Path.exists_file_or_alternatives(found)
    return annotate_found_where(found, map_name) if found
  end

  return follow(:default)
end

#find_all(caller_lib = nil, search_paths = nil) ⇒ Object



284
285
286
287
288
# File 'lib/scout/path/find.rb', line 284

def find_all(caller_lib = nil, search_paths = nil)
  map_order
    .collect{|where| find(where) }
    .select{|file| file.exist? }.uniq
end

#find_with_extension(extension, *args, produce: true) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/scout/path/find.rb', line 290

def find_with_extension(extension, *args, produce: true)
  found = self.find(*args)
  return found if found.exists? && ! found.directory?
  if Array === extension
    extension.each do |ext|
      found_with_extension = self.set_extension(ext).find
      return found_with_extension if found_with_extension.exists?
    end
  else
    found_with_extension = self.set_extension(extension).find
    return found_with_extension if found_with_extension.exists?
  end
  return found
end

#follow(map_name = :default, annotate = true) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/scout/path/find.rb', line 219

def follow(map_name = :default, annotate = true)
  IndiferentHash.setup(path_maps)
  map = path_maps[map_name] || Path.path_maps[map_name]
  if map.nil? && String === map_name
    map = File.join(map_name, '{TOPLEVEL}/{SUBPATH}')
  end
  raise "Map not found #{Log.fingerprint map_name} not in #{Log.fingerprint path_maps.keys}" if map.nil?
  while Symbol === map
    map_name = map
    map = path_maps[map_name]
  end
  found = Path.follow(self, map, map_name)

  annotate_found_where(found, map_name)  if annotate

  found
end

#get_extension(multiple = false) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/scout/path/util.rb', line 124

def get_extension(multiple = false)
  parts = File.basename(self).split(".")
  extension = [parts.pop]

  while parts.length < 5
    extension << [parts.pop]
  end if multiple

  extension * "."
end

#glob(pattern = "*") ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/scout/path/util.rb', line 77

def glob(pattern = "*")
  if self.include? "*"
    if located?
      Dir.glob(self)
    else
      self.glob_all
    end
  else
    return [] unless self.exist? 
    found = self.find

    exp = File.join(found, pattern)
    paths = Dir.glob(exp).collect{|f| self.annotate(f) }

    paths.each do |p|
      p.original = File.join(found.original, p.sub(/^#{found}/, ''))
    end if found.original

    paths
  end
end

#glob_all(pattern = nil, caller_lib = nil, search_paths = nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/scout/path/util.rb', line 103

def glob_all(pattern = nil, caller_lib = nil, search_paths = nil)
  search_paths ||= self.path_maps || Path.path_maps
  search_paths = search_paths.dup

  search_paths.keys.collect do |where| 
    found = find(where)
    next unless found.located?

    paths = pattern ? found.glob(pattern) : found.glob

    paths = paths.collect{|p| self.annotate p }

    paths = paths.each do |p|
      p.original = File.join(found.original, p.sub(/^#{found}/, ''))
      p.where = where
    end if found.original and pattern

    paths
  end.flatten.uniq
end

#glob_namesObject



99
100
101
# File 'lib/scout/path/util.rb', line 99

def glob_names(...)
  glob(...).collect{|f| f.basename }
end

#identifyObject



54
55
56
# File 'lib/scout/resource/path.rb', line 54

def identify
  Resource.identify(self)
end

#join(subpath = nil, prevpath = nil) ⇒ Object Also known as: [], /



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/scout/path.rb', line 30

def join(subpath = nil, prevpath = nil)
  return self if subpath.nil?

  subpath = subpath.to_s if Symbol === subpath
  prevpath = prevpath.to_s if Symbol === prevpath

  subpath = File.join(prevpath.to_s, subpath) if prevpath
  new = self.empty? ? subpath.dup : File.join(self, subpath)
  self.annotate(new)
  new
end

#json(*rest, &block) ⇒ Object



8
9
10
# File 'lib/scout/persist/path.rb', line 8

def json(*rest, &block)
  Open.json(self, *rest, &block)
end

#libdirObject



22
23
24
# File 'lib/scout/path.rb', line 22

def libdir
  @libdir || Path.caller_lib_dir
end

#listObject



72
73
74
75
# File 'lib/scout/resource/path.rb', line 72

def list
  found = produce_and_find('list')
  Open.list(found)
end

#located?Boolean

Returns:

  • (Boolean)


200
201
202
# File 'lib/scout/path/find.rb', line 200

def located?
  Path.located?(self)
end

#map_orderObject



136
137
138
139
140
141
142
143
144
# File 'lib/scout/path/find.rb', line 136

def map_order
  @map_order ||= 
    begin
      all_maps = path_maps.keys.collect{|m| m.to_s }.reverse
      basic_map_order = Path.map_order.collect{|m| m.to_s }

      (basic_map_order & all_maps) + (all_maps - basic_map_order)
    end.collect{|m| m.to_sym }
end

#marshal(*rest, &block) ⇒ Object



12
13
14
# File 'lib/scout/persist/path.rb', line 12

def marshal(*rest, &block)
  Open.marshal(self, *rest, &block)
end

#newer_files(*files) ⇒ Object



168
169
170
171
172
# File 'lib/scout/path/util.rb', line 168

def newer_files(*files)
  files.flatten.select do |file|
    Path.newer?(self, file)
  end
end

#no_method_missingObject



2
3
4
5
6
# File 'lib/scout/path/util.rb', line 2

def no_method_missing
  class << self
    undef_method :method_missing
  end
end

#open(*args, &block) ⇒ Object



58
59
60
61
# File 'lib/scout/resource/path.rb', line 58

def open(*args, &block)
  produce
  Open.open(self, *args, &block)
end

#originalObject



215
216
217
# File 'lib/scout/path/find.rb', line 215

def original
  @original
end

#outdated?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/scout/path/util.rb', line 174

def outdated?(...)
  newer_files(...).any?
end

#path_mapsObject



26
27
28
# File 'lib/scout/path.rb', line 26

def path_maps
  @path_maps ||= Path.path_maps.dup
end

#pkgdirObject



18
19
20
# File 'lib/scout/path.rb', line 18

def pkgdir
  @pkgdir ||= Path.default_pkgdir
end

#prepend_path(name, map) ⇒ Object



151
152
153
154
# File 'lib/scout/path/find.rb', line 151

def prepend_path(name, map)
  path_maps[name] = map
  map_order.unshift(name.to_sym)
end

#produce(force = false) ⇒ Object

Raises:

  • (@produced)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/scout/resource/path.rb', line 2

def produce(force = false)
  raise @produced if Exception === @produced
  return self if ! force && (Open.exist?(self.find) || @produced)
  begin
    if Resource === self.pkgdir
      self.pkgdir.produce self, force
    else
      false
    end
  rescue ResourceNotFound
    @produced = false
  rescue
    message = $!.message
    message = "No exception message" if message.nil? || message.empty?
    Log.warn "Error producing #{self}: #{message}"
    raise $!
  ensure
    @produced = true if @produced.nil?
  end
end

#produce_and_find(extension = nil, *args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scout/resource/path.rb', line 36

def produce_and_find(extension = nil, *args)
  found = if extension
            found = find_with_extension(extension, *args)
            found.exists? ? found : produce_with_extension(extension, *args)
          else
            found = find
            found.exists? ? found : produce(*args)
          end
  raise "Not found: #{self}" unless found

  found
end

#produce_with_extension(extension, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/scout/resource/path.rb', line 23

def produce_with_extension(extension, *args)
  begin
    self.produce(*args)
  rescue Exception
    exception = $!
    begin
      self.set_extension(extension).produce(*args)
    rescue Exception
      raise exception
    end
  end
end

#readObject



63
64
65
66
# File 'lib/scout/resource/path.rb', line 63

def read
  produce
  Open.read(self)
end

#realpathObject



57
58
59
# File 'lib/scout/path/util.rb', line 57

def realpath
  File.realpath(self.find)
end

#relative_to(dir) ⇒ Object



61
62
63
# File 'lib/scout/path/util.rb', line 61

def relative_to(dir)
  Misc.path_relative_to(File.expand_path(dir), self.find)
end

#relocateObject



49
50
51
52
# File 'lib/scout/resource/path.rb', line 49

def relocate
  return self if Open.exists?(self)
  Resource.relocate(self)
end

#remove_extension(extension = nil) ⇒ Object



148
149
150
151
152
153
154
# File 'lib/scout/path/util.rb', line 148

def remove_extension(extension = nil)
  if extension.nil?
    unset_extension
  else
    self.annotate(self.sub(/\.#{extension}$/,''))
  end
end

#replace_extension(new_extension = nil, multiple = false) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
# File 'lib/scout/path/util.rb', line 156

def replace_extension(new_extension = nil, multiple = false)
  if String === multiple
    new_path = self.sub(/(\.[^\.\/]{1,5})(.#{multiple})?$/,'')
  elsif multiple
    new_path = self.sub(/(\.[^\.\/]{1,5})+$/,'')
  else
    new_path = self.sub(/\.[^\.\/]{1,5}$/,'')
  end
  new_path = new_path + "." + new_extension.to_s
  self.annotate(new_path)
end

#set_extension(extension) ⇒ Object



135
136
137
# File 'lib/scout/path/util.rb', line 135

def set_extension(extension)
  self.annotate(self + ".#{extension}")
end

#sub(*args) ⇒ Object



65
66
67
# File 'lib/scout/path/util.rb', line 65

def sub(*args)
  self.annotate super(*args)
end

#unset_extensionObject



139
140
141
142
143
144
145
146
# File 'lib/scout/path/util.rb', line 139

def unset_extension
  parts = self.split("/")
  basename = parts.pop
  return self unless basename.include?(".")
  basename = basename.split(".")[0..-2] * "."
  parts.push basename
  self.annotate(parts * "/")
end

#whereObject



211
212
213
# File 'lib/scout/path/find.rb', line 211

def where
  @where
end

#write(*args, &block) ⇒ Object



68
69
70
# File 'lib/scout/resource/path.rb', line 68

def write(*args, &block)
  Open.write(self.find, *args, &block)
end

#yaml(*rest, &block) ⇒ Object



4
5
6
# File 'lib/scout/persist/path.rb', line 4

def yaml(*rest, &block)
  Open.yaml(self, *rest, &block)
end