Class: Pullable::Processor
- Inherits:
-
Object
- Object
- Pullable::Processor
- Defined in:
- lib/pullable/processor.rb
Constant Summary collapse
- CONFIG_FILE =
".pullable.yml"
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
Returns the value of attribute branch.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(method, directory, options = {}) ⇒ Processor
constructor
A new instance of Processor.
- #mirror!(options = {}) ⇒ Object
- #run(command) ⇒ Object
- #update!(options = {}) ⇒ Object
Constructor Details
#initialize(method, directory, options = {}) ⇒ Processor
Returns a new instance of Processor.
9 10 11 12 13 14 15 |
# File 'lib/pullable/processor.rb', line 9 def initialize(method, directory, = {}) @method = method @directory = directory @options = @branch = `git rev-parse --abbrev-ref HEAD` || 'master' end |
Instance Attribute Details
#branch ⇒ Object (readonly)
Returns the value of attribute branch.
7 8 9 |
# File 'lib/pullable/processor.rb', line 7 def branch @branch end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
7 8 9 |
# File 'lib/pullable/processor.rb', line 7 def directory @directory end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
7 8 9 |
# File 'lib/pullable/processor.rb', line 7 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/pullable/processor.rb', line 7 def @options end |
Class Method Details
.update!(method, directory) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pullable/processor.rb', line 17 def self.update!(method, directory) = File.exists?(CONFIG_FILE) ? YAML.load(File.read(CONFIG_FILE)) : {} processor = new(method, directory, ) if processor.['mirror'] processor.mirror!() else processor.update!() end end |
Instance Method Details
#command ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pullable/processor.rb', line 42 def command case method when 'merge' "git merge --ff-only origin/#{branch}" when 'pull' "git pull origin #{branch}" else raise NotImplementedError end end |
#mirror!(options = {}) ⇒ Object
28 29 30 31 |
# File 'lib/pullable/processor.rb', line 28 def mirror!( = {}) remote = ['mirror']['remote'] rescue 'upstream' run "git pull #{remote} #{branch} && git push origin #{branch}" end |
#run(command) ⇒ Object
37 38 39 40 |
# File 'lib/pullable/processor.rb', line 37 def run(command) puts "Updating:\t#{directory}" system "#{command} > /dev/null" end |
#update!(options = {}) ⇒ Object
33 34 35 |
# File 'lib/pullable/processor.rb', line 33 def update!( = {}) run "git fetch -p && #{command}" end |