feat(logic): operators sources
This commit is contained in:
parent
0df7090eaa
commit
81f00774af
10 changed files with 48 additions and 0 deletions
|
@ -5,6 +5,10 @@ class Logic::BinaryOperator < Logic::Term
|
|||
@left, @right = left, right
|
||||
end
|
||||
|
||||
def sources
|
||||
[@left, @right].flat_map(&:sources)
|
||||
end
|
||||
|
||||
def to_h
|
||||
{
|
||||
"term" => self.class.name,
|
||||
|
|
|
@ -23,6 +23,10 @@ class Logic::ChampValue < Logic::Term
|
|||
@stable_id = stable_id
|
||||
end
|
||||
|
||||
def sources
|
||||
[@stable_id]
|
||||
end
|
||||
|
||||
def compute(champs)
|
||||
targeted_champ = champ(champs)
|
||||
|
||||
|
|
|
@ -5,6 +5,10 @@ class Logic::Constant < Logic::Term
|
|||
@value = value
|
||||
end
|
||||
|
||||
def sources
|
||||
[]
|
||||
end
|
||||
|
||||
def compute(_champs = nil) = @value
|
||||
|
||||
def to_s(_type_de_champs = [])
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
class Logic::Empty < Logic::Term
|
||||
def sources
|
||||
[]
|
||||
end
|
||||
|
||||
def to_s(_type_de_champs = []) = I18n.t('logic.empty')
|
||||
|
||||
def type(_type_de_champs = []) = :empty
|
||||
|
|
|
@ -5,6 +5,10 @@ class Logic::NAryOperator < Logic::Term
|
|||
@operands = operands
|
||||
end
|
||||
|
||||
def sources
|
||||
@operands.flat_map(&:sources)
|
||||
end
|
||||
|
||||
def to_h
|
||||
{
|
||||
"term" => self.class.name,
|
||||
|
|
|
@ -18,6 +18,16 @@ describe Logic::BinaryOperator do
|
|||
describe '#errors' do
|
||||
it { expect(greater_than(constant(1), constant(true)).errors).to eq([{ operator_name: "Logic::GreaterThan", type: :required_number }]) }
|
||||
end
|
||||
|
||||
describe '#sources' do
|
||||
let(:champ) { create(:champ_integer_number, value: nil) }
|
||||
let(:champ2) { create(:champ_integer_number, value: nil) }
|
||||
|
||||
it { expect(two_greater_than_one.sources).to eq([]) }
|
||||
it { expect(greater_than(champ_value(champ.stable_id), constant(2)).sources).to eq([champ.stable_id]) }
|
||||
it { expect(greater_than(constant(2), champ_value(champ.stable_id)).sources).to eq([champ.stable_id]) }
|
||||
it { expect(greater_than(champ_value(champ.stable_id), champ_value(champ2.stable_id)).sources).to eq([champ.stable_id, champ2.stable_id]) }
|
||||
end
|
||||
end
|
||||
|
||||
describe Logic::GreaterThan do
|
||||
|
|
|
@ -83,6 +83,12 @@ describe Logic::ChampValue do
|
|||
it { expect(champ_value(champ.stable_id).errors([])).to eq([{ type: :not_available }]) }
|
||||
end
|
||||
|
||||
describe '#sources' do
|
||||
let(:champ) { create(:champ) }
|
||||
|
||||
it { expect(champ_value(champ.stable_id).sources).to eq([champ.stable_id]) }
|
||||
end
|
||||
|
||||
context 'with multiple revision' do
|
||||
let(:options) { ['revision_1'] }
|
||||
let(:procedure) do
|
||||
|
|
|
@ -21,4 +21,8 @@ describe Logic::Constant do
|
|||
it { expect(constant(1)).to eq(constant(1)) }
|
||||
it { expect(constant(1)).not_to eq(constant('a')) }
|
||||
end
|
||||
|
||||
describe '#sources' do
|
||||
it { expect(constant(1).sources).to eq([]) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,4 +17,8 @@ describe Logic::Constant do
|
|||
describe '#to_s' do
|
||||
it { expect(empty.to_s).to eq('un membre vide') }
|
||||
end
|
||||
|
||||
describe '#sources' do
|
||||
it { expect(empty.sources).to eq([]) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,6 +23,10 @@ describe Logic::NAryOperator do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#sources' do
|
||||
it { expect(and_from([false, true]).sources).to eq([]) }
|
||||
end
|
||||
|
||||
def and_from(boolean_to_constants)
|
||||
ds_and(boolean_to_constants.map { |b| constant(b) })
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue