Skip to content

Make it possible to reduce available patterns #40

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

Merged
merged 16 commits into from
Jan 26, 2015
Merged

Make it possible to reduce available patterns #40

merged 16 commits into from
Jan 26, 2015

Conversation

maxmeyer
Copy link
Contributor

@maxmeyer maxmeyer commented Jan 7, 2015

This PR is based on rspec-PR and testsuite-PR.

This PR makes it possible to reduce the available patterns. To make this possible it moves code from the PatternGenerator-class to a separate class I named PatternDb. This class handles all the checks etc. To make the library more testable I also moved some code to helpers methods I can also use in the tests.

@maxmeyer
Copy link
Contributor Author

maxmeyer commented Jan 7, 2015

I also added aruba to make filesystem-tests possible though I didn't add tests which make use of it.

public

def initialize
@db = {
Copy link
Contributor

Choose a reason for hiding this comment

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

@patterns might be a better name, considering it is under an attr_reader.

@maxmeyer
Copy link
Contributor Author

maxmeyer commented Jan 8, 2015

Ok. Fixed.

@maxmeyer
Copy link
Contributor Author

maxmeyer commented Jan 8, 2015

Rebased.

@maxmeyer
Copy link
Contributor Author

maxmeyer commented Jan 8, 2015

Ready to go 🚀

@jasonlong
Copy link
Owner

Thanks @maxmeyer. I'm going to take a little time to get my head around this one. Hopefully I can do so in the next couple of days. Thanks again for all the work here!

@maxmeyer
Copy link
Contributor Author

maxmeyer commented Jan 8, 2015

No problem. You're welcome. Thanks a lot for making this library public. 😃

Hopefully I can do so in the next couple of days.

Would be great! I started using this library in a few projects of mine to generate some small eyecatchers. And spread the word about it. It's quite amazing how beautiful those generated images are.

:shipit:

@maxmeyer
Copy link
Contributor Author

BTW:

I added a few more tests. While writing them I also found a bug in the previous implementation of mine. Which is fixed now. I also added a proper exception for an invalid pattern which will be raised instead of "SystemExit" which is used by abort. Something I would expect to be raised by a commandline application but not a library.

@@ -0,0 +1,7 @@
module GeoPattern
# user errors
class UserError < StandardError; end
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 think using this kind of pattern for exceptions is a question of style. If you do not like it, I can remove the "intermediate" error.

Copy link
Owner

Choose a reason for hiding this comment

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

I don't have an opinion on this. @ttaylorr, do you?

Copy link
Contributor

Choose a reason for hiding this comment

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

I use this pattern all the time -- looks great.

@jasonlong
Copy link
Owner

The changes here seem ok to me. Much of it effects @ttaylorr's recent restructuring changes, so I want to make sure we have a 👍 from him as well.

@maxmeyer
Copy link
Contributor Author

Ok. Thanks for the feedback.

@maxmeyer
Copy link
Contributor Author

@ttaylorr ping :-)

@ttaylorr
Copy link
Contributor

Sorry that took so long, it's been a crazy few days for me!

Everything looks fine to me, but I would've implemented a PatternSieve class which has the responsibility of selecting available filters. If we don't want to go that route, this PR is fine to merge as-is.

@maxmeyer
Copy link
Contributor Author

I'm not sure if I understand you correctly. Do you suggest to move this method and those following this to a separate class? I'm open for suggestions. :-)

@jasonlong
Copy link
Owner

Friendly @ttaylorr ping. You aren't busy are you? 😉

@maxmeyer
Copy link
Contributor Author

😄

@maxmeyer
Copy link
Contributor Author

I think I've got an idea what he has got in his mind. @ttaylorr I think we're mixing multiple things in PatternDb:

  1. "Translating" strings to classes
  2. Checking if a pattern is valid
  3. Filtering patterns

Correct @ttaylorr? So I will try to splitup PatternDbinto two or three classes. One for each task mentioned above.

@ttaylorr
Copy link
Contributor

Yup. PatternDB has too many responsibilities right now. I think the
PatternDB class is fine to take those first two tasks, but the filtering
of Patterns should be done somewhere else.

What I had suggested earlier (albeit in some fairly ambiguous language) was
to create a PatternSieve which has a PatternDB as reference and a
Filter upon which it can narrow down options in the backing DB. A call
to PatternSieve#valid_patterns should return all elements in the backing
PatternDB #selected with the Filter object.

The Filter class would have one method Filter#is_valid(Pattern) which
would take in a pattern and return true/false depending on whether or not
that pattern matches the criteria set by that filter.

Make sense?

On Sat, Jan 24, 2015 at 3:06 PM, maxmeyer notifications@github.com wrote:

I think I've got an idea what he has got in his mind. @ttaylorr
https://github.com/ttaylorr I think we're mixing multiple things in
PatternDb:

  1. "Translating" strings to classes
  2. Checking if a pattern is valid
  3. Filtering patterns

Correct @ttaylorr https://github.com/ttaylorr? So I will try to splitup
PatternDbinto two or three classes. One for each task mentioned above.


Reply to this email directly or view it on GitHub
#40 (comment).

Thanks,
Taylor Blau

ttaylorr.com

@maxmeyer
Copy link
Contributor Author

Yes. I put together some more commits and push them as soon as I can. 😁 I think
is_valid -> valid? is a better choice ;-P.

@ttaylorr
Copy link
Contributor

Mixing my Java conventions with my Ruby conventions! Filter#valid? is a
much better choice in Ruby :)

On Sat, Jan 24, 2015 at 3:12 PM, maxmeyer notifications@github.com wrote:

Yes. I put together some more commits and push them as soon as I can. [image:
😁] I think
is_valid -> valid? is a better choice ;-P.


Reply to this email directly or view it on GitHub
#40 (comment).

Thanks,
Taylor Blau

ttaylorr.com

@maxmeyer
Copy link
Contributor Author

Maybe I rename PatternDB to PatternTranslator. But only if I also outsource the validation part.

@ttaylorr
Copy link
Contributor

I would go with PatternStore, but either will work 😄.

On Sat, Jan 24, 2015 at 3:14 PM, maxmeyer notifications@github.com wrote:

Maybe I rename PatternDB to PatternTranslator. But only if I also
outsource the validation part.


Reply to this email directly or view it on GitHub
#40 (comment).

Thanks,
Taylor Blau

ttaylorr.com

@maxmeyer
Copy link
Contributor Author

@ttaylorr
I like the name PatternStore. Changed the implementation already. I think I will push the new implementation this evening.

@maxmeyer
Copy link
Contributor Author

One thing I would like you to reconsider:
Changing the "pattern:"-option one last time from support classes to supporting Symbols by default. I think classes reveal too much implementation details and Symbols are much more common. The new implementaiton will support them as well. I will just change the deprecation warnings.

@ttaylorr
Copy link
Contributor

I disagree with it revealing too many implementation details, but for the
sake of Symbols being more common, this seems like a win to me.

On Sun, Jan 25, 2015 at 1:25 PM, maxmeyer notifications@github.com wrote:

One thing I would like you to reconsider:
Changing the "pattern:"-option one last time from support classes to
supporting Symbols by default. I think classes reveal too much
implementation details and Symbols are much more common. The new
implementaiton will support them as well. I will just change the
deprecation warnings.


Reply to this email directly or view it on GitHub
#40 (comment).

Thanks,
Taylor Blau

ttaylorr.com

@maxmeyer
Copy link
Contributor Author

I disagree with it revealing too many implementation details

You're revealing the structure of your library in the API by using e.g. GeoPattern::XesPattern. If you want to refactor your library and you need to change the structure of your library you would change the API as well: GeoPattern::XesPattern => GeoPattern::Generators::XesPattern.

The reason I raise this issue is the following: When introducing the Pattern-class (#44) I think it does make sense to rename the XesPattern etc. as well and name them according their function, XesPatternGenerator or wrap them in a Generator-module.

public

def initialize(
store = HashStore.new(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is kind of a HashWithIndifferentAccess. So there's no need to use strings here anymore.


def [](pattern)
if pattern.kind_of?(String) || pattern.kind_of?(Symbol)
$stderr.puts 'String pattern references are deprecated as of 1.3.0' if pattern.kind_of?(String)
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 added the deprecation warnings for string + class. I can revert this change @jasonlong. It's just a single commit.

@maxmeyer
Copy link
Contributor Author

@jasonlong @ttaylorr What do you think about the new structure?

#
# stream = capture(:stderr) { system('echo error 1>&2') }
# stream # => "error\n"
def capture(stream)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is also in Kernel::capture?

Copy link
Contributor

Choose a reason for hiding this comment

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

@ttaylorr it is, but this method is being deprecated due to it not being thread safe.

You can check it out here https://github.com/rails/rails/blob/346677b3137a35de65c660c230d6fe9e71aa9b0e/activesupport/lib/active_support/core_ext/kernel/reporting.rb

And here is the PR that talks about it rails/rails#13392

Sorry for the random interjection I'm working a similar problem in teachers_pet :bowtie:

@maxmeyer
Copy link
Contributor Author

@ttaylorr Fixed duplication of code. Yes, it's marked deprecated because of missing thread-safety, but I think this should be ok for testing. What do you think?

@jasonlong
Copy link
Owner

Guys, I apologize for my responsiveness. I've been dealing with some personal/family matters lately and haven't been able to focus much on this.

Most of this is lower level Ruby than I'm comfortable with, so I'm happy to defer to @ttaylorr, @tarebyte, and others to collaborate with you (@maxmeyer) on these decisions.

@ttaylorr
Copy link
Contributor

👍

@maxmeyer
Copy link
Contributor Author

😄 Love to see this merged.

@maxmeyer
Copy link
Contributor Author

@jasonlong

Guys, I apologize for my responsiveness. I've been dealing with some personal/family matters lately and haven't been able to focus much on this.

Hope everything is fine again for you/your familly soon!

jasonlong pushed a commit that referenced this pull request Jan 26, 2015
Make it possible to reduce available patterns
@jasonlong jasonlong merged commit 54497af into jasonlong:master Jan 26, 2015
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.

4 participants