appkernel 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,55 @@
1
+
2
+ require File.dirname(__FILE__) + '/../spec_helper'
3
+
4
+ describe "Type Conversion" do
5
+
6
+ describe "Boolean" do
7
+
8
+ it "should convert values the correct values into true, everything else should be false" do
9
+ tb("true").should be(true)
10
+ tb("True").should be(true)
11
+ tb("t").should be(true)
12
+ tb("y").should be(true)
13
+ tb("yes").should be(true)
14
+ tb("on").should be(true)
15
+
16
+ tb('1').should be(false)
17
+ tb('off').should be(false)
18
+ tb('false').should be(false)
19
+ tb('Phil Trotill').should be(false)
20
+ end
21
+
22
+ it "can call with a boolean function" do
23
+ function = Class.new(AppKernel::Function).class_eval do
24
+ self.tap do
25
+ option :bool, :type => AppKernel::Boolean, :index => 1
26
+ def execute
27
+ @bool
28
+ end
29
+ end
30
+ end
31
+
32
+ function.call("true").should == true
33
+ end
34
+
35
+ end
36
+
37
+ describe "Numeric" do
38
+ it "converts integers" do
39
+ t(Integer,"5").should == 5
40
+ end
41
+
42
+ it "converts floats" do
43
+ t(Float, "3.14").should == 3.14
44
+ end
45
+ end
46
+
47
+ def t(type, str)
48
+ type.to_option(str)
49
+ end
50
+
51
+ def tb(str)
52
+ t(AppKernel::Boolean, str)
53
+ end
54
+
55
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appkernel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-17 00:00:00 -06:00
12
+ date: 2009-10-06 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -43,13 +43,15 @@ files:
43
43
  - Rakefile
44
44
  - appkernel.gemspec
45
45
  - lib/appkernel.rb
46
+ - lib/appkernel/curry.rb
46
47
  - lib/appkernel/function.rb
47
- - lib/appkernel/validation.rb
48
+ - lib/appkernel/types.rb
48
49
  - script/console
49
50
  - script/destroy
50
51
  - script/generate
52
+ - spec/appkernel/curry_spec.rb
51
53
  - spec/appkernel/function_spec.rb
52
- - spec/appkernel/validation_spec.rb
54
+ - spec/appkernel/types_spec.rb
53
55
  - spec/spec.opts
54
56
  - spec/spec_helper.rb
55
57
  has_rdoc: true
@@ -1,82 +0,0 @@
1
- require 'delegate'
2
- module AppKernel::Validation
3
- class Validator
4
-
5
- attr_reader :errors
6
-
7
- def initialize(fun, &block)
8
- @fun = fun
9
- @body = block
10
- end
11
-
12
- def validate(vars = {})
13
- errors = {}
14
- scope = Object.new
15
- scope.extend @fun.mod
16
- for k,v in vars do
17
- val = case v
18
- when nil
19
- NilValue.new
20
- when Fixnum
21
- FixnumValue.new(v)
22
- when Symbol
23
- v
24
- when FalseClass
25
- FalseValue.new
26
- when TrueClass
27
- TrueValue.new
28
- else
29
- v.dup
30
- end
31
- unless Symbol === val
32
- val.extend Check
33
- val.instance_eval do
34
- @_add_validation_error = lambda {|message|
35
- errors[k] = message
36
- }
37
- end
38
- end
39
- scope.instance_variable_set("@#{k}", val)
40
- end
41
- scope.instance_eval &@body if @body
42
- errors
43
- end
44
-
45
- end
46
-
47
- module Check
48
- def check(condition, message)
49
- unless condition
50
- @_add_validation_error.call(message)
51
- end
52
- end
53
- end
54
-
55
- class NilValue < DelegateClass(NilClass)
56
- def initialize
57
- super(nil)
58
- end
59
-
60
- def nil?
61
- true
62
- end
63
- end
64
-
65
- class FalseValue < DelegateClass(FalseClass)
66
- def initialize
67
- super(false)
68
- end
69
- end
70
-
71
- class TrueValue < DelegateClass(TrueClass)
72
- def initialize
73
- super(true)
74
- end
75
- end
76
-
77
- class FixnumValue < DelegateClass(Fixnum)
78
- def initialize(val)
79
- super(val)
80
- end
81
- end
82
- end
@@ -1,32 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
-
3
- describe AppKernel::Validation do
4
-
5
-
6
- it "can do assertions which are associated with a field" do
7
- validate({:foo => 'bar'}) do
8
- @foo.check(!@foo.nil?, "'foo' cannot be nil")
9
- end.should be_empty
10
-
11
- validate({:foo => nil}) do
12
- @foo.check(!@foo.nil?, "cannot be nil.")
13
- end[:foo].should == "cannot be nil."
14
- end
15
-
16
- it "returns a positive result if there is no validation body passed" do
17
- validate().should be_empty
18
- end
19
-
20
-
21
- it "can validate fixnum fields fixnums" do
22
- validate({:num => 5}) do
23
- @num.check(@num < 5, "too big number!")
24
- end[:num].should == "too big number!"
25
- end
26
-
27
- def validate(vars = {}, &block)
28
- v = AppKernel::Validation::Validator.new(stub(:Fun, :mod => Module.new),&block)
29
- v.validate vars
30
- end
31
-
32
- end