drain 0.1.0 → 0.2.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.
- checksums.yaml +5 -5
 - data/.gitignore +6 -2
 - data/.travis.yml +10 -0
 - data/.yardopts +6 -1
 - data/Gemfile +7 -0
 - data/LICENSE.txt +1 -1
 - data/README.md +11 -5
 - data/Rakefile +7 -12
 - data/drain.gemspec +15 -5
 - data/gemspec.yml +4 -3
 - data/lib/dr.rb +1 -0
 - data/lib/{drain → dr}/base.rb +0 -0
 - data/lib/{drain → dr}/base/bool.rb +0 -0
 - data/lib/dr/base/converter.rb +33 -0
 - data/lib/{drain → dr}/base/encoding.rb +0 -0
 - data/lib/dr/base/eruby.rb +284 -0
 - data/lib/{drain → dr}/base/functional.rb +2 -2
 - data/lib/dr/base/graph.rb +378 -0
 - data/lib/dr/base/utils.rb +28 -0
 - data/lib/dr/parse.rb +1 -0
 - data/lib/dr/parse/simple_parser.rb +70 -0
 - data/lib/{drain → dr}/parse/time_parse.rb +0 -0
 - data/lib/dr/ruby_ext.rb +1 -0
 - data/lib/dr/ruby_ext/core_ext.rb +7 -0
 - data/lib/{drain/ruby_ext/core_ext.rb → dr/ruby_ext/core_modules.rb} +67 -27
 - data/lib/{drain → dr}/ruby_ext/meta_ext.rb +57 -30
 - data/lib/dr/tools.rb +1 -0
 - data/lib/{drain → dr}/tools/gtk.rb +0 -0
 - data/lib/dr/version.rb +4 -0
 - data/lib/drain.rb +2 -1
 - data/test/helper.rb +12 -1
 - data/test/test_converter.rb +42 -0
 - data/test/test_core_ext.rb +116 -0
 - data/test/test_graph.rb +126 -0
 - data/test/test_meta.rb +65 -0
 - data/test/test_simple_parser.rb +41 -0
 - metadata +45 -21
 - data/.document +0 -3
 - data/lib/drain/base/eruby.rb +0 -28
 - data/lib/drain/base/graph.rb +0 -213
 - data/lib/drain/parse.rb +0 -5
 - data/lib/drain/parse/simple_parser.rb +0 -61
 - data/lib/drain/ruby_ext.rb +0 -5
 - data/lib/drain/tools.rb +0 -5
 - data/lib/drain/tools/git.rb +0 -116
 - data/lib/drain/version.rb +0 -4
 
    
        data/lib/drain/parse.rb
    DELETED
    
    
| 
         @@ -1,61 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module DR
         
     | 
| 
       2 
     | 
    
         
            -
            	#utilities to parse some strings into name values
         
     | 
| 
       3 
     | 
    
         
            -
            	module SimpleParser
         
     | 
| 
       4 
     | 
    
         
            -
            		extend self
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            		#takes a string 'name:value' and return name and value
         
     | 
| 
       7 
     | 
    
         
            -
            		#can specify a default value; if the default is true we match
         
     | 
| 
       8 
     | 
    
         
            -
            		#no-name as name:false
         
     | 
| 
       9 
     | 
    
         
            -
            		def parse_namevalue(nameval, sep: ':', default: nil)
         
     | 
| 
       10 
     | 
    
         
            -
            			name,*val=nameval.split(sep)
         
     | 
| 
       11 
     | 
    
         
            -
            			if val.empty?
         
     | 
| 
       12 
     | 
    
         
            -
            				if default == true
         
     | 
| 
       13 
     | 
    
         
            -
            					#special case where if name begins by no- we return false
         
     | 
| 
       14 
     | 
    
         
            -
            					if name =~ /^no-(.*)$/
         
     | 
| 
       15 
     | 
    
         
            -
            						return $1, false
         
     | 
| 
       16 
     | 
    
         
            -
            					else
         
     | 
| 
       17 
     | 
    
         
            -
            						return name, true
         
     | 
| 
       18 
     | 
    
         
            -
            					end
         
     | 
| 
       19 
     | 
    
         
            -
            				else
         
     | 
