boundy 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/lib/boundy.rb +19 -0
  3. data/lib/boundy/bound.rb +65 -0
  4. data/lib/boundy/bound/comparator.rb +67 -0
  5. data/lib/boundy/bound/constrainer.rb +29 -0
  6. data/lib/boundy/bound/infinite.rb +46 -0
  7. data/lib/boundy/bound/infinite/above.rb +12 -0
  8. data/lib/boundy/bound/infinite/below.rb +13 -0
  9. data/lib/boundy/comparator.rb +19 -0
  10. data/lib/boundy/comparators.rb +28 -0
  11. data/lib/boundy/domain.rb +115 -0
  12. data/lib/boundy/domain/anterior.rb +45 -0
  13. data/lib/boundy/domain/builder.rb +31 -0
  14. data/lib/boundy/domain/comparator.rb +26 -0
  15. data/lib/boundy/domain/constrainer.rb +21 -0
  16. data/lib/boundy/domain/finite.rb +64 -0
  17. data/lib/boundy/domain/posterior.rb +43 -0
  18. data/lib/boundy/formatter.rb +9 -0
  19. data/lib/boundy/formatter/sql.rb +26 -0
  20. data/lib/boundy/formatter/sql/domain.rb +20 -0
  21. data/lib/boundy/formatter/sql/domain/plugin.rb +22 -0
  22. data/lib/boundy/formatter/sql/factory.rb +14 -0
  23. data/lib/boundy/formatter/sql/plugin.rb +38 -0
  24. data/lib/boundy/formatters/bound.rb +16 -0
  25. data/lib/boundy/formatters/domain.rb +12 -0
  26. data/lib/boundy/formatters/fixnum.rb +20 -0
  27. data/lib/boundy/formatters/sql/bound.rb +22 -0
  28. data/lib/boundy/formatters/sql/domain.rb +28 -0
  29. data/lib/boundy/formatters/sql/domain/anterior.rb +23 -0
  30. data/lib/boundy/formatters/sql/domain/finite.rb +24 -0
  31. data/lib/boundy/formatters/sql/domain/posterior.rb +23 -0
  32. data/lib/boundy/formatters/time.rb +42 -0
  33. data/lib/boundy/range/comparator.rb +38 -0
  34. data/lib/boundy/range/constrainer.rb +17 -0
  35. data/lib/boundy/time/comparator.rb +37 -0
  36. data/test/integration/boundy_test.rb +37 -0
  37. data/test/integration/domain_test.rb +18 -0
  38. data/test/integration/formatter/sql_test.rb +21 -0
  39. data/test/integration/test_helper.rb +14 -0
  40. data/test/unit/boundy/bound/comparator_test.rb +37 -0
  41. data/test/unit/boundy/bound/constrainer_test.rb +123 -0
  42. data/test/unit/boundy/bound/infinite/above_test.rb +36 -0
  43. data/test/unit/boundy/bound/infinite/below_test.rb +36 -0
  44. data/test/unit/boundy/bound/infinite_test.rb +0 -0
  45. data/test/unit/boundy/bound_test.rb +86 -0
  46. data/test/unit/boundy/comparator_test.rb +0 -0
  47. data/test/unit/boundy/domain/anterior_test.rb +103 -0
  48. data/test/unit/boundy/domain/comparator_test.rb +75 -0
  49. data/test/unit/boundy/domain/constrainer_test.rb +11 -0
  50. data/test/unit/boundy/domain/posterior_test.rb +75 -0
  51. data/test/unit/boundy/domain_test.rb +50 -0
  52. data/test/unit/boundy/formatter/sql/domain/plugin_test.rb +16 -0
  53. data/test/unit/boundy/formatter/sql/plugin_test.rb +50 -0
  54. data/test/unit/boundy/formatter/sql_test.rb +26 -0
  55. data/test/unit/boundy/formatters/bound_test.rb +43 -0
  56. data/test/unit/boundy/formatters/domain_test.rb +12 -0
  57. data/test/unit/boundy/formatters/sql/domain/anterior_test.rb +29 -0
  58. data/test/unit/boundy/formatters/sql/domain/finite_test.rb +35 -0
  59. data/test/unit/boundy/formatters/sql/domain/posterior_test.rb +30 -0
  60. data/test/unit/boundy/formatters/time_test.rb +27 -0
  61. data/test/unit/boundy/range/comparator_test.rb +44 -0
  62. data/test/unit/boundy/range/constrainer_test.rb +11 -0
  63. data/test/unit/boundy/time/comparator_test.rb +40 -0
  64. data/test/unit/test_helper.rb +14 -0
  65. metadata +154 -0
