bisque 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/bisque.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "bisque"
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jeremy Holland"]
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
@@ -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
@@ -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.2
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: -194881109709687049
204
+ hash: -2336335870480925139
205
205
  required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  none: false
207
207
  requirements: