Skip to content
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

Update logger prefix if uid is set inside rule block #252

Merged
merged 1 commit into from
Mar 5, 2024

Conversation

jimtng
Copy link
Contributor

@jimtng jimtng commented Feb 12, 2024

No description provided.

@jimtng jimtng added the bug Something isn't working label Feb 12, 2024
@jimtng jimtng requested a review from ccutrer February 12, 2024 01:57
@ccutrer
Copy link
Contributor

ccutrer commented Feb 26, 2024

Caveat: it only gets updated after the block is evaluated. Logger inside the rule block itself will still be wrong.

Should we update it immediately when uid is called?

@jimtng jimtng force-pushed the rule-uid-logging branch 2 times, most recently from 7472bb5 to 5042325 Compare February 27, 2024 02:15
@jimtng
Copy link
Contributor Author

jimtng commented Feb 27, 2024

Caveat: it only gets updated after the block is evaluated. Logger inside the rule block itself will still be wrong.

Should we update it immediately when uid is called?

That's a nice challenge :) At first I thought I had to define #uid with a plain method, but then I thought of another way.

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
@@ -30,6 +32,7 @@ def prop(name)
elsif block
instance_variable_set(:"@#{name}", block)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ccutrer, This is unrelated to the PR, but I just noticed this. Shouldn't we call the block here instead?

Suggested change
instance_variable_set(:"@#{name}", block)
instance_variable_set(:"@#{name}", block.call(name))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that the idea was to pass a block to the property, e.g.

rule do
  tags { # build and return the required tags  }
end

Since this isn't documented I doubt anyone uses it this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would make sense to assign the block itself to the ivar, if you then actually call that block when reading the property, and if there was actually some advantage to deferring execution of that block until the property is read, but that's not really the case. execution could be deferred, but only until the end of the rule block, which doesn't seem useful. and like you said, not document. so I vote we just remove this functionality completely

@@ -30,6 +32,7 @@ def prop(name)
elsif block
instance_variable_set(:"@#{name}", block)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would make sense to assign the block itself to the ivar, if you then actually call that block when reading the property, and if there was actually some advantage to deferring execution of that block until the property is read, but that's not really the case. execution could be deferred, but only until the end of the rule block, which doesn't seem useful. and like you said, not document. so I vote we just remove this functionality completely

@ccutrer ccutrer merged commit 5e32a20 into openhab:main Mar 5, 2024
18 checks passed
@jimtng jimtng deleted the rule-uid-logging branch March 5, 2024 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants