-
Notifications
You must be signed in to change notification settings - Fork 900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove value2tag for count field in MiqExpression #18369
Remove value2tag for count field in MiqExpression #18369
Conversation
Thanks for finding this. With this class, I think it works better if we walk before running here. Can we try making this more verbose before we dry it up? Introduce more calls to I just want to trying to get all the code looking as similar as possible first. From here, I believe the code will become more approachable. Some examples (I very possibly flubbed these - please double check my work) elsif ops["count"]
target = parse_field_or_tag(ops["count"])
fld = "<count ref=#{target.model.to_s.downcase}>#{target.tag_path_with}</count>"
[fld, quote(ops["value"], field.col_type)]
elsif ops["regkey"] field = parse_field_or_tag(ops["field"])
case context_type
when "hash"
fld = "<value type=#{field.col_type}>#{field.to_s}</value>"
else
fld = "<value ref=#{field.model.to_s.downcase}, type=#{field.col_type}>#{field.tag_path_with(val)}</value>"
end
if ["like", "not like", "starts with", "ends with", "includes", "regular expression matches", "regular expression does not match"].include?(operator)
[fld, ops["value"]]
else
[fld, quote(ops["value"], field.col_type)]
end def self.quote(val, typ)
if (target = parse_field_or_tag(val) rescue nil)
return "<value ref=#{target.model.to_s.downcase}, type=#{target.col_type}>#{value}</value>"
end |
@@ -948,7 +948,7 @@ | |||
|
|||
describe "#to_ruby" do | |||
it "generates the ruby for a = expression with count" do | |||
actual = described_class.new("=" => {"count" => "Vm-snapshots", "value" => "1"}).to_ruby | |||
actual = described_class.new("=" => {"count" => "Vm.snapshots", "value" => "1"}).to_ruby |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I remember seeing both forms
Vm-snapshots
andVm.snapshots
. Could you explain the difference? - I didn't think
Expression::Field
supported an association
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember seeing both forms Vm-snapshots and Vm.snapshots. Could you explain the difference?
Vm.snapshots
- this is relation
Vm-snapshots
- this is column (MiqExpression::CountField::REGEX
)
I didn't think Expression::Field supported an association
yes it is forCountField
to filter according to count of records in relation.
🥅 🥅 Sub-sub goal : Remove value2tag because one should never use 2 to mean "to" nor 4 to mean "for" 😆 |
-1 NACK |
- it is not needed to have value2tag here method is only calling MiqExpression::Count in this situation - updating specs bude correct format is model.assocation (MiqExpression::CountField::REGEX)
514bae9
to
c080a86
Compare
@kbrock I agree with you - I added it in last commit. (I left the second commit to keep this idea in history If we will need it) I will continue with removing |
Checked commits lpichler/manageiq@46af818~...c080a86 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 |
value2tag
heremethod is only calling
MiqExpression::CountField.parse
in this situationmodel.assocation
(MiqExpression::CountField::REGEX)🥅 Sub goal : Remove
value2tag
- code inside of this method is basically calling other method on related instance ofMiqExpression::Target
and code after each calling ofvalue2tag
looks related toMiqExpression::Target
(or childs) - so it could be encapsulated⚽️ Goal: Remove useless code, simplification of MiqExpresion and finding code/patterns which could be live by
MiqExpression::Target
(childs) - moving responsibility toMiqExpression::Target
(childs)@miq-bot add_label refactoring, reporting
@miq-bot assign @kbrock