set_builder 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +35 -0
  6. data/Rakefile +14 -0
  7. data/assets/javascripts/array.js +100 -0
  8. data/assets/javascripts/set_builder.js +415 -0
  9. data/init.rb +1 -0
  10. data/install.rb +1 -0
  11. data/lib/set_builder.rb +58 -0
  12. data/lib/set_builder/constraint.rb +67 -0
  13. data/lib/set_builder/modifier.rb +134 -0
  14. data/lib/set_builder/modifier/adverb.rb +11 -0
  15. data/lib/set_builder/modifier/base.rb +105 -0
  16. data/lib/set_builder/modifier/verb.rb +24 -0
  17. data/lib/set_builder/modifier_collection.rb +41 -0
  18. data/lib/set_builder/modifiers.rb +3 -0
  19. data/lib/set_builder/modifiers/date_modifier.rb +83 -0
  20. data/lib/set_builder/modifiers/number_modifier.rb +48 -0
  21. data/lib/set_builder/modifiers/string_modifier.rb +81 -0
  22. data/lib/set_builder/query_builders/string.rb +0 -0
  23. data/lib/set_builder/set.rb +81 -0
  24. data/lib/set_builder/trait.rb +74 -0
  25. data/lib/set_builder/traits.rb +42 -0
  26. data/lib/set_builder/value_map.rb +62 -0
  27. data/lib/set_builder/version.rb +3 -0
  28. data/set_builder.gemspec +25 -0
  29. data/spec/commands/example_command.rb +19 -0
  30. data/spec/dom.html +24 -0
  31. data/spec/lib/images/bg.png +0 -0
  32. data/spec/lib/images/hr.png +0 -0
  33. data/spec/lib/images/loading.gif +0 -0
  34. data/spec/lib/images/sprites.bg.png +0 -0
  35. data/spec/lib/images/sprites.png +0 -0
  36. data/spec/lib/images/vr.png +0 -0
  37. data/spec/lib/jspec.css +149 -0
  38. data/spec/lib/jspec.growl.js +115 -0
  39. data/spec/lib/jspec.jquery.js +88 -0
  40. data/spec/lib/jspec.js +1908 -0
  41. data/spec/lib/jspec.nodejs.js +18 -0
  42. data/spec/lib/jspec.shell.js +39 -0
  43. data/spec/lib/jspec.timers.js +154 -0
  44. data/spec/lib/jspec.xhr.js +210 -0
  45. data/spec/node.js +10 -0
  46. data/spec/rhino.js +10 -0
  47. data/spec/server.html +18 -0
  48. data/spec/server.rb +4 -0
  49. data/spec/unit/array.spec.js +82 -0
  50. data/spec/unit/set_builder.spec.js +166 -0
  51. data/spec/unit/spec.helper.js +0 -0
  52. data/test/date_modifier_test.rb +13 -0
  53. data/test/inflector_test.rb +27 -0
  54. data/test/modifier_test.rb +90 -0
  55. data/test/set_test.rb +96 -0
  56. data/test/test_helper.rb +79 -0
  57. data/test/trait_test.rb +49 -0
  58. data/test/traits_test.rb +41 -0
  59. data/test/value_map_test.rb +30 -0
  60. data/uninstall.rb +1 -0
  61. metadata +191 -0
