add empty
This commit is contained in:
parent
58da4805fa
commit
6ebfc505c4
4 changed files with 42 additions and 1 deletions
|
@ -8,10 +8,12 @@ module Logic
|
|||
end
|
||||
|
||||
def self.class_from_name(name)
|
||||
[Constant]
|
||||
[Constant, Empty]
|
||||
.find { |c| c.name == name }
|
||||
end
|
||||
|
||||
def constant(value) = Logic::Constant.new(value)
|
||||
|
||||
def empty = Logic::Empty.new
|
||||
|
||||
end
|
||||
|
|
21
app/models/logic/empty.rb
Normal file
21
app/models/logic/empty.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
class Logic::Empty < Logic::Term
|
||||
def to_s = "empty member"
|
||||
|
||||
def type = :empty
|
||||
|
||||
def errors(_stable_ids = nil) = ['empty']
|
||||
|
||||
def to_h
|
||||
{
|
||||
"op" => self.class.name
|
||||
}
|
||||
end
|
||||
|
||||
def self.from_h(_h)
|
||||
self.new
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
self.class == other.class
|
||||
end
|
||||
end
|
16
spec/models/logic/empty_spec.rb
Normal file
16
spec/models/logic/empty_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
describe Logic::Constant do
|
||||
include Logic
|
||||
|
||||
describe '#type' do
|
||||
it { expect(empty.type).to eq(:empty) }
|
||||
end
|
||||
|
||||
describe '#errors' do
|
||||
it { expect(empty.errors).to eq(['empty']) }
|
||||
end
|
||||
|
||||
describe '#==' do
|
||||
it { expect(empty).to eq(empty) }
|
||||
it { expect(empty).not_to eq(constant(true)) }
|
||||
end
|
||||
end
|
|
@ -4,5 +4,7 @@ describe Logic do
|
|||
it 'serializes deserializes' do
|
||||
expect(Logic.from_h(constant(1).to_h)).to eq(constant(1))
|
||||
expect(Logic.from_json(constant(1).to_json)).to eq(constant(1))
|
||||
|
||||
expect(Logic.from_h(empty.to_h)).to eq(empty)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue