fact_checker 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/basic.rb +1 -1
- data/fact_checker.gemspec +1 -1
- data/lib/fact_checker/boot.rb +31 -0
- data/lib/fact_checker/version.rb +1 -1
- data/lib/fact_checker.rb +3 -29
- data/spec/fact_checker_inheritance_spec.rb +9 -9
- data/spec/fact_checker_spec.rb +23 -10
- data/spec/support/classes_with_facts.rb +2 -0
- metadata +21 -27
data/examples/basic.rb
CHANGED
data/fact_checker.gemspec
CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.required_ruby_version = ">= 1.8.7"
|
24
24
|
s.required_rubygems_version = ">= 1.3.5"
|
25
25
|
|
26
|
-
s.add_development_dependency 'rspec', '~> 2.8.0'
|
27
26
|
s.add_development_dependency 'rake'
|
28
27
|
s.add_development_dependency 'bundler'
|
28
|
+
s.add_development_dependency 'rspec', '~> 2.9.0'
|
29
29
|
s.add_development_dependency 'simplecov', '~> 0.6.1'
|
30
30
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module FactChecker
|
4
|
+
def self.included(klass)
|
5
|
+
klass.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def inherited(child)
|
10
|
+
child.instance_variable_set('@fact_checker', fact_checker.dup)
|
11
|
+
end
|
12
|
+
|
13
|
+
def def_fact(*opts)
|
14
|
+
symbolic_fact_name = fact_checker.def_fact(*opts)
|
15
|
+
fact_name = symbolic_fact_name.to_s + '?'
|
16
|
+
unless fact_name.start_with? '_'
|
17
|
+
define_method(fact_name) { fact_accomplished?(symbolic_fact_name) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def fact_checker
|
22
|
+
@fact_checker ||= FactChecker::Base.new
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Delegate methods to self.class.fact_checker
|
27
|
+
[:fact_accomplished?, :fact_possible?, :accomplished_facts, :possible_facts].each do |name|
|
28
|
+
define_method(name) { |*opts| self.class.fact_checker.send(name, self, *opts) }
|
29
|
+
end
|
30
|
+
def facts; self.class.fact_checker.facts; end
|
31
|
+
end
|
data/lib/fact_checker/version.rb
CHANGED
data/lib/fact_checker.rb
CHANGED
@@ -1,31 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
module FactChecker
|
7
|
-
def self.included(klass)
|
8
|
-
klass.extend ClassMethods
|
9
|
-
end
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
def inherited(child)
|
13
|
-
child.instance_variable_set('@fact_checker', fact_checker.dup)
|
14
|
-
end
|
15
|
-
|
16
|
-
def def_fact(*opts)
|
17
|
-
fact_name = fact_checker.def_fact(*opts)
|
18
|
-
define_method(fact_name.to_s << '?') { fact_accomplished?(fact_name) }
|
19
|
-
end
|
20
|
-
|
21
|
-
def fact_checker
|
22
|
-
@fact_checker ||= FactChecker::Base.new
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Delegate methods to self.class.fact_checker
|
27
|
-
[:fact_accomplished?, :fact_possible?, :accomplished_facts, :possible_facts].each do |name|
|
28
|
-
define_method(name) { |*opts| self.class.fact_checker.send(name, self, *opts) }
|
29
|
-
end
|
30
|
-
def facts; self.class.fact_checker.facts; end
|
31
|
-
end
|
3
|
+
require 'fact_checker/base'
|
4
|
+
require 'fact_checker/version'
|
5
|
+
require 'fact_checker/boot'
|
@@ -12,47 +12,47 @@ describe 'FactCheckerInheritance' do
|
|
12
12
|
describe 'context for inherited facts' do
|
13
13
|
let(:target) { ChildOfClassWithFacts.new }
|
14
14
|
|
15
|
-
context 'inherited bare fact', :
|
15
|
+
context 'inherited bare fact', fact: :bare_fact do
|
16
16
|
it_behaves_like 'an accomplished fact', true
|
17
17
|
it_behaves_like 'a possible fact', true
|
18
18
|
end
|
19
19
|
|
20
|
-
context 'inherited true fact with no dependencies', :
|
20
|
+
context 'inherited true fact with no dependencies', fact: :true_fact_with_no_dependencies do
|
21
21
|
it_behaves_like 'an accomplished fact', true
|
22
22
|
it_behaves_like 'a possible fact', true
|
23
23
|
end
|
24
24
|
|
25
|
-
context 'inherited true fact with true dependencies', :
|
25
|
+
context 'inherited true fact with true dependencies', fact: :true_fact_with_true_dependencies do
|
26
26
|
it_behaves_like 'an accomplished fact', true
|
27
27
|
it_behaves_like 'a possible fact', true
|
28
28
|
end
|
29
29
|
|
30
|
-
context 'inherited true fact with false dependencies', :
|
30
|
+
context 'inherited true fact with false dependencies', fact: :true_fact_with_false_dependencies do
|
31
31
|
it_behaves_like 'an accomplished fact', false
|
32
32
|
it_behaves_like 'a possible fact', false
|
33
33
|
end
|
34
34
|
|
35
|
-
context 'inherited false fact with no dependencies', :
|
35
|
+
context 'inherited false fact with no dependencies', fact: :false_fact_with_no_dependencies do
|
36
36
|
it_behaves_like 'an accomplished fact', false
|
37
37
|
it_behaves_like 'a possible fact', true
|
38
38
|
end
|
39
39
|
|
40
|
-
context 'inherited false fact with true dependencies', :
|
40
|
+
context 'inherited false fact with true dependencies', fact: :false_fact_with_true_dependencies do
|
41
41
|
it_behaves_like 'an accomplished fact', false
|
42
42
|
it_behaves_like 'a possible fact', true
|
43
43
|
end
|
44
44
|
|
45
|
-
context 'inherited false fact with false dependencies', :
|
45
|
+
context 'inherited false fact with false dependencies', fact: :false_fact_with_false_dependencies do
|
46
46
|
it_behaves_like 'an accomplished fact', false
|
47
47
|
it_behaves_like 'a possible fact', false
|
48
48
|
end
|
49
49
|
|
50
50
|
specify '#facts' do
|
51
|
-
target.facts.size.should ==
|
51
|
+
target.facts.size.should == 8
|
52
52
|
end
|
53
53
|
|
54
54
|
specify '#accomplished_facts' do
|
55
|
-
target.accomplished_facts.should == [ :bare_fact, :true_fact_with_no_dependencies, :true_fact_with_true_dependencies ]
|
55
|
+
target.accomplished_facts.should == [ :bare_fact, :true_fact_with_no_dependencies, :true_fact_with_true_dependencies, :_private_fact ]
|
56
56
|
end
|
57
57
|
|
58
58
|
specify '#possible_facts' do
|
data/spec/fact_checker_spec.rb
CHANGED
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe
|
5
|
+
describe FactChecker do
|
6
6
|
describe ClassWithNoFacts do
|
7
|
+
subject { ClassWithNoFacts.new }
|
8
|
+
|
7
9
|
its(:facts) { should == [] }
|
8
10
|
its(:possible_facts) { should == [] }
|
9
11
|
its(:accomplished_facts) { should == [] }
|
@@ -23,47 +25,58 @@ describe 'FactChecker' do
|
|
23
25
|
describe 'context for facts' do
|
24
26
|
let(:target) { ClassWithFacts.new }
|
25
27
|
|
26
|
-
context 'given
|
28
|
+
context 'given private fact', fact: :_private_fact do
|
29
|
+
specify 'private fact included in #facts' do
|
30
|
+
target.facts.should include example.metadata[:fact]
|
31
|
+
end
|
32
|
+
|
33
|
+
specify 'private fact does not have a predicate method' do
|
34
|
+
target.methods(true).should_not include example.metadata[:fact]
|
35
|
+
-> { target.send(example.metadata[:fact].to_s + '?') }.should raise_error NoMethodError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'given bare fact', fact: :bare_fact do
|
27
40
|
it_behaves_like 'an accomplished fact', true
|
28
41
|
it_behaves_like 'a possible fact', true
|
29
42
|
end
|
30
43
|
|
31
|
-
context 'given true fact with no dependencies', :
|
44
|
+
context 'given true fact with no dependencies', fact: :true_fact_with_no_dependencies do
|
32
45
|
it_behaves_like 'an accomplished fact', true
|
33
46
|
it_behaves_like 'a possible fact', true
|
34
47
|
end
|
35
48
|
|
36
|
-
context 'given true fact with true dependencies', :
|
49
|
+
context 'given true fact with true dependencies', fact: :true_fact_with_true_dependencies do
|
37
50
|
it_behaves_like 'an accomplished fact', true
|
38
51
|
it_behaves_like 'a possible fact', true
|
39
52
|
end
|
40
53
|
|
41
|
-
context 'given true fact with false dependencies', :
|
54
|
+
context 'given true fact with false dependencies', fact: :true_fact_with_false_dependencies do
|
42
55
|
it_behaves_like 'an accomplished fact', false
|
43
56
|
it_behaves_like 'a possible fact', false
|
44
57
|
end
|
45
58
|
|
46
|
-
context 'given false fact with no dependencies', :
|
59
|
+
context 'given false fact with no dependencies', fact: :false_fact_with_no_dependencies do
|
47
60
|
it_behaves_like 'an accomplished fact', false
|
48
61
|
it_behaves_like 'a possible fact', true
|
49
62
|
end
|
50
63
|
|
51
|
-
context 'given false fact with true dependencies', :
|
64
|
+
context 'given false fact with true dependencies', fact: :false_fact_with_true_dependencies do
|
52
65
|
it_behaves_like 'an accomplished fact', false
|
53
66
|
it_behaves_like 'a possible fact', true
|
54
67
|
end
|
55
68
|
|
56
|
-
context 'given false fact with false dependencies', :
|
69
|
+
context 'given false fact with false dependencies', fact: :false_fact_with_false_dependencies do
|
57
70
|
it_behaves_like 'an accomplished fact', false
|
58
71
|
it_behaves_like 'a possible fact', false
|
59
72
|
end
|
60
73
|
|
61
74
|
specify '#facts' do
|
62
|
-
target.facts.size.should
|
75
|
+
target.facts.size.should be 8
|
63
76
|
end
|
64
77
|
|
65
78
|
specify '#accomplished_facts' do
|
66
|
-
target.accomplished_facts.should == [ :bare_fact, :true_fact_with_no_dependencies, :true_fact_with_true_dependencies ]
|
79
|
+
target.accomplished_facts.should == [ :bare_fact, :true_fact_with_no_dependencies, :true_fact_with_true_dependencies, :_private_fact ]
|
67
80
|
end
|
68
81
|
|
69
82
|
specify '#possible_facts' do
|
@@ -16,6 +16,8 @@ class ClassWithFacts
|
|
16
16
|
def_fact :false_fact_with_no_dependencies, :if => lambda { false }
|
17
17
|
def_fact :false_fact_with_true_dependencies => :bare_fact , :if => lambda { false }
|
18
18
|
def_fact :false_fact_with_false_dependencies => :false_fact_with_no_dependencies , :if => lambda { false }
|
19
|
+
|
20
|
+
def_fact :_private_fact
|
19
21
|
end
|
20
22
|
|
21
23
|
class ChildOfClassWithFacts < ClassWithFacts
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fact_checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-03
|
13
|
+
date: 2012-05-03 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
requirement: &
|
16
|
+
name: rake
|
17
|
+
requirement: &84289010 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
|
-
- -
|
20
|
+
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *84289010
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
-
requirement: &
|
27
|
+
name: bundler
|
28
|
+
requirement: &84288670 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,21 +33,21 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *84288670
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
39
|
-
requirement: &
|
38
|
+
name: rspec
|
39
|
+
requirement: &84288420 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ~>
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
44
|
+
version: 2.9.0
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *84288420
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: simplecov
|
50
|
-
requirement: &
|
50
|
+
requirement: &84288090 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ~>
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: 0.6.1
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *84288090
|
59
59
|
description: Simple gem to check hierarchically dependent "facts" about objects
|
60
60
|
email:
|
61
61
|
- alexisowl+fact_checker@gmail.com
|
@@ -73,6 +73,7 @@ files:
|
|
73
73
|
- fact_checker.gemspec
|
74
74
|
- lib/fact_checker.rb
|
75
75
|
- lib/fact_checker/base.rb
|
76
|
+
- lib/fact_checker/boot.rb
|
76
77
|
- lib/fact_checker/version.rb
|
77
78
|
- spec/fact_checker/base_spec.rb
|
78
79
|
- spec/fact_checker/version_spec.rb
|
@@ -102,16 +103,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
103
|
version: 1.3.5
|
103
104
|
requirements: []
|
104
105
|
rubyforge_project: fact_checker
|
105
|
-
rubygems_version: 1.8.
|
106
|
+
rubygems_version: 1.8.10
|
106
107
|
signing_key:
|
107
108
|
specification_version: 3
|
108
109
|
summary: Checks facts which may depend on other facts
|
109
|
-
test_files:
|
110
|
-
|
111
|
-
- spec/fact_checker/version_spec.rb
|
112
|
-
- spec/fact_checker_inheritance_spec.rb
|
113
|
-
- spec/fact_checker_spec.rb
|
114
|
-
- spec/spec.rake
|
115
|
-
- spec/spec_helper.rb
|
116
|
-
- spec/support/classes_with_facts.rb
|
117
|
-
- spec/support/shared_facts_behaviour.rb
|
110
|
+
test_files: []
|
111
|
+
has_rdoc:
|