parameters 0.1.2 → 0.1.3

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.
@@ -1,3 +1,8 @@
1
+ === 0.1.3 / 2009-01-14
2
+
3
+ * Allow the use of lambdas to generate the default values of parameters.
4
+ * Fixed typos in the README.txt.
5
+
1
6
  === 0.1.2 / 2009-01-06
2
7
 
3
8
  * When printing parameter values, print the inspected version of the value.
data/README.txt CHANGED
@@ -6,12 +6,14 @@
6
6
 
7
7
  == DESCRIPTION:
8
8
 
9
- Parameters allows you to add annoted variables to your classes which may
9
+ Parameters allows you to add annotated variables to your classes which may
10
10
  have configurable default values.
11
11
 
12
12
  == FEATURES:
13
13
 
14
14
  * Give parameters default values.
15
+ * Default values maybe either objects or lambdas used to generate the
16
+ default value.
15
17
  * Change default values of parameters.
16
18
  * Give descriptions to parameters.
17
19
 
@@ -21,24 +23,33 @@ have configurable default values.
21
23
 
22
24
  include Parameters
23
25
 
24
- parameter :x, :value => 0
26
+ parameter :x, :default => 0
25
27
 
26
- parameter :y, :value => 0.5
28
+ parameter :y, :default => 0.5
27
29
 
28
30
  parameter :radius, :description => 'The radius of the Octagon'
31
+
32
+ parameter :opacity,
33
+ :default => lambda { rand },
34
+ :description => 'The opacity of the Octagon'
29
35
 
30
36
  end
31
37
 
32
38
  oct = Octagon.new
33
39
  oct.x # => 0
34
40
  oct.y # => 0.5
41
+ oct.opacity # => 0.25
35
42
 
36
43
  oct = Octagon.new(:radius => 10)
37
44
  oct.radius # => 10
45
+ oct.opacity # => 0.7
38
46
 
39
47
  Octagon.radius = 33
48
+ Octagon.opacity = 0.3
49
+
40
50
  oct = Octagon.new
41
51
  oct.radius # => 33
52
+ oct.opacity # => 0.3
42
53
 
43
54
  == INSTALL:
44
55
 
@@ -148,7 +148,11 @@ module Parameters
148
148
  # do not override existing instance value if present
149
149
  unless instance_variable_get("@#{param.name}")
150
150
  begin
151
- value = param.value.clone
151
+ if param.value.kind_of?(Proc)
152
+ value = param.value.call()
153
+ else
154
+ value = param.value.clone
155
+ end
152
156
  rescue TypeError
153
157
  value = param.value
154
158
  end
@@ -1,3 +1,3 @@
1
1
  module Parameters
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -15,6 +15,10 @@ describe Parameters do
15
15
 
16
16
  parameter :var_without_default,
17
17
  :description => 'This parameter does not have a default value'
18
+
19
+ parameter :var_with_lambda,
20
+ :default => lambda { rand },
21
+ :description => 'This parameter uses a lambda instead of a default value'
18
22
  end
19
23
 
20
24
  class InheritedParameters < TestParameters
@@ -101,6 +105,13 @@ describe Parameters do
101
105
  @test.instance_variable_get('@var').should == 3
102
106
  end
103
107
 
108
+ it "should allow using lambdas for the default values of parameters" do
109
+ test1 = TestParameters.new
110
+ test2 = TestParameters.new
111
+
112
+ test1.var_with_lambda.should_not == test2.var_with_lambda
113
+ end
114
+
104
115
  it "should contain the parameters from all ancestors" do
105
116
  @test_inherited.has_param?(:var).should == true
106
117
  @test_inherited.has_param?(:child_var).should == true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parameters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-05 00:00:00 -08:00
12
+ date: 2009-01-14 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,7 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: 1.8.2
24
24
  version:
25
- description: Parameters allows you to add annoted variables to your classes which may have configurable default values.
25
+ description: Parameters allows you to add annotated variables to your classes which may have configurable default values.
26
26
  email:
27
27
  - postmodern.mod3@gmail.com
28
28
  executables: []
@@ -79,6 +79,6 @@ rubyforge_project: parameters
79
79
  rubygems_version: 1.3.1
80
80
  signing_key:
81
81
  specification_version: 2
82
- summary: Parameters allows you to add annoted variables to your classes which may have configurable default values.
82
+ summary: Parameters allows you to add annotated variables to your classes which may have configurable default values.
83
83
  test_files: []
84
84