hirb 0.6.1 → 0.6.2
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.
- data/CHANGELOG.rdoc +3 -0
- data/README.rdoc +1 -1
- data/lib/hirb/menu.rb +11 -6
- data/lib/hirb/util.rb +1 -1
- data/lib/hirb/version.rb +1 -1
- data/test/menu_test.rb +35 -2
- metadata +10 -10
    
        data/CHANGELOG.rdoc
    CHANGED
    
    
    
        data/README.rdoc
    CHANGED
    
    | @@ -180,7 +180,7 @@ Table code from http://gist.github.com/72234 and {my console app's needs}[http:/ | |
| 180 180 | 
             
            == Credits
         | 
| 181 181 | 
             
            * Chrononaut for vertical table helper.
         | 
| 182 182 | 
             
            * janlelis for unicode table helper.
         | 
| 183 | 
            -
            * crafterm, spastorino, xaviershay, bogdan, asanghi, vwall and joshua for patches.
         | 
| 183 | 
            +
            * hsume2, crafterm, spastorino, xaviershay, bogdan, asanghi, vwall and joshua for patches.
         | 
| 184 184 |  | 
| 185 185 | 
             
            == Bugs/Issues
         | 
| 186 186 | 
             
            Please report them {on github}[http://github.com/cldwalker/hirb/issues].
         | 
    
        data/lib/hirb/menu.rb
    CHANGED
    
    | @@ -9,7 +9,7 @@ module Hirb | |
| 9 9 | 
             
                class Error < StandardError; end
         | 
| 10 10 |  | 
| 11 11 | 
             
                # Detects valid choices and optional field/column
         | 
| 12 | 
            -
                CHOSEN_REGEXP = /^(\d([^:]+) | 
| 12 | 
            +
                CHOSEN_REGEXP = /^(\d([^:]+)?|\*)(?::)?(\S+)?/
         | 
| 13 13 | 
             
                CHOSEN_ARG = '%s'
         | 
| 14 14 | 
             
                DIRECTIONS = "Specify individual choices (4,7), range of choices (1-3) or all choices (*)."
         | 
| 15 15 |  | 
| @@ -128,14 +128,16 @@ module Hirb | |
| 128 128 | 
             
                end
         | 
| 129 129 |  | 
| 130 130 | 
             
                def map_tokens(tokens)
         | 
| 131 | 
            -
                  if return_cell_values?
         | 
| 132 | 
            -
                    @output[0].is_a?(Hash) ? | 
| 131 | 
            +
                  values = if return_cell_values?
         | 
| 132 | 
            +
                    @output[0].is_a?(Hash) ?
         | 
| 133 | 
            +
                      tokens.map {|arr,f| arr.map {|e| e[f]} } :
         | 
| 133 134 | 
             
                      tokens.map {|arr,f|
         | 
| 134 135 | 
             
                        arr.map {|e| e.is_a?(Array) && f.is_a?(Integer) ? e[f] : e.send(f) }
         | 
| 135 | 
            -
                      } | 
| 136 | 
            +
                      }
         | 
| 136 137 | 
             
                  else
         | 
| 137 | 
            -
                    tokens.map {| | 
| 138 | 
            +
                    tokens.map {|arr, f| arr[0] }
         | 
| 138 139 | 
             
                  end
         | 
| 140 | 
            +
                  values.flatten
         | 
| 139 141 | 
             
                end
         | 
| 140 142 |  | 
| 141 143 | 
             
                def return_cell_values?
         | 
| @@ -154,7 +156,10 @@ module Hirb | |
| 154 156 | 
             
                    @new_args << CHOSEN_ARG
         | 
| 155 157 | 
             
                    field = $3 ? unalias_field($3) : default_field ||
         | 
| 156 158 | 
             
                      raise(Error, "No default field/column found. Fields must be explicitly picked.")
         | 
| 157 | 
            -
             | 
| 159 | 
            +
             | 
| 160 | 
            +
                    token = Util.choose_from_array(@output, word)
         | 
| 161 | 
            +
                    token = [token] if word[/\*|-|\.\.|,/] && !return_cell_values?
         | 
| 162 | 
            +
                    [token, field]
         | 
| 158 163 | 
             
                  else
         | 
| 159 164 | 
             
                    @new_args << word
         | 
| 160 165 | 
             
                    nil
         | 
    
        data/lib/hirb/util.rb
    CHANGED
    
    | @@ -35,7 +35,7 @@ module Hirb | |
| 35 35 | 
             
                #    ''  -> []
         | 
| 36 36 | 
             
                def choose_from_array(array, input, options={})
         | 
| 37 37 | 
             
                  options = {:splitter=>","}.merge(options)
         | 
| 38 | 
            -
                  return array if input | 
| 38 | 
            +
                  return array if input[/^\s*\*/]
         | 
| 39 39 | 
             
                  result = []
         | 
| 40 40 | 
             
                  input.split(options[:splitter]).each do |e|
         | 
| 41 41 | 
             
                    if e =~ /-|\.\./
         | 
    
        data/lib/hirb/version.rb
    CHANGED
    
    
    
        data/test/menu_test.rb
    CHANGED
    
    | @@ -36,7 +36,7 @@ describe "Menu" do | |
| 36 36 | 
             
                it "with block renders" do
         | 
| 37 37 | 
             
                  menu_input "1,2"
         | 
| 38 38 | 
             
                  expected_result = [1,2]
         | 
| 39 | 
            -
                  capture_stdout { | 
| 39 | 
            +
                  capture_stdout {
         | 
| 40 40 | 
             
                    menu([1,2,3]) {|e| e.should == expected_result }.should == expected_result
         | 
| 41 41 | 
             
                  }
         | 
| 42 42 | 
             
                end
         | 
| @@ -177,6 +177,17 @@ describe "Menu" do | |
| 177 177 | 
             
                  two_d_menu(:action=>true, :two_d=>nil, :invoke=>[[{:a=>1, :bro=>2}]])
         | 
| 178 178 | 
             
                end
         | 
| 179 179 |  | 
| 180 | 
            +
                it "with 1d invokes on range of choices" do
         | 
| 181 | 
            +
                  menu_input "p 1,2 1-2 1..2"
         | 
| 182 | 
            +
                  choices =  [{:a => 1, :bro => 2}, {:a => 3, :bro => 4}]
         | 
| 183 | 
            +
                  two_d_menu(:action=>true, :two_d=>nil, :invoke=>[Array.new(3, choices).flatten])
         | 
| 184 | 
            +
                end
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                it "with 1d and all choices" do
         | 
| 187 | 
            +
                  menu_input "p *"
         | 
| 188 | 
            +
                  two_d_menu(:action=>true, :two_d => nil, :invoke=>[[{:a => 1, :bro => 2}, {:a => 3, :bro => 4}]])
         | 
| 189 | 
            +
                end
         | 
| 190 | 
            +
             | 
| 180 191 | 
             
                it "with non-choice arguments invokes" do
         | 
| 181 192 | 
             
                  menu_input "p arg1 1"
         | 
| 182 193 | 
             
                  two_d_menu :action=>true, :invoke=>['arg1', [1]]
         | 
| @@ -192,6 +203,22 @@ describe "Menu" do | |
| 192 203 | 
             
                  capture_stderr { two_d_menu(:action=>true) }.should =~ /No rows chosen/
         | 
| 193 204 | 
             
                end
         | 
| 194 205 |  | 
| 206 | 
            +
                it "with range of choices" do
         | 
| 207 | 
            +
                  menu_input "p 1,2:a 1-2:a 1..2:a"
         | 
| 208 | 
            +
                  choices =  [1,3]
         | 
| 209 | 
            +
                  two_d_menu(:action=>true, :invoke=>[Array.new(3, choices).flatten])
         | 
| 210 | 
            +
                end
         | 
| 211 | 
            +
             | 
| 212 | 
            +
                it "with multiple all choices" do
         | 
| 213 | 
            +
                  menu_input "p * * 2:bro"
         | 
| 214 | 
            +
                  two_d_menu(:action=>true, :invoke=>[[1,3,1,3,4]])
         | 
| 215 | 
            +
                end
         | 
| 216 | 
            +
             | 
| 217 | 
            +
                it "with all choices with field" do
         | 
| 218 | 
            +
                  menu_input "p *:bro"
         | 
| 219 | 
            +
                  two_d_menu(:action=>true, :invoke=>[[2, 4]])
         | 
| 220 | 
            +
                end
         | 
| 221 | 
            +
             | 
| 195 222 | 
             
                it "with no command given prints error" do
         | 
| 196 223 | 
             
                  menu_input "1"
         | 
| 197 224 | 
             
                  capture_stderr { two_d_menu(:action=>true) }.should =~ /No command given/
         | 
| @@ -203,6 +230,12 @@ describe "Menu" do | |
| 203 230 | 
             
                    :invokes=>[[['some']]]
         | 
| 204 231 | 
             
                end
         | 
| 205 232 |  | 
| 233 | 
            +
                it "with array menu items and all choices" do
         | 
| 234 | 
            +
                  menu_input "p 1 *"
         | 
| 235 | 
            +
                  two_d_menu :action=>true, :output=>[['some', 'choice'], ['and', 'another']],
         | 
| 236 | 
            +
                    :invokes=>[[['some', 'some', 'and']]]
         | 
| 237 | 
            +
                end
         | 
| 238 | 
            +
             | 
| 206 239 | 
             
                it "with multi_action option invokes" do
         | 
| 207 240 | 
             
                  menu_input "p 1 2:bro"
         | 
| 208 241 | 
             
                  two_d_menu(:action=>true, :multi_action=>true, :invokes=>[[1], [4]])
         | 
| @@ -236,4 +269,4 @@ describe "Menu" do | |
| 236 269 | 
             
                  }.should =~ /Default.*required/
         | 
| 237 270 | 
             
                end
         | 
| 238 271 | 
             
              end
         | 
| 239 | 
            -
            end
         | 
| 272 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: hirb
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.6. | 
| 4 | 
            +
              version: 0.6.2
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors:
         | 
| @@ -9,11 +9,11 @@ authors: | |
| 9 9 | 
             
            autorequire: 
         | 
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 | 
            -
            date: 2012-03- | 
| 12 | 
            +
            date: 2012-03-19 00:00:00.000000000Z
         | 
| 13 13 | 
             
            dependencies:
         | 
| 14 14 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 15 15 | 
             
              name: bacon
         | 
| 16 | 
            -
              requirement: & | 
| 16 | 
            +
              requirement: &70183088619280 !ruby/object:Gem::Requirement
         | 
| 17 17 | 
             
                none: false
         | 
| 18 18 | 
             
                requirements:
         | 
| 19 19 | 
             
                - - ! '>='
         | 
| @@ -21,10 +21,10 @@ dependencies: | |
| 21 21 | 
             
                    version: 1.1.0
         | 
| 22 22 | 
             
              type: :development
         | 
| 23 23 | 
             
              prerelease: false
         | 
| 24 | 
            -
              version_requirements: * | 
| 24 | 
            +
              version_requirements: *70183088619280
         | 
| 25 25 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 26 26 | 
             
              name: mocha
         | 
| 27 | 
            -
              requirement: & | 
| 27 | 
            +
              requirement: &70183088618780 !ruby/object:Gem::Requirement
         | 
| 28 28 | 
             
                none: false
         | 
| 29 29 | 
             
                requirements:
         | 
| 30 30 | 
             
                - - ! '>='
         | 
| @@ -32,10 +32,10 @@ dependencies: | |
| 32 32 | 
             
                    version: 0.9.8
         | 
| 33 33 | 
             
              type: :development
         | 
| 34 34 | 
             
              prerelease: false
         | 
| 35 | 
            -
              version_requirements: * | 
| 35 | 
            +
              version_requirements: *70183088618780
         | 
| 36 36 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 37 | 
             
              name: mocha-on-bacon
         | 
| 38 | 
            -
              requirement: & | 
| 38 | 
            +
              requirement: &70183088617940 !ruby/object:Gem::Requirement
         | 
| 39 39 | 
             
                none: false
         | 
| 40 40 | 
             
                requirements:
         | 
| 41 41 | 
             
                - - ! '>='
         | 
| @@ -43,10 +43,10 @@ dependencies: | |
| 43 43 | 
             
                    version: 0.1.1
         | 
| 44 44 | 
             
              type: :development
         | 
| 45 45 | 
             
              prerelease: false
         | 
| 46 | 
            -
              version_requirements: * | 
| 46 | 
            +
              version_requirements: *70183088617940
         | 
| 47 47 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 48 48 | 
             
              name: bacon-bits
         | 
| 49 | 
            -
              requirement: & | 
| 49 | 
            +
              requirement: &70183088617440 !ruby/object:Gem::Requirement
         | 
| 50 50 | 
             
                none: false
         | 
| 51 51 | 
             
                requirements:
         | 
| 52 52 | 
             
                - - ! '>='
         | 
| @@ -54,7 +54,7 @@ dependencies: | |
| 54 54 | 
             
                    version: '0'
         | 
| 55 55 | 
             
              type: :development
         | 
| 56 56 | 
             
              prerelease: false
         | 
| 57 | 
            -
              version_requirements: * | 
| 57 | 
            +
              version_requirements: *70183088617440
         | 
| 58 58 | 
             
            description: Hirb provides a mini view framework for console applications and uses
         | 
| 59 59 | 
             
              it to improve ripl(irb)'s default inspect output. Given an object or array of objects,
         | 
| 60 60 | 
             
              hirb renders a view based on the object's class and/or ancestry. Hirb offers reusable
         |