parameters 0.1.6 → 0.1.7
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.tar.gz.sig +3 -0
- data/History.txt +15 -0
- data/Manifest.txt +1 -0
- data/Rakefile +5 -4
- data/lib/parameters/class_param.rb +1 -1
- data/lib/parameters/instance_param.rb +1 -1
- data/lib/parameters/parameters.rb +27 -14
- data/lib/parameters/version.rb +1 -1
- data/spec/classes/custom_parameters.rb +20 -0
- data/spec/classes/other_parameters.rb +2 -2
- data/spec/classes/test_parameters.rb +5 -5
- data/spec/parameters_spec.rb +73 -0
- metadata +33 -7
- metadata.gz.sig +2 -0
    
        data.tar.gz.sig
    ADDED
    
    
    
        data/History.txt
    CHANGED
    
    | @@ -1,3 +1,18 @@ | |
| 1 | 
            +
            === 0.1.7 / 2009-07-19
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * Renamed Parameters#initialize_parameters to
         | 
| 4 | 
            +
              Parameters#initialize_params.
         | 
| 5 | 
            +
            * Adjust spacing in the output of ClassParam#to_s
         | 
| 6 | 
            +
              and InstanceParam#to_s.
         | 
| 7 | 
            +
            * Specifically check if the instance variable is nil
         | 
| 8 | 
            +
              before initializing it to the default value of the parameter.
         | 
| 9 | 
            +
            * Handle default value callbacks in Parameters#parameter.
         | 
| 10 | 
            +
            * Check the arity of all default value callbacks, before
         | 
| 11 | 
            +
              passing self to them.
         | 
| 12 | 
            +
            * Parameters#require_params now specifically tests if
         | 
| 13 | 
            +
              the instance variable of the parameter is nil.
         | 
| 14 | 
            +
            * Added more specs.
         | 
| 15 | 
            +
             | 
| 1 16 | 
             
            === 0.1.6 / 2009-05-11
         | 
| 2 17 |  | 
| 3 18 | 
             
            * Fixed a bug in Parameters.params= and Parameters#params=, where they
         | 
    
        data/Manifest.txt
    CHANGED
    
    
    
        data/Rakefile
    CHANGED
    
    | @@ -2,13 +2,14 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            require 'rubygems'
         | 
| 4 4 | 
             
            require 'hoe'
         | 
| 5 | 
            +
            require 'hoe/signing'
         | 
| 5 6 | 
             
            require './tasks/spec.rb'
         | 
| 6 7 | 
             
            require './lib/parameters/version.rb'
         | 
| 7 8 |  | 
| 8 | 
            -
            Hoe. | 
| 9 | 
            -
               | 
| 10 | 
            -
               | 
| 11 | 
            -
               | 
| 9 | 
            +
            Hoe.spec('parameters') do
         | 
| 10 | 
            +
              self.rubyforge_name = 'parameters'
         | 
| 11 | 
            +
              self.developer('Postmodern','postmodern.mod3@gmail.com')
         | 
| 12 | 
            +
              self.remote_rdoc_dir = '/'
         | 
| 12 13 | 
             
            end
         | 
| 13 14 |  | 
| 14 15 | 
             
            # vim: syntax=Ruby
         | 
| @@ -148,13 +148,17 @@ module Parameters | |
| 148 148 | 
             
              # _values_, which can override the default values of
         | 
| 149 149 | 
             
              # parameters.
         | 
| 150 150 | 
             
              #
         | 
| 151 | 
            -
              def  | 
| 151 | 
            +
              def initialize_params(values={})
         | 
| 152 152 | 
             
                self.class.each_param do |param|
         | 
| 153 153 | 
             
                  # do not override existing instance value if present
         | 
| 154 | 
            -
                   | 
| 154 | 
            +
                  if instance_variable_get("@#{param.name}".to_sym).nil?
         | 
| 155 155 | 
             
                    begin
         | 
| 156 156 | 
             
                      if param.value.kind_of?(Proc)
         | 
| 157 | 
            -
                        value = param.value. | 
| 157 | 
            +
                        value = if param.value.arity > 0
         | 
| 158 | 
            +
                                  param.value.call(self)
         | 
| 159 | 
            +
                                else
         | 
