avalon 0.0.2 → 0.0.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.
@@ -5,14 +5,22 @@ module Avalon
5
5
  extend self
6
6
 
7
7
  def validate(*args, &block)
8
- Validator.new(*args, &block).validate
8
+ delegate(:validate, *args, &block)
9
9
  end
10
10
 
11
11
  def valid?(*args, &block)
12
- Validator.new(*args, &block).valid?
12
+ delegate(:valid?, *args, &block)
13
13
  end
14
14
 
15
15
  def invalid?(*args, &block)
16
- Validator.new(*args, &block).invalid?
16
+ delegate(:invalid?, *args, &block)
17
+ end
18
+
19
+ private
20
+
21
+ # In the usage of include, use self as target if target is abbreviated
22
+ def delegate(method_name, *args, &block)
23
+ args.unshift(self) if args.empty? && block_given?
24
+ Validator.new(*args, &block).send(method_name)
17
25
  end
18
26
  end
@@ -1,3 +1,3 @@
1
1
  module Avalon
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -21,4 +21,24 @@ describe Avalon do
21
21
  Avalon.invalid?("target", "pattern")
22
22
  end
23
23
  end
24
+
25
+ context "when included" do
26
+ let(:klass) do
27
+ Class.new do
28
+ include Avalon
29
+
30
+ def abc
31
+ "abc"
32
+ end
33
+ end
34
+ end
35
+
36
+ context "when not given target but given block" do
37
+ it "should take self as target of validation" do
38
+ expect do
39
+ klass.new.validate { abc =~ /def/ }
40
+ end.to raise_error(Avalon::ValidationError)
41
+ end
42
+ end
43
+ end
24
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avalon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-09-17 00:00:00.000000000 Z
12
+ date: 2012-09-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70209852418340 !ruby/object:Gem::Requirement
16
+ requirement: &70157829484560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70209852418340
24
+ version_requirements: *70157829484560
25
25
  description: Provide a simple validation method and validator class for Ruby
26
26
  email:
27
27
  - r7kamura@gmail.com