Class: Pullable::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/pullable/directory.rb

Constant Summary collapse

VALID_METHODS =
['pull', 'merge']
SKIPPED_DIRECTORIES =
['.DS_Store']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, method) ⇒ Directory



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pullable/directory.rb', line 11

def initialize(path, method)
  unless File.directory?(path)
    raise ArgumentError.new('Please pass a directory that exists!')
  end

  unless VALID_METHODS.include?(method)
    raise ArgumentError.new("#{method} cannot be used to update the repo!")
  end

  @path   = path
  @method = method
end

Instance Attribute Details

#methodObject (readonly)

Returns the value of attribute method.



9
10
11
# File 'lib/pullable/directory.rb', line 9

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/pullable/directory.rb', line 9

def path
  @path
end

Class Method Details

.process!(path, method = 'merge') ⇒ Object



40
41
42
# File 'lib/pullable/directory.rb', line 40

def self.process!(path, method = 'merge')
  new(path, method).process!
end

Instance Method Details

#process!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pullable/directory.rb', line 24

def process!
  Dir.foreach(path) do |directory|
    if File.directory?(directory)
      unless SKIPPED_DIRECTORIES.include?(directory)
        FileUtils.cd(directory)

        if Dir.exists?('.git')
          Pullable::Processor.update!(method, directory)
        end

        FileUtils.cd(path)
      end
    end
  end
end