| 
       20 
     | 
    
         
            -
            					return name, default
         
     | 
| 
       21 
     | 
    
         
            -
            				end
         
     | 
| 
       22 
     | 
    
         
            -
            			else
         
     | 
| 
       23 
     | 
    
         
            -
            				value=val.join(sep)
         
     | 
| 
       24 
     | 
    
         
            -
            				return name,value
         
     | 
| 
       25 
     | 
    
         
            -
            			end
         
     | 
| 
       26 
     | 
    
         
            -
            		end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
            		#takes a string as "name:value!option1=ploum!option2=plam,name2:value2!!globalopt=plim,globalopt2=plam"
         
     | 
| 
       29 
     | 
    
         
            -
            		#and return the hash
         
     | 
| 
       30 
     | 
    
         
            -
            		#{values: {name: value, name2: value2},
         
     | 
| 
       31 
     | 
    
         
            -
            		# localopt: {name: {option1:ploum,option2:plam}},
         
     | 
| 
       32 
     | 
    
         
            -
            		# globalopt: {globalopt: plim, globalopt2: plam},
         
     | 
| 
       33 
     | 
    
         
            -
            		# opt: {name: {option1:ploum,option2:plam,globalopt: plim, globalopt2: plam}, name2:{{globalopt: plim, globalopt2: plam}}}
         
     | 
| 
       34 
     | 
    
         
            -
            		def parse_string(s)
         
     | 
| 
       35 
     | 
    
         
            -
            			r={values: {}, local_opts: {}, global_opts: {}, opts: {}}
         
     | 
| 
       36 
     | 
    
         
            -
            			args,*globopts=s.split('!!')
         
     | 
| 
       37 
     | 
    
         
            -
            			globopts.map {|g| g.split(',')}.flatten.each do |g|
         
     | 
| 
       38 
     | 
    
         
            -
            				name,value=parse_namevalue(g, sep: '=', default: true)
         
     | 
| 
       39 
     | 
    
         
            -
            				r[:global_opts][name]=value
         
     | 
| 
       40 
     | 
    
         
            -
            			end
         
     | 
| 
       41 
     | 
    
         
            -
            			args.split(',').each do |arg|
         
     | 
| 
       42 
     | 
    
         
            -
            				arg,*localopts=arg.split('!')
         
     | 
| 
       43 
     | 
    
         
            -
            				name,value=parse_namevalue(arg)
         
     | 
| 
       44 
     | 
    
         
            -
            				r[:values][name]=value
         
     | 
| 
       45 
     | 
    
         
            -
            				r[:local_opts][name]={}
         
     | 
| 
       46 
     | 
    
         
            -
            				localopts.each do |o|
         
     | 
| 
       47 
     | 
    
         
            -
            					oname,ovalue=parse_namevalue(o, sep: '=', default: true)
         
     | 
| 
       48 
     | 
    
         
            -
            					r[:local_opts][name][oname]=ovalue
         
     | 
| 
       49 
     | 
    
         
            -
            				end
         
     | 
| 
       50 
     | 
    
         
            -
            				r[:local_opts].each do |name,hash|
         
     | 
| 
       51 
     | 
    
         
            -
            					r[:opts][name]=r[:local_opts][name].dup
         
     | 
| 
       52 
     | 
    
         
            -
            					r[:global_opts].each do |k,v|
         
     | 
| 
       53 
     | 
    
         
            -
            						r[:opts][name][k]||=v
         
     | 
| 
       54 
     | 
    
         
            -
            					end
         
     | 
| 
       55 
     | 
    
         
            -
            				end
         
     | 
| 
       56 
     | 
    
         
            -
            			end
         
     | 
| 
       57 
     | 
    
         
            -
            			return r
         
     | 
| 
       58 
     | 
    
         
            -
            		end
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
            	end
         
     | 
| 
       61 
     | 
    
         
            -
            end
         
     | 
    
        data/lib/drain/ruby_ext.rb
    DELETED
    
    
    
        data/lib/drain/tools.rb
    DELETED
    
    
    
        data/lib/drain/tools/git.rb
    DELETED
    
    | 
         @@ -1,116 +0,0 @@ 
     | 
|
| 
       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
         
     | 
    
        data/lib/drain/version.rb
    DELETED