bisque 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bisque.gemspec +1 -1
- data/lib/bisque/report.rb +10 -1
- data/spec/bisque/report_spec.rb +4 -0
- data/spec/resources/models.rb +5 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bisque.gemspec
CHANGED
data/lib/bisque/report.rb
CHANGED
@@ -9,7 +9,7 @@ module Bisque
|
|
9
9
|
@sql = self.class.query.dup
|
10
10
|
self.class.params.each do |param|
|
11
11
|
value = @params[param]
|
12
|
-
raise Bisque::MissingParameterException, "Missing parameter :#{param} for construction of #{self.class} - please provide a value for this parameter to the constructor or define a default." if value.nil?
|
12
|
+
raise Bisque::MissingParameterException, "Missing parameter :#{param} for construction of #{self.class} - please provide a value for this parameter to the constructor or define a default." if value.nil? && !self.class.optional.include?(param.intern)
|
13
13
|
@sql.gsub!(/(?<!:):#{param}/, sanitize_and_sqlize(value))
|
14
14
|
end
|
15
15
|
@results = ActiveRecord::Base.connection.execute @sql
|
@@ -109,6 +109,15 @@ module Bisque
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
def optional(*keys)
|
113
|
+
if keys
|
114
|
+
@optionals ||= []
|
115
|
+
@optionals = (@optionals + keys).uniq
|
116
|
+
else
|
117
|
+
@optionals || []
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
112
121
|
def query(qstr=nil)
|
113
122
|
if qstr
|
114
123
|
@qstr = qstr.strip
|
data/spec/bisque/report_spec.rb
CHANGED
@@ -97,6 +97,10 @@ describe Bisque::Report do
|
|
97
97
|
lambda { BarReport.new }.should raise_error Bisque::MissingParameterException
|
98
98
|
end
|
99
99
|
|
100
|
+
it "should not raise a Bisque::MissingParameterException if the query designates parameters but no defaults, it is constructed with no arguments, and the designated parameters are designated as optional" do
|
101
|
+
lambda { CornReport.new }.should_not raise_error
|
102
|
+
end
|
103
|
+
|
100
104
|
it "should accept a hash of parameters" do
|
101
105
|
lambda { BarReport.new :corn => 'cheese' }.should_not raise_error
|
102
106
|
end
|
data/spec/resources/models.rb
CHANGED
@@ -41,6 +41,11 @@ class FunReport < Bisque::Report
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
class CornReport < Bisque::Report
|
45
|
+
query "SELECT * FROM frobnitzs WHERE name = :corn"
|
46
|
+
optional :corn
|
47
|
+
end
|
48
|
+
|
44
49
|
class ParamReport < Bisque::Report
|
45
50
|
query "SELECT * FROM frobnitzs WHERE name = :name AND description = :description AND score = :score AND cost = :cost AND numberish = :numberish AND created_at = :created_at AND timish = :timish AND summed_at = :summed_at AND created_on = :created_on AND boolish = :boolish AND binny = :binny"
|
46
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bisque
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -201,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
201
|
version: '0'
|
202
202
|
segments:
|
203
203
|
- 0
|
204
|
-
hash: -
|
204
|
+
hash: -2336335870480925139
|
205
205
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
206
|
none: false
|
207
207
|
requirements:
|