Class: Clerq::Repositories::FileRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/clerq/repositories/file_repository.rb

Overview

The class provides File and Dir functions that executed relativly path

provided in constructor.

Usage:

FileRepository.new(path: Dir.pwd, pattern: '*.*')
FileRepository.new(path: Dir.pwd, pattern: ['*.rb', '*.md'])

Direct Known Subclasses

NodeRepository, TextRepository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: Dir.pwd, pattern: '*.*') ⇒ FileRepository

Returns a new instance of FileRepository.

Parameters:

  • path (String) (defaults to: Dir.pwd)
  • pattern (String, Array<String>) (defaults to: '*.*')


18
19
20
21
22
23
24
25
26
# File 'lib/clerq/repositories/file_repository.rb', line 18

def initialize(path: Dir.pwd, pattern: '*.*')
  # TODO check that path exists and save it in full form
  unless Dir.exist?(path)
    msg = "'#{path}' directory does not exist!"
    raise ArgumentError, msg
  end
  @path = path
  @patt = pattern
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/clerq/repositories/file_repository.rb', line 13

def path
  @path
end

#pattObject (readonly)

Returns the value of attribute patt.



14
15
16
# File 'lib/clerq/repositories/file_repository.rb', line 14

def patt
  @patt
end

Instance Method Details

#insideObject



28
29
30
# File 'lib/clerq/repositories/file_repository.rb', line 28

def inside
  Dir.chdir(@path) { yield }
end