| 160 | 
            +
                                  param.value.call()
         | 
| 161 | 
            +
                                end
         | 
| 158 162 | 
             
                      else
         | 
| 159 163 | 
             
                        value = param.value.clone
         | 
| 160 164 | 
             
                      end
         | 
| @@ -167,21 +171,17 @@ module Parameters | |
| 167 171 |  | 
| 168 172 | 
             
                  self.params[param.name] = InstanceParam.new(self,param.name,param.description)
         | 
| 169 173 | 
             
                end
         | 
| 174 | 
            +
             | 
| 175 | 
            +
                self.params = values if values.kind_of?(Hash)
         | 
| 170 176 | 
             
              end
         | 
| 171 177 |  | 
| 172 178 | 
             
              #
         | 
| 173 | 
            -
              # Initializes the parameters using  | 
| 179 | 
            +
              # Initializes the parameters using initialize_params. If a +Hash+
         | 
| 174 180 | 
             
              # is passed in as the first argument, it will be used to set the values
         | 
| 175 181 | 
             
              # of parameters described within the Hash.
         | 
| 176 182 | 
             
              #
         | 
| 177 183 | 
             
              def initialize(*args,&block)
         | 
| 178 | 
            -
                 | 
| 179 | 
            -
             | 
| 180 | 
            -
                values = args.first
         | 
| 181 | 
            -
             | 
| 182 | 
            -
                if values.kind_of?(Hash)
         | 
| 183 | 
            -
                  self.params = values
         | 
| 184 | 
            -
                end
         | 
| 184 | 
            +
                initialize_params(args.first)
         | 
| 185 185 | 
             
              end
         | 
| 186 186 |  | 
| 187 187 | 
             
              #
         | 
| @@ -198,12 +198,25 @@ module Parameters | |
| 198 198 | 
             
              #
         | 
| 199 199 | 
             
              def parameter(name,options={})
         | 
| 200 200 | 
             
                name = name.to_sym
         | 
| 201 | 
            +
                default = options[:default]
         | 
| 202 | 
            +
                description = options[:description]
         | 
| 203 | 
            +
             | 
| 204 | 
            +
                # resolve the default value
         | 
| 205 | 
            +
                if default.kind_of?(Proc)
         | 
| 206 | 
            +
                  value = if default.arity > 0
         | 
| 207 | 
            +
                            default.call(self)
         | 
| 208 | 
            +
                          else
         | 
| 209 | 
            +
                            default.call()
         | 
| 210 | 
            +
                          end
         | 
| 211 | 
            +
                else
         | 
| 212 | 
            +
                  value = default
         | 
| 213 | 
            +
                end
         | 
| 201 214 |  | 
| 202 215 | 
             
                # set the instance variable
         | 