@@ -0,0 +1,79 @@
1
+ require 'rubygems'
2
+ require "rails"
3
+ require "rails/test_help"
4
+ require "active_support/core_ext"
5
+ require "turn"
6
+ require 'set_builder'
7
+
8
+
9
+
10
+ # Mocks NamedScope so that composed scoping can be tested
11
+
12
+ class FakeScope
13
+
14
+ def initialize(args)
15
+ args = [args] unless args.is_a?(Array)
16
+ @composed_scope = args
17
+ end
18
+
19
+ def scoped(args)
20
+ FakeScope.new(@composed_scope + [args])
21
+ end
22
+
23
+ def composed_scope
24
+ @composed_scope
25
+ end
26
+
27
+ end
28
+
29
+
30
+
31
+ # Sample class used by tests
32
+
33
+ SetBuilder::ValueMap.register(:school, [[1, "Concordia"], [2, "McKendree"]])
34
+
35
+ class Friend
36
+ extend SetBuilder
37
+
38
+
39
+ trait(:is, "awesome") do |query|
40
+ {:conditions => {:awesome => true}}
41
+ end
42
+
43
+ trait(nil, "died") do |query|
44
+ {:conditions => {:alive => false}}
45
+ end
46
+
47
+ # this trait accepts modifiers --- an adverbial clause
48
+ trait(:was, "born", :date) do |query|
49
+ {:conditions => query.modifiers[0].build_conditions_for("friends.birthday")}
50
+ end
51
+
52
+ trait(:whose, "age", :number) do |query|
53
+ {:conditions => query.modifiers[0].build_conditions_for("friends.age")}
54
+ end
55
+
56
+ # this trait has a direct object
57
+ trait(:has, {"attended" => :school}) do |query|
58
+ {
59
+ :joins => "INNER JOIN schools ON friends.school_id=schools.id",
60
+ :conditions => {"schools.id" => query.direct_object}
61
+ }
62
+ end
63
+
64
+ # this trait is a noun
65
+ # also modifiers can be classes
66
+ trait(:whose, "name", StringModifier) do |query|
67
+ {:conditions => query.modifiers[0].build_conditions_for("friends.name")}
68
+ end
69
+
70
+
71
+
72
+ # by stubbing out scoped, we can unit test the `performed` features
73
+ def self.scoped(*args)
74
+ FakeScope.new(args)
75
+ end
76
+
77
+
78
+
79
+ end
@@ -0,0 +1,49 @@
1
+ require 'test_helper'
2
+
3
+ class TraitTest < ActiveSupport::TestCase
4
+ include SetBuilder::Modifiers
5
+
6
+
7
+ test "constraints find correct modifiers" do
8
+ trait = Friend.traits[:name]
9
+ assert_equal 1, trait.modifiers.length
10
+
11
+ constraint = trait.apply({:is => "Jerome"})
12
+ assert_equal 1, constraint.modifiers.length
13
+ assert_kind_of StringModifier, constraint.modifiers.first
14
+ end
15
+
16
+ test "modifiers should find correct values" do
17
+ trait = Friend.traits[:name]
18
+ modifier = trait.apply({:is => "Jerome"}).modifiers.first
19
+ assert_equal :is, modifier.operator
20
+ assert_equal ["Jerome"], modifier.values
21
+ end
22
+
23
+ test "traits correctly expect direct objects" do
24
+ trait_requires_direct_object = {
25
+ :awesome => false,
26
+ :born => false,
27
+ :attended => true,
28
+ :died => false,
29
+ :name => false
30
+ }
31
+ trait_requires_direct_object.each do |trait, expected_value|
32
+ assert_equal expected_value, Friend.traits[trait].requires_direct_object?
33
+ end
34
+ end
35
+
36
+ # test "traits whose direct objects support value mapping should be able to enumerate their values" do
37
+ # trait = Friend.traits[:attended]
38
+ # expected_map = {1 => "Concordia", 2 => "McKendree"}
39
+ # actual_map = trait.
40
+ # end
41
+
42
+ test "constraint should be valid" do
43
+ trait = Friend.traits[:name]
44
+ constraint = trait.apply({:is => "Jerome"})
45
+ assert constraint.valid?
46
+ end
47
+
48
+
49
+ end
@@ -0,0 +1,41 @@
1
+ require 'test_helper'
2
+
3
+ class TraitsTest < ActiveSupport::TestCase
4
+ include SetBuilder::Modifiers
5
+
6
+
7
+ test "traits" do
8
+ expected_traits = %w{age attended awesome born died name}
9
+ assert_equal expected_traits, Friend.traits.collect(&:name).sort
10
+ end
11
+
12
+ test "traits' accessor" do
13
+ traits = Friend.traits
14
+ assert_kind_of SetBuilder::Traits, traits
15
+ assert_equal "awesome", traits[0].name, "Array getter should still work like normal"
16
+ assert_kind_of SetBuilder::Trait, traits[:born], "If you pass a string or symbol Traits should lookup a trait by name"
17
+ end
18
+
19
+ test "trait method is protected" do
20
+ assert_raises NoMethodError, "this method is for use within class definition" do
21
+ Friend.trait
22
+ end
23
+ end
24
+
25
+ test "collection of modifiers" do
26
+ expected_modifiers = %w{DateModifier NumberModifier StringModifier}.collect {|name| "SetBuilder::Modifiers::#{name}"}
27
+ assert_equal expected_modifiers, Friend.traits.modifiers.collect(&:name).sort
28
+ end
29
+
30
+ test "to_json" do
31
+ expected_json = [['awesome', 'reflexive'],
32
+ ['died', 'active'],
33
+ ['born', 'passive', ['date']],
34
+ ['age', 'noun', ['number']],
35
+ [['attended', 'school'], 'perfect'],
36
+ ['name', 'noun', ['string']]].to_json
37
+ assert_equal expected_json, Friend.traits.to_json
38
+ end
39
+
40
+
41
+ end
@@ -0,0 +1,30 @@
1
+ require 'test_helper'
2
+
3
+ class ValueMapTest < ActiveSupport::TestCase
4
+
5
+
6
+ test "value map can fetch what you supplied it" do
7
+ expected_map = [[1, "Concordia"], [2, "McKendree"]]
8
+ assert_equal expected_map, SetBuilder::ValueMap.for(:school)
9
+ end
10
+
11
+
12
+ test "value map should fetch the correct value" do
13
+ expected_school = "Concordia"
14
+ assert_equal expected_school, SetBuilder::ValueMap.to_s(:school, 1)
15
+ end
16
+
17
+
18
+ test "value map should fetch the correct value when passed as a string" do
19
+ expected_school = "Concordia"
20
+ assert_equal expected_school, SetBuilder::ValueMap.to_s("school", 1)
21
+ end
22
+
23
+
24
+ test "value map should generate json that can be handed to the client-side SetBuilder" do
25
+ expected_json = "{\"school\":[[1,\"Concordia\"],[2,\"McKendree\"]]}"
26
+ assert_equal expected_json, SetBuilder::ValueMap.to_json
27
+ end
28
+
29
+
30
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: set_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Bob Lail
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - <
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - <
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: turn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A gem for describing constraints on data sets
70
+ email:
71
+ - bob.lailfamily@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - MIT-LICENSE
79
+ - README.md
80
+ - Rakefile
81
+ - assets/javascripts/array.js
82
+ - assets/javascripts/set_builder.js
83
+ - init.rb
84
+ - install.rb
85
+ - lib/set_builder.rb
86
+ - lib/set_builder/constraint.rb
87
+ - lib/set_builder/modifier.rb
88
+ - lib/set_builder/modifier/adverb.rb
89
+ - lib/set_builder/modifier/base.rb
90
+ - lib/set_builder/modifier/verb.rb
91
+ - lib/set_builder/modifier_collection.rb
92
+ - lib/set_builder/modifiers.rb
93
+ - lib/set_builder/modifiers/date_modifier.rb
94
+ - lib/set_builder/modifiers/number_modifier.rb
95
+ - lib/set_builder/modifiers/string_modifier.rb
96
+ - lib/set_builder/query_builders/string.rb
97
+ - lib/set_builder/set.rb
98
+ - lib/set_builder/trait.rb
99
+ - lib/set_builder/traits.rb
100
+ - lib/set_builder/value_map.rb
101
+ - lib/set_builder/version.rb
102
+ - set_builder.gemspec
103
+ - spec/commands/example_command.rb
104
+ - spec/dom.html
105
+ - spec/lib/images/bg.png
106
+ - spec/lib/images/hr.png
107
+ - spec/lib/images/loading.gif
108
+ - spec/lib/images/sprites.bg.png
109
+ - spec/lib/images/sprites.png
110
+ - spec/lib/images/vr.png
111
+ - spec/lib/jspec.css
112
+ - spec/lib/jspec.growl.js
113
+ - spec/lib/jspec.jquery.js
114
+ - spec/lib/jspec.js
115
+ - spec/lib/jspec.nodejs.js
116
+ - spec/lib/jspec.shell.js
117
+ - spec/lib/jspec.timers.js
118
+ - spec/lib/jspec.xhr.js
119
+ - spec/node.js
120
+ - spec/rhino.js
121
+ - spec/server.html
122
+ - spec/server.rb
123
+ - spec/unit/array.spec.js
124
+ - spec/unit/set_builder.spec.js
125
+ - spec/unit/spec.helper.js
126
+ - test/date_modifier_test.rb
127
+ - test/inflector_test.rb
128
+ - test/modifier_test.rb
129
+ - test/set_test.rb
130
+ - test/test_helper.rb
131
+ - test/trait_test.rb
132
+ - test/traits_test.rb
133
+ - test/value_map_test.rb
134
+ - uninstall.rb
135
+ homepage: ''
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.0.2
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Define traits on a model, create sets that constrain those traits, and generate
159
+ both natural-language descriptions of the sets and queries to select them
160
+ test_files:
161
+ - spec/commands/example_command.rb
162
+ - spec/dom.html
163
+ - spec/lib/images/bg.png
164
+ - spec/lib/images/hr.png
165
+ - spec/lib/images/loading.gif
166
+ - spec/lib/images/sprites.bg.png
167
+ - spec/lib/images/sprites.png
168
+ - spec/lib/images/vr.png
169
+ - spec/lib/jspec.css
170
+ - spec/lib/jspec.growl.js
171
+ - spec/lib/jspec.jquery.js
172
+ - spec/lib/jspec.js
173
+ - spec/lib/jspec.nodejs.js
174
+ - spec/lib/jspec.shell.js
175
+ - spec/lib/jspec.timers.js
176
+ - spec/lib/jspec.xhr.js
177
+ - spec/node.js
178
+ - spec/rhino.js
179
+ - spec/server.html
180
+ - spec/server.rb
181
+ - spec/unit/array.spec.js
182
+ - spec/unit/set_builder.spec.js
183
+ - spec/unit/spec.helper.js
184
+ - test/date_modifier_test.rb
185
+ - test/inflector_test.rb
186
+ - test/modifier_test.rb
187
+ - test/set_test.rb
188
+ - test/test_helper.rb
189
+ - test/trait_test.rb
190
+ - test/traits_test.rb
191
+ - test/value_map_test.rb