rchoice 0.2.0 → 0.3.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.
- data/.document +5 -5
 - data/.rspec +1 -1
 - data/Gemfile +25 -17
 - data/Gemfile.lock +62 -21
 - data/Guardfile +27 -0
 - data/LICENSE.txt +20 -20
 - data/README.rdoc +19 -19
 - data/Rakefile +42 -50
 - data/VERSION +1 -1
 - data/lib/rchoice.rb +10 -10
 - data/lib/rchoice/choice.rb +41 -38
 - data/lib/rchoice/choosers/command_line_chooser.rb +19 -19
 - data/lib/rchoice/choosers/redis_chooser.rb +33 -0
 - data/lib/rchoice/core_ext.rb +30 -30
 - data/lib/rchoice/option.rb +23 -23
 - data/rchoice.gemspec +89 -77
 - data/spec/choice_spec.rb +122 -107
 - data/spec/spec_helper.rb +24 -14
 - data/vol/choice.txt +1 -0
 - data/vol/set_choice.rb +5 -0
 - metadata +128 -29
 
    
        data/.document
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            lib/**/*.rb
         
     | 
| 
       2 
     | 
    
         
            -
            bin/*
         
     | 
| 
       3 
     | 
    
         
            -
            - 
         
     | 
| 
       4 
     | 
    
         
            -
            features/**/*.feature
         
     | 
| 
       5 
     | 
    
         
            -
            LICENSE.txt
         
     | 
| 
      
 1 
     | 
    
         
            +
            lib/**/*.rb
         
     | 
| 
      
 2 
     | 
    
         
            +
            bin/*
         
     | 
| 
      
 3 
     | 
    
         
            +
            - 
         
     | 
| 
      
 4 
     | 
    
         
            +
            features/**/*.feature
         
     | 
| 
      
 5 
     | 
    
         
            +
            LICENSE.txt
         
     | 
    
        data/.rspec
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            --color
         
     | 
| 
      
 1 
     | 
    
         
            +
            --color
         
     | 
    
        data/Gemfile
    CHANGED
    
    | 
         @@ -1,17 +1,25 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            source "http://rubygems.org"
         
     | 
| 
       2 
     | 
    
         
            -
            # Add dependencies required to use your gem here.
         
     | 
| 
       3 
     | 
    
         
            -
            # Example:
         
     | 
| 
       4 
     | 
    
         
            -
            #   gem "activesupport", ">= 2.3.5"
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
            # Add dependencies to develop your gem here.
         
     | 
| 
       7 
     | 
    
         
            -
            # Include everything needed to run rake, tests, features, etc.
         
     | 
| 
       8 
     | 
    
         
            -
            group :development do
         
     | 
| 
       9 
     | 
    
         
            -
              gem "rspec", "~> 2. 
     | 
| 
       10 
     | 
    
         
            -
              gem "bundler", " 
     | 
| 
       11 
     | 
    
         
            -
              gem "jeweler", " 
     | 
| 
       12 
     | 
    
         
            -
              gem "rcov", ">= 0"
         
     | 
| 
       13 
     | 
    
         
            -
              gem 'rr'
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
            gem ' 
     | 
| 
       17 
     | 
    
         
            -
            gem ' 
     | 
| 
      
 1 
     | 
    
         
            +
            source "http://rubygems.org"
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Add dependencies required to use your gem here.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # Example:
         
     | 
| 
      
 4 
     | 
    
         
            +
            #   gem "activesupport", ">= 2.3.5"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # Add dependencies to develop your gem here.
         
     | 
| 
      
 7 
     | 
    
         
            +
            # Include everything needed to run rake, tests, features, etc.
         
     | 
| 
      
 8 
     | 
    
         
            +
            group :development do
         
     | 
| 
      
 9 
     | 
    
         
            +
              gem "rspec", "~> 2.8.0"
         
     | 
| 
      
 10 
     | 
    
         
            +
              gem "bundler", ">= 1.2"
         
     | 
| 
      
 11 
     | 
    
         
            +
              gem "jeweler", ">= 1.5.2"
         
     | 
| 
      
 12 
     | 
    
         
            +
              #gem "rcov", ">= 0"
         
     | 
| 
      
 13 
     | 
    
         
            +
              gem 'rr'
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
              gem 'guard'
         
     | 
| 
      
 16 
     | 
    
         
            +
              gem 'guard-rspec'
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem 'guard-spork'
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              gem 'lre'
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            gem 'mharris_ext'
         
     | 
| 
      
 23 
     | 
    
         
            +
            gem 'andand'
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            gem 'redis'
         
     | 
    
        data/Gemfile.lock
    CHANGED
    
    | 
         @@ -1,38 +1,79 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            GEM
         
     | 
| 
       2 
2 
     | 
    
         
             
              remote: http://rubygems.org/
         
     | 
| 
       3 
3 
     | 
    
         
             
              specs:
         
     | 
| 
       4 
     | 
    
         
            -
                andand (1.3. 
     | 
| 
       5 
     | 
    
         
            -
                 
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
                 
     | 
| 
      
 4 
     | 
    
         
            +
                andand (1.3.3)
         
     | 
| 
      
 5 
     | 
    
         
            +
                childprocess (0.3.9)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  ffi (~> 1.0, >= 1.0.11)
         
     | 
| 
      
 7 
     | 
    
         
            +
                coderay (1.0.9)
         
     | 
| 
      
 8 
     | 
    
         
            +
                diff-lcs (1.1.3)
         
     | 
| 
      
 9 
     | 
    
         
            +
                facets (2.9.3)
         
     | 
| 
      
 10 
     | 
    
         
            +
                fattr (2.2.1)
         
     | 
| 
      
 11 
     | 
    
         
            +
                ffi (1.4.0)
         
     | 
| 
       8 
12 
     | 
    
         
             
                git (1.2.5)
         
     | 
| 
       9 
     | 
    
         
            -
                 
     | 
| 
       10 
     | 
    
         
            -
                   
     | 
| 
      
 13 
     | 
    
         
            +
                guard (1.6.2)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  listen (>= 0.6.0)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  lumberjack (>= 1.0.2)
         
     | 
| 
      
 16 
     | 
    
         
            +
                  pry (>= 0.9.10)
         
     | 
| 
      
 17 
     | 
    
         
            +
                  terminal-table (>= 1.4.3)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  thor (>= 0.14.6)
         
     | 
| 
      
 19 
     | 
    
         
            +
                guard-rspec (1.2.1)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  guard (>= 1.1)
         
     | 
| 
      
 21 
     | 
    
         
            +
                guard-spork (1.4.2)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  childprocess (>= 0.2.3)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  guard (>= 1.1)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  spork (>= 0.8.4)
         
     | 
| 
      
 25 
     | 
    
         
            +
                jeweler (1.8.4)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  bundler (~> 1.0)
         
     | 
| 
       11 
27 
     | 
    
         
             
                  git (>= 1.2.5)
         
     | 
| 
       12 
28 
     | 
    
         
             
                  rake
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 29 
     | 
    
         
            +
                  rdoc
         
     | 
| 
      
 30 
     | 
    
         
            +
                json (1.7.7)
         
     | 
| 
      
 31 
     | 
    
         
            +
                listen (0.7.3)
         
     | 
| 
      
 32 
     | 
    
         
            +
                lre (0.3.0)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  fattr
         
     | 
| 
      
 34 
     | 
    
         
            +
                  mharris_ext
         
     | 
| 
      
 35 
     | 
    
         
            +
                  watchr
         
     | 
| 
      
 36 
     | 
    
         
            +
                lumberjack (1.0.2)
         
     | 
| 
      
 37 
     | 
    
         
            +
                method_source (0.8.1)
         
     | 
| 
      
 38 
     | 
    
         
            +
                mharris_ext (1.6.0)
         
     | 
| 
       14 
39 
     | 
    
         
             
                  facets
         
     | 
| 
       15 
40 
     | 
    
         
             
                  fattr
         
     | 
| 
       16 
     | 
    
         
            -
                 
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
       23 
     | 
    
         
            -
                 
     | 
| 
       24 
     | 
    
         
            -
                 
     | 
| 
      
 41 
     | 
    
         
            +
                pry (0.9.12)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  coderay (~> 1.0.5)
         
     | 
| 
      
 43 
     | 
    
         
            +
                  method_source (~> 0.8)
         
     | 
| 
      
 44 
     | 
    
         
            +
                  slop (~> 3.4)
         
     | 
| 
      
 45 
     | 
    
         
            +
                rake (10.0.4)
         
     | 
| 
      
 46 
     | 
    
         
            +
                rdoc (4.0.1)
         
     | 
| 
      
 47 
     | 
    
         
            +
                  json (~> 1.4)
         
     | 
| 
      
 48 
     | 
    
         
            +
                redis (3.0.2)
         
     | 
| 
      
 49 
     | 
    
         
            +
                rr (1.0.5)
         
     | 
| 
      
 50 
     | 
    
         
            +
                rspec (2.8.0)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  rspec-core (~> 2.8.0)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  rspec-expectations (~> 2.8.0)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  rspec-mocks (~> 2.8.0)
         
     | 
| 
      
 54 
     | 
    
         
            +
                rspec-core (2.8.0)
         
     | 
| 
      
 55 
     | 
    
         
            +
                rspec-expectations (2.8.0)
         
     | 
| 
       25 
56 
     | 
    
         
             
                  diff-lcs (~> 1.1.2)
         
     | 
| 
       26 
     | 
    
         
            -
                rspec-mocks (2. 
     | 
| 
      
 57 
     | 
    
         
            +
                rspec-mocks (2.8.0)
         
     | 
| 
      
 58 
     | 
    
         
            +
                slop (3.4.3)
         
     | 
| 
      
 59 
     | 
    
         
            +
                spork (0.9.2)
         
     | 
| 
      
 60 
     | 
    
         
            +
                terminal-table (1.4.5)
         
     | 
| 
      
 61 
     | 
    
         
            +
                thor (0.17.0)
         
     | 
| 
      
 62 
     | 
    
         
            +
                watchr (0.7)
         
     | 
| 
       27 
63 
     | 
    
         | 
| 
       28 
64 
     | 
    
         
             
            PLATFORMS
         
     | 
| 
      
 65 
     | 
    
         
            +
              ruby
         
     | 
| 
       29 
66 
     | 
    
         
             
              x86-mingw32
         
     | 
| 
       30 
67 
     | 
    
         | 
| 
       31 
68 
     | 
    
         
             
            DEPENDENCIES
         
     | 
| 
       32 
69 
     | 
    
         
             
              andand
         
     | 
| 
       33 
     | 
    
         
            -
              bundler ( 
     | 
| 
       34 
     | 
    
         
            -
               
     | 
| 
      
 70 
     | 
    
         
            +
              bundler (>= 1.2)
         
     | 
| 
      
 71 
     | 
    
         
            +
              guard
         
     | 
| 
      
 72 
     | 
    
         
            +
              guard-rspec
         
     | 
| 
      
 73 
     | 
    
         
            +
              guard-spork
         
     | 
| 
      
 74 
     | 
    
         
            +
              jeweler (>= 1.5.2)
         
     | 
| 
      
 75 
     | 
    
         
            +
              lre
         
     | 
| 
       35 
76 
     | 
    
         
             
              mharris_ext
         
     | 
| 
       36 
     | 
    
         
            -
               
     | 
| 
      
 77 
     | 
    
         
            +
              redis
         
     | 
| 
       37 
78 
     | 
    
         
             
              rr
         
     | 
| 
       38 
     | 
    
         
            -
              rspec (~> 2. 
     | 
| 
      
 79 
     | 
    
         
            +
              rspec (~> 2.8.0)
         
     | 
    
        data/Guardfile
    ADDED
    
    | 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # A sample Guardfile
         
     | 
| 
      
 2 
     | 
    
         
            +
            # More info at https://github.com/guard/guard#readme
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            guard 'rspec', :cli => "--drb" do
         
     | 
| 
      
 8 
     | 
    
         
            +
              watch(%r{^spec/.+_spec\.rb$})
         
     | 
| 
      
 9 
     | 
    
         
            +
              watch(%r{^lib/(.+)\.rb$})   { "spec" } # { |m| "spec/lib/#{m[1]}_spec.rb" }
         
     | 
| 
      
 10 
     | 
    
         
            +
              watch(%r{^lib/(.+)\.treetop$})   { "spec" }
         
     | 
| 
      
 11 
     | 
    
         
            +
              watch('spec/spec_helper.rb')  { "spec" }
         
     | 
| 
      
 12 
     | 
    
         
            +
            end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            guard 'spork' do
         
     | 
| 
      
 18 
     | 
    
         
            +
              watch('config/application.rb')
         
     | 
| 
      
 19 
     | 
    
         
            +
              watch('config/environment.rb')
         
     | 
| 
      
 20 
     | 
    
         
            +
              watch('config/environments/test.rb')
         
     | 
| 
      
 21 
     | 
    
         
            +
              watch(%r{^config/initializers/.+\.rb$})
         
     | 
| 
      
 22 
     | 
    
         
            +
              watch('Gemfile')
         
     | 
| 
      
 23 
     | 
    
         
            +
              watch('Gemfile.lock')
         
     | 
| 
      
 24 
     | 
    
         
            +
              watch('spec/spec_helper.rb') { :rspec }
         
     | 
| 
      
 25 
     | 
    
         
            +
              watch('test/test_helper.rb') { :test_unit }
         
     | 
| 
      
 26 
     | 
    
         
            +
              watch(%r{features/support/}) { :cucumber }
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
    
        data/LICENSE.txt
    CHANGED
    
    | 
         @@ -1,20 +1,20 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            Copyright (c) 2011 Mike Harris
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
       4 
     | 
    
         
            -
            a copy of this software and associated documentation files (the
         
     | 
| 
       5 
     | 
    
         
            -
            "Software"), to deal in the Software without restriction, including
         
     | 
| 
       6 
     | 
    
         
            -
            without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
       7 
     | 
    
         
            -
            distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
       8 
     | 
    
         
            -
            permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
       9 
     | 
    
         
            -
            the following conditions:
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            The above copyright notice and this permission notice shall be
         
     | 
| 
       12 
     | 
    
         
            -
            included in all copies or substantial portions of the Software.
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
       15 
     | 
    
         
            -
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
       16 
     | 
    
         
            -
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
       17 
     | 
    
         
            -
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
       18 
     | 
    
         
            -
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
       19 
     | 
    
         
            -
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
       20 
     | 
    
         
            -
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
| 
      
 1 
     | 
    
         
            +
            Copyright (c) 2011 Mike Harris
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
      
 4 
     | 
    
         
            +
            a copy of this software and associated documentation files (the
         
     | 
| 
      
 5 
     | 
    
         
            +
            "Software"), to deal in the Software without restriction, including
         
     | 
| 
      
 6 
     | 
    
         
            +
            without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
      
 7 
     | 
    
         
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
      
 8 
     | 
    
         
            +
            permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
      
 9 
     | 
    
         
            +
            the following conditions:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be
         
     | 
| 
      
 12 
     | 
    
         
            +
            included in all copies or substantial portions of the Software.
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
      
 15 
     | 
    
         
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
      
 16 
     | 
    
         
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
      
 17 
     | 
    
         
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
      
 18 
     | 
    
         
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
      
 19 
     | 
    
         
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
      
 20 
     | 
    
         
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/README.rdoc
    CHANGED
    
    | 
         @@ -1,19 +1,19 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            = choice
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            Description goes here.
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            == Contributing to choice
         
     | 
| 
       6 
     | 
    
         
            -
             
         
     | 
| 
       7 
     | 
    
         
            -
            * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
         
     | 
| 
       8 
     | 
    
         
            -
            * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
         
     | 
| 
       9 
     | 
    
         
            -
            * Fork the project
         
     | 
| 
       10 
     | 
    
         
            -
            * Start a feature/bugfix branch
         
     | 
| 
       11 
     | 
    
         
            -
            * Commit and push until you are happy with your contribution
         
     | 
| 
       12 
     | 
    
         
            -
            * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
         
     | 
| 
       13 
     | 
    
         
            -
            * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
            == Copyright
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
            Copyright (c) 2011 Mike Harris. See LICENSE.txt for
         
     | 
| 
       18 
     | 
    
         
            -
            further details.
         
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            = choice
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Description goes here.
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            == Contributing to choice
         
     | 
| 
      
 6 
     | 
    
         
            +
             
         
     | 
| 
      
 7 
     | 
    
         
            +
            * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
         
     | 
| 
      
 8 
     | 
    
         
            +
            * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
         
     | 
| 
      
 9 
     | 
    
         
            +
            * Fork the project
         
     | 
| 
      
 10 
     | 
    
         
            +
            * Start a feature/bugfix branch
         
     | 
| 
      
 11 
     | 
    
         
            +
            * Commit and push until you are happy with your contribution
         
     | 
| 
      
 12 
     | 
    
         
            +
            * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
         
     | 
| 
      
 13 
     | 
    
         
            +
            * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            == Copyright
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            Copyright (c) 2011 Mike Harris. See LICENSE.txt for
         
     | 
| 
      
 18 
     | 
    
         
            +
            further details.
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -1,50 +1,42 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'rubygems'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'bundler'
         
     | 
| 
       3 
     | 
    
         
            -
            begin
         
     | 
| 
       4 
     | 
    
         
            -
              Bundler.setup(:default, :development)
         
     | 
| 
       5 
     | 
    
         
            -
            rescue Bundler::BundlerError => e
         
     | 
| 
       6 
     | 
    
         
            -
              $stderr.puts e.message
         
     | 
| 
       7 
     | 
    
         
            -
              $stderr.puts "Run `bundle install` to install missing gems"
         
     | 
| 
       8 
     | 
    
         
            -
              exit e.status_code
         
     | 
| 
       9 
     | 
    
         
            -
            end
         
     | 
| 
       10 
     | 
    
         
            -
            require 'rake'
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
            require 'jeweler'
         
     | 
| 
       13 
     | 
    
         
            -
            Jeweler::Tasks.new do |gem|
         
     | 
| 
       14 
     | 
    
         
            -
              # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
         
     | 
| 
       15 
     | 
    
         
            -
              gem.name = "rchoice"
         
     | 
| 
       16 
     | 
    
         
            -
              gem.homepage = "http://github.com/mharris717/rchoice"
         
     | 
| 
       17 
     | 
    
         
            -
              gem.license = "MIT"
         
     | 
| 
       18 
     | 
    
         
            -
              gem.summary = %Q{choice}
         
     | 
| 
       19 
     | 
    
         
            -
              gem.description = %Q{choice}
         
     | 
| 
       20 
     | 
    
         
            -
              gem.email = "mharris717@gmail.com"
         
     | 
| 
       21 
     | 
    
         
            -
              gem.authors = ["Mike Harris"]
         
     | 
| 
       22 
     | 
    
         
            -
              # Include your dependencies below. Runtime dependencies are required when using your gem,
         
     | 
| 
       23 
     | 
    
         
            -
              # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
         
     | 
| 
       24 
     | 
    
         
            -
              #  gem.add_runtime_dependency 'jabber4r', '> 0.1'
         
     | 
| 
       25 
     | 
    
         
            -
              #  gem.add_development_dependency 'rspec', '> 1.2.3'
         
     | 
| 
       26 
     | 
    
         
            -
            end
         
     | 
| 
       27 
     | 
    
         
            -
            Jeweler::RubygemsDotOrgTasks.new
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
            require 'rspec/core'
         
     | 
| 
       30 
     | 
    
         
            -
            require 'rspec/core/rake_task'
         
     | 
| 
       31 
     | 
    
         
            -
            RSpec::Core::RakeTask.new(:spec) do |spec|
         
     | 
| 
       32 
     | 
    
         
            -
              spec.pattern = FileList['spec/**/*_spec.rb']
         
     | 
| 
       33 
     | 
    
         
            -
            end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
            RSpec::Core::RakeTask.new(:rcov) do |spec|
         
     | 
| 
       36 
     | 
    
         
            -
              spec.pattern = 'spec/**/*_spec.rb'
         
     | 
| 
       37 
     | 
    
         
            -
              spec.rcov = true
         
     | 
| 
       38 
     | 
    
         
            -
            end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
            task :default => :spec
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
            Rake::RDocTask.new do |rdoc|
         
     | 
| 
       44 
     | 
    
         
            -
              version = File.exist?('VERSION') ? File.read('VERSION') : ""
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
              rdoc.rdoc_dir = 'rdoc'
         
     | 
| 
       47 
     | 
    
         
            -
              rdoc.title = "choice #{version}"
         
     | 
| 
       48 
     | 
    
         
            -
              rdoc.rdoc_files.include('README*')
         
     | 
| 
       49 
     | 
    
         
            -
              rdoc.rdoc_files.include('lib/**/*.rb')
         
     | 
| 
       50 
     | 
    
         
            -
            end
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'bundler'
         
     | 
| 
      
 3 
     | 
    
         
            +
            begin
         
     | 
| 
      
 4 
     | 
    
         
            +
              Bundler.setup(:default, :development)
         
     | 
| 
      
 5 
     | 
    
         
            +
            rescue Bundler::BundlerError => e
         
     | 
| 
      
 6 
     | 
    
         
            +
              $stderr.puts e.message
         
     | 
| 
      
 7 
     | 
    
         
            +
              $stderr.puts "Run `bundle install` to install missing gems"
         
     | 
| 
      
 8 
     | 
    
         
            +
              exit e.status_code
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'rake'
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            require 'jeweler'
         
     | 
| 
      
 13 
     | 
    
         
            +
            Jeweler::Tasks.new do |gem|
         
     | 
| 
      
 14 
     | 
    
         
            +
              # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
         
     | 
| 
      
 15 
     | 
    
         
            +
              gem.name = "rchoice"
         
     | 
| 
      
 16 
     | 
    
         
            +
              gem.homepage = "http://github.com/mharris717/rchoice"
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem.license = "MIT"
         
     | 
| 
      
 18 
     | 
    
         
            +
              gem.summary = %Q{choice}
         
     | 
| 
      
 19 
     | 
    
         
            +
              gem.description = %Q{choice}
         
     | 
| 
      
 20 
     | 
    
         
            +
              gem.email = "mharris717@gmail.com"
         
     | 
| 
      
 21 
     | 
    
         
            +
              gem.authors = ["Mike Harris"]
         
     | 
| 
      
 22 
     | 
    
         
            +
              # Include your dependencies below. Runtime dependencies are required when using your gem,
         
     | 
| 
      
 23 
     | 
    
         
            +
              # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
         
     | 
| 
      
 24 
     | 
    
         
            +
              #  gem.add_runtime_dependency 'jabber4r', '> 0.1'
         
     | 
| 
      
 25 
     | 
    
         
            +
              #  gem.add_development_dependency 'rspec', '> 1.2.3'
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
      
 27 
     | 
    
         
            +
            Jeweler::RubygemsDotOrgTasks.new
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            require 'rspec/core'
         
     | 
| 
      
 30 
     | 
    
         
            +
            require 'rspec/core/rake_task'
         
     | 
| 
      
 31 
     | 
    
         
            +
            RSpec::Core::RakeTask.new(:spec) do |spec|
         
     | 
| 
      
 32 
     | 
    
         
            +
              spec.pattern = FileList['spec/**/*_spec.rb']
         
     | 
| 
      
 33 
     | 
    
         
            +
            end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            RSpec::Core::RakeTask.new(:rcov) do |spec|
         
     | 
| 
      
 36 
     | 
    
         
            +
              spec.pattern = 'spec/**/*_spec.rb'
         
     | 
| 
      
 37 
     | 
    
         
            +
              spec.rcov = true
         
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            task :default => :spec
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
    
        data/VERSION
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            0. 
     | 
| 
      
 1 
     | 
    
         
            +
            0.3.0
         
     | 
    
        data/lib/rchoice.rb
    CHANGED
    
    | 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'mharris_ext'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'andand'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            module RChoice
         
     | 
| 
       5 
     | 
    
         
            -
              class OptionNotChosenError < Exception; end
         
     | 
| 
       6 
     | 
    
         
            -
            end
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
            d = File.expand_path(File.dirname(__FILE__))
         
     | 
| 
       9 
     | 
    
         
            -
            Dir["#{d}/rchoice/**/*.rb"].each do |f|
         
     | 
| 
       10 
     | 
    
         
            -
              require f
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'mharris_ext'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'andand'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module RChoice
         
     | 
| 
      
 5 
     | 
    
         
            +
              class OptionNotChosenError < Exception; end
         
     | 
| 
      
 6 
     | 
    
         
            +
            end
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
            d = File.expand_path(File.dirname(__FILE__))
         
     | 
| 
      
 9 
     | 
    
         
            +
            Dir["#{d}/rchoice/**/*.rb"].each do |f|
         
     | 
| 
      
 10 
     | 
    
         
            +
              require f
         
     | 
| 
       11 
11 
     | 
    
         
             
            end
         
     | 
    
        data/lib/rchoice/choice.rb
    CHANGED
    
    | 
         @@ -1,39 +1,42 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            module RChoice
         
     | 
| 
       2 
     | 
    
         
            -
              class Choice
         
     | 
| 
       3 
     | 
    
         
            -
                include FromHash
         
     | 
| 
       4 
     | 
    
         
            -
                attr_accessor :optional, :action_blk, :chooser
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                fattr(: 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                 
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                   
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                   
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                 
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                   
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                   
     | 
| 
       25 
     | 
    
         
            -
                end
         
     | 
| 
       26 
     | 
    
         
            -
                def  
     | 
| 
       27 
     | 
    
         
            -
                   
     | 
| 
       28 
     | 
    
         
            -
                end
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
             
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                def  
     | 
| 
       36 
     | 
    
         
            -
                   
     | 
| 
       37 
     | 
    
         
            -
                end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            module RChoice
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Choice
         
     | 
| 
      
 3 
     | 
    
         
            +
                include FromHash
         
     | 
| 
      
 4 
     | 
    
         
            +
                attr_accessor :optional, :action_blk, :chooser, :name, :parent_obj
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                fattr(:choice_id) { rand(100000000000) }
         
     | 
| 
      
 7 
     | 
    
         
            +
                fattr(:options) { [] }
         
     | 
| 
      
 8 
     | 
    
         
            +
                fattr(:option_presenter) do
         
     | 
| 
      
 9 
     | 
    
         
            +
                  lambda { |o| o.to_s }
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
                fattr(:chosen_option) do
         
     | 
| 
      
 12 
     | 
    
         
            +
                  raise "no chooser" unless chooser
         
     | 
| 
      
 13 
     | 
    
         
            +
                  res = chooser.call(self)
         
     | 
| 
      
 14 
     | 
    
         
            +
                  raise OptionNotChosenError.new if !res && !optional
         
     | 
| 
      
 15 
     | 
    
         
            +
                  res
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
                def execute!
         
     | 
| 
      
 18 
     | 
    
         
            +
                  return unless action_blk
         
     | 
| 
      
 19 
     | 
    
         
            +
                  chosen_option.execute!(&action_blk) if chosen_option
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
                def make_option(obj,&b)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  return obj if obj.kind_of?(Option)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  obj = {:base_obj => obj} unless obj.kind_of?(Hash)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  Option.new(obj)
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
                def add_option(obj,&b)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  self.options << make_option(obj,&b)
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
                def options=(raw)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @options = raw.map { |r| make_option(r) }
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
              class ProcChoice < Choice
         
     | 
| 
      
 35 
     | 
    
         
            +
                def execute!
         
     | 
| 
      
 36 
     | 
    
         
            +
                  chosen_option.execute! if chosen_option
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
                def make_option(name,&b)
         
     | 
| 
      
 39 
     | 
    
         
            +
                  ProcOption.new(:name => name, :blk => b)
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
       39 
42 
     | 
    
         
             
            end
         
     |