Skip to content

Commit

Permalink
Add aliases for Boolean attribute class
Browse files Browse the repository at this point in the history
* It will now be possible to specify TrueClass or FalseClass for a
  Boolean attribute.
  • Loading branch information
dkubb committed Jun 19, 2013
1 parent 61e00ab commit d995759
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/flay.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
threshold: 41
total_score: 945.0
total_score: 947.0
2 changes: 1 addition & 1 deletion lib/axiom/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def self.name_from(object)
def self.infer_type(operand)
case operand
when Attribute, Function, Aggregate then operand.type
when FalseClass then Boolean
when ::FalseClass then Boolean
else
type = operand.class
descendants.detect { |descendant| type <= descendant.primitive }
Expand Down
9 changes: 7 additions & 2 deletions lib/axiom/attribute/boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Boolean < Object
#
# @api public
def self.primitive
TrueClass
::TrueClass
end

# Test if the value is a boolean
Expand All @@ -33,9 +33,14 @@ def self.primitive
#
# @api public
def valid_value?(value)
valid_or_optional?(value) { super || value.kind_of?(FalseClass) }
valid_or_optional?(value) { super || value.kind_of?(::FalseClass) }
end

end # class Boolean

# Add aliases for Boolean
TrueClass = Boolean
FalseClass = Boolean

end # class Attribute
end # module Axiom
2 changes: 1 addition & 1 deletion spec/unit/axiom/algebra/join/methods/join_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
context 'with a block' do
subject { object.send(method, other, &block) }

let(:other) { described_class.new([ Attribute::Boolean.new(:active) ], [ [ true ] ]) }
let(:other) { described_class.new([ [ :active, TrueClass ] ], [ [ true ] ]) }
let(:block) do
lambda do |relation|
relation[:id].eq(1).and(relation[:active].eq(true))
Expand Down

0 comments on commit d995759

Please sign in to comment.