@@ -0,0 +1,16 @@
1
+ require File.expand_path('../../../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/bound'
4
+ require 'boundy/domain/anterior'
5
+ require 'boundy/formatter/sql/domain/plugin'
6
+
7
+ class Boundy::Formatter::Sql::Domain::PluginTest < Test::Unit::TestCase
8
+ test "#punch" do
9
+ from = mock
10
+ Boundy::Bound.expects(:===).with(from).returns(true)
11
+ result = Boundy::Formatter::Sql::Domain::Plugin.punch(Boundy::Domain::Anterior.new(from))
12
+
13
+ assert_equal Boundy::Formatters::Sql::Domain::Anterior, result
14
+ end
15
+ end
16
+
@@ -0,0 +1,50 @@
1
+ require File.expand_path('../../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/formatter/sql/plugin'
4
+
5
+ class Boundy::Formatter::Sql::PluginTest < Test::Unit::TestCase
6
+ setup do
7
+ @random = Class.new do
8
+ def inspect
9
+ "RANDOM"
10
+ end
11
+ end
12
+
13
+ @formatter = Class.new do
14
+ def self.type=(type)
15
+ @@type = type
16
+ end
17
+
18
+ def self.type
19
+ @@type
20
+ end
21
+
22
+ def inspect
23
+ "FORMATTTER"
24
+ end
25
+
26
+ def initialize(inst, name)
27
+ end
28
+ end
29
+
30
+ @formatter.type = @random
31
+
32
+ @mock_factory = mock
33
+ Boundy::Formatter::Sql::Factory.expects(:new).returns(@mock_factory)
34
+ Boundy::Formatter::Sql::Factory.expects(:new).never
35
+
36
+ @formatter.class_eval do
37
+ include Boundy::Formatter::Sql::Plugin
38
+ end
39
+ end
40
+
41
+ test "#for" do
42
+ rand_inst = @random.new
43
+
44
+
45
+ result = Boundy::Formatter::Sql::Plugin.for(rand_inst)
46
+ assert_equal @mock_factory, result
47
+
48
+ end
49
+ end
50
+
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/formatter/sql'
4
+
5
+ class Boundy::Formatter::SqlTest < Test::Unit::TestCase
6
+ setup do
7
+ mock_instance = mock
8
+ @mock_delegate_formatter_factory = mock
9
+
10
+ Boundy::Formatter::Sql::Plugin.expects(:for).with(mock_instance).returns(@mock_delegate_formatter_factory)
11
+ @mock_formatter = mock
12
+ @mock_delegate_formatter_factory.expects(:build).with(mock_instance, "mock_name").returns(@mock_formatter)
13
+
14
+ @formatter = Boundy::Formatter::Sql.new(mock_instance, "mock_name")
15
+ end
16
+
17
+ test ".to_s" do
18
+ mock_rep = mock
19
+
20
+ @mock_formatter.expects(:to_s).returns(mock_rep)
21
+
22
+ result = @formatter.to_s
23
+
24
+ assert_equal mock_rep, result
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/formatters/bound'
4
+
5
+ class Boundy::Formatters::BoundTest < Test::Unit::TestCase
6
+ test "#to_s" do
7
+ mock_type = Class.new
8
+
9
+ formatter_klass = Class.new do
10
+ def initialize(bound)
11
+ @formatter = self.class.formatter
12
+ super
13
+ end
14
+
15
+ def self.formatter=(formatter)
16
+ @formatter = formatter
17
+ end
18
+
19
+ def self.formatter
20
+ @formatter
21
+ end
22
+ end
23
+
24
+ formatter_klass.class_eval do
25
+ include Boundy::Formatters::Bound
26
+ end
27
+
28
+ mock_bound = mock
29
+ mock_formatter = mock
30
+
31
+ formatter_klass.formatter = mock_formatter
32
+
33
+ mock_formatted = mock
34
+ mock_formatter.expects(:to_s).returns(mock_formatted)
35
+
36
+ formatter = formatter_klass.new(mock_bound)
37
+
38
+ result = formatter.to_s
39
+
40
+ assert_equal mock_formatted, result
41
+ end
42
+ end
43
+
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/formatters/domain'
4
+
5
+ class Boundy::Formatters::DomainTest < Test::Unit::TestCase
6
+ test "#format" do
7
+ mock_range = mock
8
+ mock_bound = mock
9
+ Boundy::Domain::Constrainer.new(mock_range,mock_bound)
10
+ end
11
+ end
12
+
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../../../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/formatters/sql/domain/anterior'
4
+
5
+ class Boundy::Formatters::Sql::Domain::AnterorTest < Test::Unit::TestCase
6
+ setup do
7
+
8
+ @name = "mock_thing"
9
+
10
+ @mock_domain = mock
11
+
12
+ @mock_from = mock
13
+
14
+ @mock_domain.expects(:from).returns(@mock_from)
15
+
16
+ @mock_from_formatter = mock
17
+
18
+ Boundy::Formatter::Sql.expects(:new).with(@mock_from, @name).returns(@mock_from_formatter)
19
+ end
20
+
21
+ test "#to_s" do
22
+ @mock_from_formatter.expects(:to_s).returns("from")
23
+
24
+ formatter = Boundy::Formatters::Sql::Domain::Anterior.new(@mock_domain, @name)
25
+ result = formatter.to_s
26
+
27
+ assert_equal "mock_thing >= 'from'", result
28
+ end
29
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path('../../../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/formatters/sql/domain/finite'
4
+
5
+ class Boundy::Formatters::Sql::Domain::FiniteTest < Test::Unit::TestCase
6
+ setup do
7
+ @name = "mock_thing"
8
+
9
+ @mock_domain = mock
10
+
11
+ @mock_from = mock
12
+ @mock_to = mock
13
+
14
+ @mock_domain.expects(:from).returns(@mock_from)
15
+ @mock_domain.expects(:to).returns(@mock_to)
16
+
17
+ @mock_from_formatter = mock
18
+ @mock_to_formatter = mock
19
+
20
+ Boundy::Formatter::Sql.expects(:new).with(@mock_from, @name).returns(@mock_from_formatter)
21
+ Boundy::Formatter::Sql.expects(:new).with(@mock_to, @name).returns(@mock_to_formatter)
22
+
23
+ end
24
+
25
+ test "#to_s" do
26
+ @mock_from_formatter.expects(:to_s).returns("from")
27
+ @mock_to_formatter.expects(:to_s).returns("to")
28
+
29
+ formatter = Boundy::Formatters::Sql::Domain::Finite.new(@mock_domain, "mock_thing")
30
+ result = formatter.to_s
31
+
32
+ assert_equal "mock_thing >= 'from' AND mock_thing <= 'to'", result
33
+ end
34
+ end
35
+
@@ -0,0 +1,30 @@
1
+ require File.expand_path('../../../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/formatters/sql/domain/posterior'
4
+
5
+ class Boundy::Formatters::Sql::Domain::PosteriorTest < Test::Unit::TestCase
6
+ setup do
7
+ @name = "mock_thing"
8
+
9
+ @mock_domain = mock
10
+
11
+ @mock_to = mock
12
+
13
+ @mock_domain.expects(:to).returns(@mock_to)
14
+
15
+ @mock_to_formatter = mock
16
+
17
+ Boundy::Formatter::Sql.expects(:new).with(@mock_to, @name).returns(@mock_to_formatter)
18
+ end
19
+
20
+ test "#to_s" do
21
+ @mock_to_formatter.expects(:to_s).returns("to")
22
+
23
+ formatter = Boundy::Formatters::Sql::Domain::Posterior.new(@mock_domain, "mock_thing")
24
+ result = formatter.to_s
25
+
26
+ assert_equal "mock_thing <= 'to'", result
27
+ end
28
+ end
29
+
30
+
@@ -0,0 +1,27 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/formatters/time'
4
+
5
+ class Boundy::Formatters::Time::FactoryTest < Test::Unit::TestCase
6
+ test "#new" do
7
+ format = "%Y%m%d"
8
+ factory = Boundy::Formatters::Time::Factory.new(format)
9
+
10
+ Boundy::Formatters::Time.factory = factory
11
+ time = Time.now
12
+ result = factory.build(time, "name")
13
+
14
+ assert_kind_of Boundy::Formatters::Time, result
15
+ end
16
+ end
17
+
18
+ class Boundy::Formatters::Time::FormatterTest < Test::Unit::TestCase
19
+ test "#to_s" do
20
+ time = Time.now
21
+ format = "%Y%m%d"
22
+ formatter = Boundy::Formatters::Time.new(format,time)
23
+
24
+ result = formatter.to_s
25
+ assert_equal time.strftime(format), result
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/bound'
4
+ require 'boundy/range/comparator'
5
+
6
+ class Boundy::Range::ComparatorTest < Test::Unit::TestCase
7
+ setup do
8
+ mock_begin = mock
9
+ mock_end = mock
10
+
11
+ mock_range = mock
12
+ mock_range.expects(:begin).returns(mock_begin)
13
+ mock_range.expects(:end).returns(mock_end)
14
+
15
+ mock_domain = mock
16
+
17
+ Boundy::Domain.expects(:new).with(mock_begin, mock_end).returns(mock_domain)
18
+
19
+ @mock_comparator = mock
20
+ mock_bound = mock
21
+
22
+ Boundy::Domain::Comparator.expects(:new).with(mock_bound, mock_domain).returns(@mock_comparator)
23
+
24
+ @comp = Boundy::Range::Comparator.new(mock_bound, mock_range)
25
+ end
26
+
27
+ test "#before?" do
28
+ @mock_comparator.expects(:before?).returns(true)
29
+
30
+ assert_equal @comp.before?, true
31
+ end
32
+
33
+ test "#within?" do
34
+ @mock_comparator.expects(:within?).returns(true)
35
+
36
+ assert_equal @comp.within?, true
37
+ end
38
+
39
+ test "#after?" do
40
+ @mock_comparator.expects(:after?).returns(true)
41
+
42
+ assert_equal @comp.after?, true
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/range/constrainer'
4
+
5
+ class Boundy::Range::ConstrainerTest < Test::Unit::TestCase
6
+ test "foo" do
7
+ range = (5.days.ago .. 1.day.ago)
8
+ mock_bound = mock
9
+ Boundy::Range::Constrainer.new(mock_bound, range)
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ require 'boundy/time/comparator'
4
+
5
+ class Boundy::Time::ComparatorTest < Test::Unit::TestCase
6
+ setup do
7
+ mock_time = mock
8
+
9
+ mock_bound = mock
10
+
11
+ mock_comparable_bound = mock
12
+
13
+ Boundy::Bound.expects(:new).with(mock_time).returns(mock_comparable_bound)
14
+
15
+ @mock_comparator = mock
16
+
17
+ Boundy::Bound::Comparator.expects(:new).with(mock_bound, mock_comparable_bound).returns(@mock_comparator)
18
+
19
+ @comp = Boundy::Time::Comparator.new(mock_bound, mock_time)
20
+ end
21
+
22
+ test "#before?" do
23
+ @mock_comparator.expects(:before?).returns(true)
24
+
25
+ assert_equal @comp.before?, true
26
+ end
27
+
28
+ test "#within?" do
29
+ @mock_comparator.expects(:within?).returns(true)
30
+
31
+ assert_equal @comp.within?, true
32
+ end
33
+
34
+ test "#after?" do
35
+ @mock_comparator.expects(:after?).returns(true)
36
+
37
+ assert_equal @comp.after?, true
38
+ end
39
+ end
40
+
@@ -0,0 +1,14 @@
1
+ $:.push('lib')
2
+
3
+ if ENV["ENABLE_SIMPLE_COV"]
4
+ require 'simplecov'
5
+ # require File.expand_path('../simplecov_helper', __FILE__)
6
+ SimpleCov.start do
7
+ add_filter "test"
8
+ add_group 'API', "lib"
9
+ end
10
+ end
11
+
12
+ require 'active_support/time'
13
+ require 'test/unit'
14
+ require 'mocha/setup'
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: boundy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Ed Carrel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2013-12-07 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: punchout
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - &id002
20
+ - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ type: :runtime
24
+ version_requirements: *id001
25
+ - !ruby/object:Gem::Dependency
26
+ name: test-unit
27
+ prerelease: false
28
+ requirement: &id003 !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - *id002
31
+ type: :development
32
+ version_requirements: *id003
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ prerelease: false
36
+ requirement: &id004 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - *id002
39
+ type: :development
40
+ version_requirements: *id004
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ prerelease: false
44
+ requirement: &id005 !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - *id002
47
+ type: :development
48
+ version_requirements: *id005
49
+ - !ruby/object:Gem::Dependency
50
+ name: simplecov
51
+ prerelease: false
52
+ requirement: &id006 !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - *id002
55
+ type: :development
56
+ version_requirements: *id006
57
+ description: " Boundy is a bounding and constraining library for any comparable types; it is like Ranges, but with much more flexibility.\n\n Boundy allows for the creation of bounded and partially-bounded intervals -- or domains. Boundy allows for these domains to be intersected, creating a new domain, which can be acted on further.\n\n I originally wrote Boundy for intersecting date ranges for reporting, but it should be useable for any Comparable types.\n"
58
+ email:
59
+ - edward@carrel.org
60
+ executables: []
61
+
62
+ extensions: []
63
+
64
+ extra_rdoc_files: []
65
+
66
+ files:
67
+ - lib/boundy.rb
68
+ - lib/boundy/bound.rb
69
+ - lib/boundy/comparator.rb
70
+ - lib/boundy/comparators.rb
71
+ - lib/boundy/domain.rb
72
+ - lib/boundy/formatter.rb
73
+ - lib/boundy/bound/comparator.rb
74
+ - lib/boundy/bound/constrainer.rb
75
+ - lib/boundy/bound/infinite.rb
76
+ - lib/boundy/domain/anterior.rb
77
+ - lib/boundy/domain/builder.rb
78
+ - lib/boundy/domain/comparator.rb
79
+ - lib/boundy/domain/constrainer.rb
80
+ - lib/boundy/domain/finite.rb
81
+ - lib/boundy/domain/posterior.rb
82
+ - lib/boundy/formatter/sql.rb
83
+ - lib/boundy/formatters/bound.rb
84
+ - lib/boundy/formatters/domain.rb
85
+ - lib/boundy/formatters/fixnum.rb
86
+ - lib/boundy/formatters/time.rb
87
+ - lib/boundy/range/comparator.rb
88
+ - lib/boundy/range/constrainer.rb
89
+ - lib/boundy/time/comparator.rb
90
+ - lib/boundy/formatters/sql/bound.rb
91
+ - lib/boundy/formatters/sql/domain.rb
92
+ - lib/boundy/formatters/sql/domain/anterior.rb
93
+ - lib/boundy/formatters/sql/domain/finite.rb
94
+ - lib/boundy/formatters/sql/domain/posterior.rb
95
+ - lib/boundy/formatter/sql/domain.rb
96
+ - lib/boundy/formatter/sql/factory.rb
97
+ - lib/boundy/formatter/sql/plugin.rb
98
+ - lib/boundy/formatter/sql/domain/plugin.rb
99
+ - lib/boundy/bound/infinite/above.rb
100
+ - lib/boundy/bound/infinite/below.rb
101
+ - test/integration/boundy_test.rb
102
+ - test/integration/domain_test.rb
103
+ - test/integration/test_helper.rb
104
+ - test/unit/test_helper.rb
105
+ - test/unit/boundy/bound_test.rb
106
+ - test/unit/boundy/comparator_test.rb
107
+ - test/unit/boundy/domain_test.rb
108
+ - test/unit/boundy/bound/comparator_test.rb
109
+ - test/unit/boundy/bound/constrainer_test.rb
110
+ - test/unit/boundy/bound/infinite_test.rb
111
+ - test/unit/boundy/domain/anterior_test.rb
112
+ - test/unit/boundy/domain/comparator_test.rb
113
+ - test/unit/boundy/domain/constrainer_test.rb
114
+ - test/unit/boundy/domain/posterior_test.rb
115
+ - test/unit/boundy/formatter/sql_test.rb
116
+ - test/unit/boundy/formatters/bound_test.rb
117
+ - test/unit/boundy/formatters/domain_test.rb
118
+ - test/unit/boundy/formatters/time_test.rb
119
+ - test/unit/boundy/range/comparator_test.rb
120
+ - test/unit/boundy/range/constrainer_test.rb
121
+ - test/unit/boundy/time/comparator_test.rb
122
+ - test/unit/boundy/formatters/sql/domain/anterior_test.rb
123
+ - test/unit/boundy/formatters/sql/domain/finite_test.rb
124
+ - test/unit/boundy/formatters/sql/domain/posterior_test.rb
125
+ - test/unit/boundy/formatter/sql/plugin_test.rb
126
+ - test/unit/boundy/formatter/sql/domain/plugin_test.rb
127
+ - test/unit/boundy/bound/infinite/above_test.rb
128
+ - test/unit/boundy/bound/infinite/below_test.rb
129
+ - test/integration/formatter/sql_test.rb
130
+ homepage:
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+
135
+ post_install_message:
136
+ rdoc_options: []
137
+
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - *id002
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - *id002
146
+ requirements: []
147
+
148
+ rubyforge_project:
149
+ rubygems_version: 2.1.10
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: A ranging and constraining gem
153
+ test_files: []
154
+