Merge pull request #7535 from betagouv/revert_terms_uuid

Revert "Add id to term"
This commit is contained in:
LeSim 2022-07-06 09:59:32 +02:00 committed by GitHub
commit e8ae8eb2ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 46 deletions

View file

@ -1,22 +1,20 @@
class Logic::BinaryOperator < Logic::Term
attr_reader :left, :right
def initialize(left, right, id = nil)
def initialize(left, right)
@left, @right = left, right
super(id)
end
def to_h
{
"term" => self.class.name,
"left" => @left.to_h,
"right" => @right.to_h,
"id" => @id
"right" => @right.to_h
}
end
def self.from_h(h)
self.new(Logic.from_h(h['left']), Logic.from_h(h['right']), h['id'])
self.new(Logic.from_h(h['left']), Logic.from_h(h['right']))
end
def errors(stable_ids = [])

View file

@ -17,9 +17,8 @@ class Logic::ChampValue < Logic::Term
attr_reader :stable_id
def initialize(stable_id, id = nil)
def initialize(stable_id)
@stable_id = stable_id
super(id)
end
def compute(champs)
@ -61,13 +60,12 @@ class Logic::ChampValue < Logic::Term
def to_h
{
"term" => self.class.name,
"stable_id" => @stable_id,
"id" => @id
"stable_id" => @stable_id
}
end
def self.from_h(h)
self.new(h['stable_id'], h['id'])
self.new(h['stable_id'])
end
def ==(other)

View file

@ -1,9 +1,8 @@
class Logic::Constant < Logic::Term
attr_reader :value
def initialize(value, id = nil)
def initialize(value)
@value = value
super(id)
end
def compute(_champs = nil) = @value
@ -35,13 +34,12 @@ class Logic::Constant < Logic::Term
def to_h
{
"term" => self.class.name,
"value" => @value,
"id" => @id
"value" => @value
}
end
def self.from_h(h)
self.new(h['value'], h['id'])
self.new(h['value'])
end
def ==(other)

View file

@ -1,8 +1,4 @@
class Logic::Empty < Logic::Term
def initialize(id = nil)
super(id)
end
def to_s = I18n.t('logic.empty')
def type = :empty
@ -11,13 +7,12 @@ class Logic::Empty < Logic::Term
def to_h
{
"term" => self.class.name,
"id" => @id
"term" => self.class.name
}
end
def self.from_h(h)
self.new(h['id'])
def self.from_h(_h)
self.new
end
def ==(other)

View file

@ -1,21 +1,19 @@
class Logic::NAryOperator < Logic::Term
attr_reader :operands
def initialize(operands, id = nil)
def initialize(operands)
@operands = operands
super(id)
end
def to_h
{
"term" => self.class.name,
"operands" => @operands.map(&:to_h),
"id" => @id
"operands" => @operands.map(&:to_h)
}
end
def self.from_h(h)
self.new(h['operands'].map { |operand_h| Logic.from_h(operand_h) }, h['id'])
self.new(h['operands'].map { |operand_h| Logic.from_h(operand_h) })
end
def errors(stable_ids = [])

View file

@ -1,10 +1,4 @@
class Logic::Term
attr_reader :id
def initialize(id = nil)
@id = id || SecureRandom.uuid
end
def to_json
to_h.to_json
end

View file

@ -15,18 +15,6 @@ describe Logic do
.to eq(ds_and([constant(true), constant(true), constant(false)]))
end
it 'saves its id' do
[
constant(1),
empty,
champ_value(1),
ds_eq(empty, empty),
ds_and([constant(true), constant(true)])
].each do |term|
expect(Logic.from_h(term.to_h).id).to eq(term.id)
end
end
describe '.ensure_compatibility_from_left' do
subject { Logic.ensure_compatibility_from_left(condition) }