Class: Pullable::Processor

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

Constant Summary collapse

CONFIG_FILE =
".pullable.yml"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, directory, options = {}) ⇒ Processor

Returns a new instance of Processor.



9
10
11
12
13
# File 'lib/pullable/processor.rb', line 9

def initialize(method, directory, options = {})
  @method    = method
  @directory = directory
  @options   = options
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



7
8
9
# File 'lib/pullable/processor.rb', line 7

def directory
  @directory
end

#methodObject (readonly)

Returns the value of attribute method.



7
8
9
# File 'lib/pullable/processor.rb', line 7

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/pullable/processor.rb', line 7

def options
  @options
end

Class Method Details

.update!(method, directory) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/pullable/processor.rb', line 15

def self.update!(method, directory)
  options   = File.exists?(CONFIG_FILE) ? YAML.load(File.read(CONFIG_FILE)) : {}
  processor = new(method, directory, options)

  if processor.options['mirror']
    processor.mirror!(options)
  else
    processor.update!(options)
  end
end

Instance Method Details

#commandObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/pullable/processor.rb', line 40

def command
  case method
  when 'merge'
    'git merge --ff-only origin/master'
  when 'pull'
    'git pull origin master'
  else
    raise NotImplementedError
  end
end

#mirror!(options = {}) ⇒ Object



26
27
28
29
# File 'lib/pullable/processor.rb', line 26

def mirror!(options = {})
  remote = options['mirror']['remote'] rescue 'upstream'
  run "git pull #{remote} master && git push origin master"
end

#run(command) ⇒ Object



35
36
37
38
# File 'lib/pullable/processor.rb', line 35

def run(command)
  puts "Updating:\t#{directory}"
  system "#{command} > /dev/null"
end

#update!(options = {}) ⇒ Object



31
32
33
# File 'lib/pullable/processor.rb', line 31

def update!(options = {})
  run "git fetch -p && #{command}"
end