drain 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ #for the filename ploum.rb, load all ploum/*.rb files
2
+ dir=File.expand_path(File.basename(__FILE__).chomp('.rb'), File.dirname(__FILE__))
3
+ Dir.glob(File.expand_path('*.rb',dir)) do |file|
4
+ require file
5
+ end
@@ -0,0 +1,116 @@
1
+ require 'shellwords'
2
+ require 'dr/base/bool'
3
+
4
+ module DR
5
+ #git functions helper
6
+ module Git
7
+ extend(self)
8
+ def git?(quiet:false)
9
+ launch="git rev-parse"
10
+ launch=launch + " 2>/dev/null" if quiet
11
+ system launch
12
+ return Bool.to_bool($?)
13
+ end
14
+ def gitdir?
15
+ return Bool.to_bool(%x/git rev-parse --is-inside-git-dir/)
16
+ end
17
+ def worktree?
18
+ return Bool.to_bool(%x/git rev-parse --is-inside-work-tree/)
19
+ end
20
+ def bare?
21
+ return Bool.to_bool(%x/git rev-parse --is-bare-repository/)
22
+ end
23
+
24
+ def toplevel
25
+ return %x/git rev-parse --show-toplevel/.chomp
26
+ end
27
+ def prefix
28
+ return %x/git rev-parse --show-prefix/.chomp
29
+ end
30
+ def gitdir
31
+ return %x/git rev-parse --git-dir/.chomp
32
+ end
33
+
34
+ def cd_to_toplevel(&block)
35
+ dir=%x/git rev-parse --show-cdup/.chomp
36
+ Dir.chdir(dir,&block) unless dir.empty?
37
+ end
38
+
39
+ def get_current_branch(always=true)
40
+ branchname= %x/git symbolic-ref -q --short HEAD/.chomp!
41
+ branchname ||= %x/git rev-parse --verify HEAD/.chomp! if always
42
+ return branchname
43
+ end
44
+
45
+ def name_branch(branch="HEAD", method: "name", always: true)
46
+ case method
47
+ when "sha1"
48
+ describe=%x"git rev-parse --short #{branch.shellescape}".chomp!
49
+ when "describe"
50
+ describe=%x"git describe #{branch.shellescape}".chomp!
51
+ when "contains"
52
+ describe=%x"git describe --contains #{branch.shellescape}".chomp!
53
+ when "match"
54
+ describe=%x"git describe --tags --exact-match #{branch.shellescape}".chomp!
55
+ when "topic"
56
+ describe=%x"git describe --all #{branch.shellescape}".chomp!
57
+ when "branch"
58
+ describe=%x"git describe --contains --all #{branch.shellescape}".chomp!
59
+ when "topic-fb" #try --all, then --contains all
60
+ describe=%x"git describe --all #{branch.shellescape}".chomp!
61
+ describe=%x"git describe --contains --all #{branch.shellescape}".chomp! if describe.nil? or describe.empty?
62
+ when "branch" #try --contains all, then --all
63
+ describe=%x"git describe --contains --all #{branch.shellescape}".chomp!
64
+ describe=%x"git describe --all #{branch.shellescape}".chomp! if describe.nil? or describe.empty?
65
+ when "magic"
66
+ describe1=%x"git describe --contains --all #{branch.shellescape}".chomp!
67
+ describe2=%x"git describe --all #{branch.shellescape}".chomp!
68
+ describe= describe1.length < describe2.length ? describe1 : describe2
69
+ describe=describe1 if describe2.empty?
70
+ describe=describe2 if describe1.empty?
71
+ when "name"
72
+ describe=%x"git rev-parse --abbrev-ref --symbolic-full-name #{branch.shellescape}".chomp!
73
+ else
74
+ describe=%x/#{method}/.chomp! unless method.nil? or method.empty?
75
+ end
76
+ if (describe.nil? or describe.empty?) and always
77
+ describe=%x/git rev-parse --short #{branch.shellescape}/.chomp!
78
+ end
79
+ return describe
80
+ end
81
+
82
+ def branch_rebase?(branch=get_current_branch)
83
+ rb=%x/git config --bool branch.shellescape.#{branch.shellescape}.rebase/.chomp!
84
+ rb||=%x/git config --bool pull.rebase/.chomp!
85
+ end
86
+ def branch_remote(branch=get_current_branch)
87
+ rb=%x/git config --get branch.shellescape.#{branch.shellescape}.remote/.chomp!
88
+ rb||="origin"
89
+ end
90
+ def branch_upstream(branch=get_current_branch)
91
+ %x/git rev-parse --abbrev-ref --symbolic-full-name #{branch.shellescape}@{u}/.chomp!
92
+ end
93
+
94
+ #return all branches that have an upstream
95
+ #if branches=:all look throug all branches
96
+ def all_upstream_branches(branches)
97
+ upstreams=%x!git for-each-ref --format='%(upstream:short)' refs/heads/branch/!
98
+ end
99
+
100
+ def get_topic_branches(*branches, complete: :local)
101
+ if branches.length >= 2
102
+ return [branches[0], branches[1]]
103
+ elsif branches.length == 1
104
+ if complete == :local
105
+ return [get_current_branch, branches[0]]
106
+ elsif complete == :remote
107
+ return [branches[0], branch_upstream(branches[0])]
108
+ else
109
+ fail "complete keyword should be :local or :remote"
110
+ end
111
+ else
112
+ return [get_current_branch, branch_upstream]
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,49 @@
1
+ #From:
2
+ #http://ruby-gnome2.sourceforge.jp/hiki.cgi?tips_threads
3
+ #helps using Gtk with threads
4
+
5
+ require 'monitor.rb'
6
+
7
+ module Gtk
8
+ GTK_PENDING_BLOCKS = []
9
+ GTK_PENDING_BLOCKS_LOCK = Monitor.new
10
+
11
+ def Gtk.queue &block
12
+ if Thread.current == Thread.main
13
+ block.call
14
+ else
15
+ GTK_PENDING_BLOCKS_LOCK.synchronize do
16
+ GTK_PENDING_BLOCKS << block
17
+ end
18
+ end
19
+ end
20
+
21
+ def Gtk.main_with_queue timeout
22
+ Gtk.timeout_add timeout do
23
+ GTK_PENDING_BLOCKS_LOCK.synchronize do
24
+ for block in GTK_PENDING_BLOCKS
25
+ block.call
26
+ end
27
+ GTK_PENDING_BLOCKS.clear
28
+ end
29
+ true
30
+ end
31
+ Gtk.main
32
+ end
33
+ end
34
+
35
+ ##First, force all your your Ruby threads to start from within the main loop using the standard Gtk.init method. You can call Gtk.init as many times as necessary. For example:
36
+
37
+ #Gtk.init_add do
38
+ # DBus.start_listener
39
+ #end
40
+
41
+ ## Start your Gtk application by calling Gtk.main_with_queue rather than Gtk.main. The "timeout" argument is in milliseconds, and it is the maximum time that can pass until queued blocks get called: 100 should be fine.
42
+ ##
43
+ ## Whenever you need to queue a call, use Gtk.queue. For example:
44
+
45
+ # def my_event_callback
46
+ # Gtk.queue do
47
+ # @image.pixbuf = Gdk::Pixbuf.new @image_path, width, height
48
+ # end
49
+ # end
@@ -0,0 +1,4 @@
1
+ module Drain
2
+ # drain version
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,2 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
@@ -0,0 +1,12 @@
1
+ require 'helper'
2
+ require 'drain'
3
+
4
+ class TestDrain < Minitest::Test
5
+
6
+ def test_version
7
+ version = Drain.const_get('VERSION')
8
+
9
+ assert(!version.empty?, 'should have a VERSION constant')
10
+ end
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drain
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Damien Robert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubygems-tasks
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ description: 'Drain is a small set of libraries that I use in my other gems.
56
+
57
+ '
58
+ email: Damien.Olivier.Robert+gems@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files:
62
+ - ChangeLog.md
63
+ - LICENSE.txt
64
+ - README.md
65
+ files:
66
+ - ".document"
67
+ - ".gitignore"
68
+ - ".yardopts"
69
+ - ChangeLog.md
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - drain.gemspec
74
+ - gemspec.yml
75
+ - lib/drain.rb
76
+ - lib/drain/base.rb
77
+ - lib/drain/base/bool.rb
78
+ - lib/drain/base/encoding.rb
79
+ - lib/drain/base/eruby.rb
80
+ - lib/drain/base/functional.rb
81
+ - lib/drain/base/graph.rb
82
+ - lib/drain/parse.rb
83
+ - lib/drain/parse/simple_parser.rb
84
+ - lib/drain/parse/time_parse.rb
85
+ - lib/drain/ruby_ext.rb
86
+ - lib/drain/ruby_ext/core_ext.rb
87
+ - lib/drain/ruby_ext/meta_ext.rb
88
+ - lib/drain/tools.rb
89
+ - lib/drain/tools/git.rb
90
+ - lib/drain/tools/gtk.rb
91
+ - lib/drain/version.rb
92
+ - test/helper.rb
93
+ - test/test_drain.rb
94
+ homepage: https://github.com/DamienRobert/drain#readme
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Use a drain for a dryer ruby!
118
+ test_files: []