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

[fix] Extract dependencies from object reference instead of class #13

Merged
merged 3 commits into from
Feb 2, 2021

Conversation

katyho
Copy link
Collaborator

@katyho katyho commented Feb 2, 2021

Summary

From here, the object reference is used to call the dependency block, not the class. Fix extracting dependencies when calling dependency_of to use the object reference as well.

Usually we have something like

memoize_method :method |_, *args| do...
end

so we don't care about the first argument.

Testing

Added specs to cover scenario. Without this change, the specs fail with something like

     Failure/Error: depends_on RedisMemo::Memoizable.new(id: obj.id, val: x)

     NoMethodError:
       undefined method `id' for #<Class:0x000056241936d420>

Specs succeed with this change

@katyho katyho requested a review from donaldong February 2, 2021 17:47
@codecov-io
Copy link

codecov-io commented Feb 2, 2021

Codecov Report

Merging #13 (090a2e2) into main (cc19d07) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #13   +/-   ##
=======================================
  Coverage   96.62%   96.63%           
=======================================
  Files          30       30           
  Lines        1691     1693    +2     
=======================================
+ Hits         1634     1636    +2     
  Misses         57       57           
Impacted Files Coverage Δ
lib/redis_memo/memoize_method.rb 96.42% <100.00%> (-0.13%) ⬇️
spec/memoizable/dependency_spec.rb 99.30% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc19d07...090a2e2. Read the comment docs.

RedisMemo::ArgumentError,
"#{method_name} is not a memoized method"
)
method_depends_on = self.class.instance_variable_get(:@memoized_dependencies)[method_name]
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should prefix this instance var with redis_memo to avoid potential conflicts?

@katyho katyho force-pushed the kho/fix_extract_dependencies branch from 8817db1 to b4a5d9a Compare February 2, 2021 19:09
@katyho katyho force-pushed the kho/fix_extract_dependencies branch from b4a5d9a to d555706 Compare February 2, 2021 22:26
@katyho katyho merged commit 1f5b121 into main Feb 2, 2021
@katyho katyho deleted the kho/fix_extract_dependencies branch February 2, 2021 22:29
@donaldong donaldong mentioned this pull request Feb 2, 2021
donaldong added a commit that referenced this pull request Feb 3, 2021
### Features
- #8 Pull in dependencies defined by other methods
- #11 Support Rails Single-Table Inheritance

### Bug Fixes
- #10 Invalidate cache on import!
- #13 Extract dependencies from object reference instead of class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants