dzl 1.0.0.rc0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/config.ru CHANGED
@@ -45,7 +45,12 @@ end
45
45
  # run Dzl::Examples::FunWithScopes
46
46
  # end
47
47
 
48
- require 'dzl/examples/fun_with_hashes'
48
+ # require 'dzl/examples/fun_with_hashes'
49
+ # map '/' do
50
+ # run Dzl::Examples::FunWithHashes
51
+ # end
52
+
53
+ require 'dzl/examples/fun_with_pblocks'
49
54
  map '/' do
50
- run Dzl::Examples::FunWithHashes
55
+ run Dzl::Examples::FunWithPblocks
51
56
  end
@@ -29,6 +29,11 @@ class Dzl::DSLSubjects::Parameter < Dzl::DSLSubject
29
29
  def dup_data
30
30
  @opts = @opts.clone
31
31
  @validations = @validations.clone
32
+ @validations.each do |k, v|
33
+ if v.kind_of?(Dzl::Validator)
34
+ @validations[k] = v.clone
35
+ end
36
+ end
32
37
  @dsl_proxy = Dzl::DSLProxies::Parameter.new(self)
33
38
  end
34
39
 
@@ -0,0 +1,26 @@
1
+ require 'dzl/examples/base'
2
+
3
+ class Dzl::Examples::FunWithPblocks < Dzl::Examples::Base
4
+ pblock :foo do
5
+ required :ary do
6
+ type Array
7
+ size == 2
8
+ end
9
+ end
10
+
11
+ pblock :bar do
12
+ import_pblock :foo
13
+
14
+ required :ary do
15
+ size == 4
16
+ end
17
+ end
18
+
19
+ get '/foo' do
20
+ import_pblock :foo
21
+ end
22
+
23
+ get '/bar' do
24
+ import_pblock :bar
25
+ end
26
+ end
@@ -1,8 +1,8 @@
1
1
  module Dzl::Validators
2
2
  class Size < Dzl::Validator
3
3
  attr_reader :conditions
4
- def initialize
5
- @conditions = []
4
+ def initialize(conditions = {})
5
+ @conditions = conditions
6
6
  end
7
7
 
8
8
  def validate(input)
@@ -25,8 +25,13 @@ module Dzl::Validators
25
25
 
26
26
  [:==, :<=, :>=, :<, :>].each do |op|
27
27
  define_method(op) do |n|
28
- @conditions << [op, n]
28
+ @conditions[op] = n
29
29
  end
30
30
  end
31
+
32
+ def clone
33
+ dup_conditions = @conditions.clone
34
+ self.class.new(dup_conditions)
35
+ end
31
36
  end
32
37
  end
data/lib/dzl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dzl
2
- VERSION = "1.0.0.rc0"
2
+ VERSION = "1.0.0.rc1"
3
3
  end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+ require 'rack/test'
3
+ require 'dzl/examples/fun_with_pblocks'
4
+
5
+ describe Dzl::Examples::FunWithPblocks do
6
+ def app; Dzl::Examples::FunWithPblocks; end
7
+ include Rack::Test::Methods
8
+
9
+ specify '/foo required :ary size == 2' do
10
+ get('/foo?ary=one%20two').status.should == 200
11
+ get('/foo?ary=one%20two%20three%20four').status.should == 404
12
+ end
13
+
14
+ specify '/bar required :ary size == 4' do
15
+ get('/bar?ary=one%20two%20three%20four').status.should == 200
16
+ get('/bar?ary=one%20two').status.should == 404
17
+ end
18
+ end
@@ -241,4 +241,38 @@ describe HashValidator do
241
241
  ary: [1, 2, 3]
242
242
  }).should == true
243
243
  end
244
+
245
+ context 'allows re-opening of keys for redefinition' do
246
+ specify 'for a simple type change' do
247
+ v = HashValidator.new do
248
+ required(:foo)
249
+ end
250
+
251
+ v.valid?({foo: 'hello'}).should == true
252
+
253
+ v.required(:foo) do
254
+ type Fixnum
255
+ end
256
+
257
+ v.valid?({foo: 'hello'}).should == false
258
+ v.valid?({foo: 4}).should == true
259
+ end
260
+
261
+ specify 'for new allowed_values' do
262
+ v = HashValidator.new do
263
+ required(:foo) do
264
+ allowed_values ['two', 'four', 'six']
265
+ end
266
+ end
267
+
268
+ v.valid?({foo: 'two'}).should == true
269
+
270
+ v.required(:foo) do
271
+ allowed_values ['one', 'three', 'five']
272
+ end
273
+
274
+ v.valid?({foo: 'two'}).should == false
275
+ v.valid?({foo: 'three'}).should == true
276
+ end
277
+ end
244
278
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dzl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc0
4
+ version: 1.0.0.rc1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-03-27 00:00:00.000000000 Z
13
+ date: 2012-03-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
17
- requirement: &70190801357240 !ruby/object:Gem::Requirement
17
+ requirement: &70217913767620 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 1.4.1
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70190801357240
25
+ version_requirements: *70217913767620
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &70190801356740 !ruby/object:Gem::Requirement
28
+ requirement: &70217913766740 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: 3.2.2
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70190801356740
36
+ version_requirements: *70217913766740
37
37
  description: Small, fast racktivesupport web framework with handy DSL and explicit
38
38
  parameter validation.
39
39
  email:
@@ -82,6 +82,7 @@ files:
82
82
  - lib/dzl/examples/fun_with_hashes.rb
83
83
  - lib/dzl/examples/fun_with_hooks.rb
84
84
  - lib/dzl/examples/fun_with_params.rb
85
+ - lib/dzl/examples/fun_with_pblocks.rb
85
86
  - lib/dzl/examples/fun_with_requests.rb
86
87
  - lib/dzl/examples/fun_with_scopes.rb
87
88
  - lib/dzl/examples/route_profile.rb
@@ -105,6 +106,7 @@ files:
105
106
  - spec/fun_with_hashes_spec.rb
106
107
  - spec/fun_with_hooks_spec.rb
107
108
  - spec/fun_with_params_spec.rb
109
+ - spec/fun_with_pblocks_spec.rb
108
110
  - spec/fun_with_requests_spec.rb
109
111
  - spec/fun_with_scopes_spec.rb
110
112
  - spec/hash_validator_spec.rb
@@ -145,6 +147,7 @@ test_files:
145
147
  - spec/fun_with_hashes_spec.rb
146
148
  - spec/fun_with_hooks_spec.rb
147
149
  - spec/fun_with_params_spec.rb
150
+ - spec/fun_with_pblocks_spec.rb
148
151
  - spec/fun_with_requests_spec.rb
149
152
  - spec/fun_with_scopes_spec.rb
150
153
  - spec/hash_validator_spec.rb