| 203 | 
            -
                instance_variable_set("@#{name}".to_sym, | 
| 216 | 
            +
                instance_variable_set("@#{name}".to_sym,value)
         | 
| 204 217 |  | 
| 205 218 | 
             
                # add the new parameter
         | 
| 206 | 
            -
                self.params[name] = InstanceParam.new(self,name, | 
| 219 | 
            +
                self.params[name] = InstanceParam.new(self,name,description)
         | 
| 207 220 |  | 
| 208 221 | 
             
                instance_eval %{
         | 
| 209 222 | 
             
                  # define the reader method for the parameter
         | 
| @@ -328,7 +341,7 @@ module Parameters | |
| 328 341 | 
             
                names.each do |name|
         | 
| 329 342 | 
             
                  name = name.to_s
         | 
| 330 343 |  | 
| 331 | 
            -
                   | 
| 344 | 
            +
                  if instance_variable_get("@#{name}".to_sym).nil?
         | 
| 332 345 | 
             
                    raise(Parameters::MissingParam,"parameter #{name.dump} has no value",caller)
         | 
| 333 346 | 
             
                  end
         | 
| 334 347 | 
             
                end
         | 
    
        data/lib/parameters/version.rb
    CHANGED
    
    
| @@ -0,0 +1,20 @@ | |
| 1 | 
            +
            require 'parameters'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class CustomParameters
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              include Parameters
         | 
| 6 | 
            +
             | 
| 7 | 
            +
              parameter :var, :description => 'A basic parameter'
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              parameter :var_with_default,
         | 
| 10 | 
            +
                        :default => 10,
         | 
| 11 | 
            +
                        :description => 'A parameter with a default value'
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              def initialize(var=nil,var_with_default=nil)
         | 
| 14 | 
            +
                @var = var
         | 
| 15 | 
            +
                @var_with_default = var_with_default
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                initialize_params()
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            end
         | 
| @@ -4,7 +4,7 @@ class OtherParameters | |
| 4 4 | 
             
              parameter :var, :description => 'Test parameter'
         | 
| 5 5 |  | 
| 6 6 | 
             
              parameter :var_with_default,
         | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 7 | 
            +
                        :default => 'other',
         | 
| 8 | 
            +
                        :description => 'This parameter has a default value'
         | 
| 9 9 |  | 
| 10 10 | 
             
            end
         | 
| @@ -4,13 +4,13 @@ class TestParameters | |
| 4 4 | 
             
              parameter :var, :description => 'Test parameter'
         | 
| 5 5 |  | 
| 6 6 | 
             
              parameter :var_with_default,
         | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 7 | 
            +
                        :default => 'thing',
         | 
| 8 | 
            +
                        :description => 'This parameter has a default value'
         | 
| 9 9 |  | 
| 10 10 | 
             
              parameter :var_without_default,
         | 
| 11 | 
            -
             | 
| 11 | 
            +
                        :description => 'This parameter does not have a default value'
         | 
| 12 12 |  | 
| 13 13 | 
             
              parameter :var_with_lambda,
         | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 14 | 
            +
                        :default => lambda { rand },
         | 
| 15 | 
            +
                        :description => 'This parameter uses a lambda instead of a default value'
         | 
| 16 16 | 
             
            end
         | 
    
        data/spec/parameters_spec.rb
    CHANGED
    
    | @@ -3,6 +3,7 @@ require 'parameters/parameters' | |
| 3 3 | 
             
            require 'spec_helper'
         | 
| 4 4 |  | 
| 5 5 | 
             
            require 'classes/test_parameters'
         | 
| 6 | 
            +
            require 'classes/custom_parameters'
         | 
| 6 7 | 
             
            require 'classes/inherited_parameters'
         | 
| 7 8 | 
             
            require 'classes/other_parameters'
         | 
| 8 9 |  | 
| @@ -41,6 +42,32 @@ describe Parameters do | |
| 41 42 | 
             
                  TestParameters.describe_param(:var).should_not be_empty
         | 
| 42 43 | 
             
                end
         | 
| 43 44 |  | 
| 45 | 
            +
                it "should be able to initialize parameters" do
         | 
| 46 | 
            +
                  obj = TestParameters.new
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  obj.params.should_not be_empty
         | 
| 49 | 
            +
                end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                it "should set initialize parameters with initial nil values" do
         | 
| 52 | 
            +
                  obj = CustomParameters.new
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  obj.var_with_default.should == 10
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                it "should not override previous parameter values" do
         | 
| 58 | 
            +
                  obj = CustomParameters.new(:test,5)
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  obj.var.should == :test
         | 
| 61 | 
            +
                  obj.var_with_default.should == 5
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                it "should not override previous 'false' values of parameters" do
         | 
| 65 | 
            +
                  obj = CustomParameters.new(false,false)
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                  obj.var.should == false
         | 
| 68 | 
            +
                  obj.var_with_default.should == false
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
             | 
| 44 71 | 
             
                it "should be able to create an object with initial parameter values" do
         | 
| 45 72 | 
             
                  obj = TestParameters.new(:var => 2, :var_with_default => 'stuff')
         | 
| 46 73 |  | 
| @@ -130,4 +157,50 @@ describe Parameters do | |
| 130 157 | 
             
                  }.should raise_error(Parameters::MissingParam)
         | 
| 131 158 | 
             
                end
         | 
| 132 159 | 
             
              end
         | 
| 160 | 
            +
             | 
| 161 | 
            +
              describe "runtime" do
         | 
| 162 | 
            +
                before(:each) do
         | 
| 163 | 
            +
                  @test = TestParameters.new
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                  @test.parameter :new_param
         | 
| 166 | 
            +
                  @test.parameter :new_param_with_default,
         | 
| 167 | 
            +
                                  :default => 5
         | 
| 168 | 
            +
                  @test.parameter :new_param_with_lambda,
         | 
| 169 | 
            +
                                  :default => lambda { |obj| obj.new_param_with_default + 2 }
         | 
| 170 | 
            +
                end
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                it "should allow for the addition of parameters" do
         | 
| 173 | 
            +
                  @test.has_param?(:new_param).should == true
         | 
| 174 | 
            +
                end
         | 
| 175 | 
            +
             | 
| 176 | 
            +
                it "should provide direct access to all parameters" do
         | 
| 177 | 
            +
                  @test.params[:new_param].should_not be_nil
         | 
| 178 | 
            +
                  @test.params[:new_param_with_default].should_not be_nil
         | 
| 179 | 
            +
                  @test.params[:new_param_with_lambda].should_not be_nil
         | 
| 180 | 
            +
                end
         | 
| 181 | 
            +
             | 
| 182 | 
            +
                it "should add reader methods for parameters" do
         | 
| 183 | 
            +
                  @test.new_param.should be_nil
         | 
| 184 | 
            +
                end
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                it "should add writer methods for parameters" do
         | 
| 187 | 
            +
                  @test.new_param = 10
         | 
| 188 | 
            +
                  @test.new_param.should == 10
         | 
| 189 | 
            +
                end
         | 
| 190 | 
            +
             | 
| 191 | 
            +
                it "should set the instance variables of parameters" do
         | 
| 192 | 
            +
                  @test.instance_variable_get(:@new_param_with_default).should == 5
         | 
| 193 | 
            +
             | 
| 194 | 
            +
                  @test.new_param_with_default = 10
         | 
| 195 | 
            +
                  @test.instance_variable_get(:@new_param_with_default).should == 10
         | 
| 196 | 
            +
                end
         | 
| 197 | 
            +
             | 
| 198 | 
            +
                it "should initialize parameters with default values" do
         | 
| 199 | 
            +
                  @test.new_param_with_default.should == 5
         | 
| 200 | 
            +
                end
         | 
| 201 | 
            +
             | 
| 202 | 
            +
                it "should initialize pamareters with default lambda values" do
         | 
| 203 | 
            +
                  @test.new_param_with_lambda.should == 7
         | 
| 204 | 
            +
                end
         | 
| 205 | 
            +
              end
         | 
| 133 206 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,15 +1,36 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: parameters
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.1. | 
| 4 | 
            +
              version: 0.1.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Postmodern
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 | 
            -
            cert_chain:  | 
| 10 | 
            +
            cert_chain: 
         | 
| 11 | 
            +
            - |
         | 
| 12 | 
            +
              -----BEGIN CERTIFICATE-----
         | 
| 13 | 
            +
              MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA9wb3N0
         | 
| 14 | 
            +
              bW9kZXJuLm1vZDMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
         | 
| 15 | 
            +
              ARkWA2NvbTAeFw0wOTA2MDMwNDU5MDNaFw0xMDA2MDMwNDU5MDNaMEYxGDAWBgNV
         | 
| 16 | 
            +
              BAMMD3Bvc3Rtb2Rlcm4ubW9kMzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYK
         | 
| 17 | 
            +
              CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
         | 
| 18 | 
            +
              1wvANkTDHFgVih5XLjuTwTZjgBq1lBGybXJiH6Id1lY2JOMqM5FB1DDHVvvij94i
         | 
| 19 | 
            +
              mJabN0zkzu6VKWC70y0IwOxY7CPokr0eFdK/D0y7mCq1P8QITv76i2YqAl0eYqIt
         | 
| 20 | 
            +
              W+IhIkANQ7E6uMZIZcdnfadC6lPAtlKkqtd9crvRbFgr6e3kyflmohbRnTEJHoRd
         | 
| 21 | 
            +
              7SHHsybE6DSn7oTDs6XBTNrNIn5VfZA0z01eeos/+zBm1zKJOK2+/7xtLLDuDU9G
         | 
| 22 | 
            +
              +Rd+ltUBbvxUrMNZmDG29pnmN2xTRH+Q8HxD2AxlvM5SRpK6OeZaHV7PaCCAVZ4L
         | 
| 23 | 
            +
              T9BFl1sfMvRlABeGEkSyuQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
         | 
| 24 | 
            +
              sDAdBgNVHQ4EFgQUKwsd+PqEYmBvyaTyoL+uRuk+PhEwDQYJKoZIhvcNAQEFBQAD
         | 
| 25 | 
            +
              ggEBAB4TvHsrlbcXcKg6gX5BIb9tI+zGkpzo0Z7jnxMEcNO7NGGwmzafDBI/xZYv
         | 
| 26 | 
            +
              xkRH3/HXbGGYDOi6Q6gWt5GujSx0bOImDtYTJTH8jnzN92HzEK5WdScm1QpZKF1e
         | 
| 27 | 
            +
              cezArMbxbSPaosxTCtG6LQTkE28lFQsmFZ5xzouugS4h5+LVJiVMmiP+l3EfkjFa
         | 
| 28 | 
            +
              GOURU+rNEMPWo8MCWivGW7jes6BMzWHcW7DQ0scNVmIcCIgdyMmpscuAEOSeghy9
         | 
| 29 | 
            +
              /fFs57Ey2OXBL55nDOyvN/ZQ2Vab05UH4t+GCxjAPeirzL/29FBtePT6VD44c38j
         | 
| 30 | 
            +
              pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
         | 
| 31 | 
            +
              -----END CERTIFICATE-----
         | 
| 11 32 |  | 
| 12 | 
            -
            date: 2009- | 
| 33 | 
            +
            date: 2009-07-19 00:00:00 -07:00
         | 
| 13 34 | 
             
            default_executable: 
         | 
| 14 35 | 
             
            dependencies: 
         | 
| 15 36 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -20,9 +41,11 @@ dependencies: | |
| 20 41 | 
             
                requirements: 
         | 
| 21 42 | 
             
                - - ">="
         | 
| 22 43 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 23 | 
            -
                    version:  | 
| 44 | 
            +
                    version: 2.3.2
         | 
| 24 45 | 
             
                version: 
         | 
| 25 | 
            -
            description:  | 
| 46 | 
            +
            description: |-
         | 
| 47 | 
            +
              Parameters allows you to add annotated variables to your classes which may
         | 
| 48 | 
            +
              have configurable default values.
         | 
| 26 49 | 
             
            email: 
         | 
| 27 50 | 
             
            - postmodern.mod3@gmail.com
         | 
| 28 51 | 
             
            executables: []
         | 
| @@ -54,12 +77,15 @@ files: | |
| 54 77 | 
             
            - tasks/spec.rb
         | 
| 55 78 | 
             
            - spec/spec_helper.rb
         | 
| 56 79 | 
             
            - spec/classes/test_parameters.rb
         | 
| 80 | 
            +
            - spec/classes/custom_parameters.rb
         | 
| 57 81 | 
             
            - spec/classes/inherited_parameters.rb
         | 
| 58 82 | 
             
            - spec/classes/other_parameters.rb
         | 
| 59 83 | 
             
            - spec/parser_spec.rb
         | 
| 60 84 | 
             
            - spec/parameters_spec.rb
         | 
| 61 85 | 
             
            has_rdoc: true
         | 
| 62 86 | 
             
            homepage: http://parameters.rubyforge.org/
         | 
| 87 | 
            +
            licenses: []
         | 
| 88 | 
            +
             | 
| 63 89 | 
             
            post_install_message: 
         | 
| 64 90 | 
             
            rdoc_options: 
         | 
| 65 91 | 
             
            - --main
         | 
| @@ -81,9 +107,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 81 107 | 
             
            requirements: []
         | 
| 82 108 |  | 
| 83 109 | 
             
            rubyforge_project: parameters
         | 
| 84 | 
            -
            rubygems_version: 1.3. | 
| 110 | 
            +
            rubygems_version: 1.3.4
         | 
| 85 111 | 
             
            signing_key: 
         | 
| 86 | 
            -
            specification_version:  | 
| 112 | 
            +
            specification_version: 3
         | 
| 87 113 | 
             
            summary: Parameters allows you to add annotated variables to your classes which may have configurable default values.
         | 
| 88 114 | 
             
            test_files: []
         | 
| 89 115 |  | 
    
        metadata.gz.sig
    ADDED