Skip to content

[WIP] generator: refactor implementation, part 1#641

Closed
hilary wants to merge 10 commits intoexercism:masterfrom
hilary:refactor_implementation
Closed

[WIP] generator: refactor implementation, part 1#641
hilary wants to merge 10 commits intoexercism:masterfrom
hilary:refactor_implementation

Conversation

@hilary
Copy link
Copy Markdown
Contributor

@hilary hilary commented May 14, 2017

I did this PR in two parts. The first part (this one) separates out the Exercise model.

The second part (two different PRs) separates out the Repository model in two different ways. One PR creates a Repository which is instantiated with paths only. The second PR creates a Repository which is instantiated with paths and exercise.

hilary added 10 commits May 14, 2017 11:57
 #available shouldn't depend on the existence of a '<mumble>_case.rb'
file, because that might go away or get changed. We can just look
for the presence of a .meta/generator directory.
leftover from the proc days
Two reasons. Main reason: Implementation shouldn't be thinking in terms of
files. Secondary reason, old name was misleading, as it regenerates the file
when it exists :(
@hilary hilary requested a review from Insti May 14, 2017 23:28
@Insti Insti changed the title generator: refactor implementation, part 1 [WIP] generator: refactor implementation, part 1 May 18, 2017
def test_slug
subject = Implementation.new(paths: FixturePaths, slug: 'alpha')
assert_equal 'alpha', subject.slug
end
Copy link
Copy Markdown
Contributor

@Insti Insti May 19, 2017

Choose a reason for hiding this comment

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

This is not a test of core ruby functionality, it is a test that Implementation responds to slug.

Request: Keep this test.

Edit: But it needs to be deleted in the next commit anyway (for a different reason), so squash these two commits together.


def camel_case
underscore.split('_').map(&:capitalize).join
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • I'm sceptical of any change that is an "add" as part of a 'refactor' commit.
  • This change makes the class name Underscore inaccurate.

module GeneratorCases
class << self
def available(track_path)
cases_filepaths(track_path).map { |filepath| slugify(filepath) }.sort
Copy link
Copy Markdown
Contributor

@Insti Insti May 19, 2017

Choose a reason for hiding this comment

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

I strongly disagree with this change.

It is true that available does not need to know exactly how a test case is generated, and you could achieve this by abstracting out the availability criteria, but since that is all this class does that seems excessive.

because that might go away or get changed.

This is a case of YAGNI and we can worry about that when it happens.

See also: #646 which aims to give new generator implementers helpful advice.

Request: Omit this commit.


def test_name
exercise = Exercise.new(slug: 'alpha-beta')
assert_equal 'alpha_beta', exercise.name
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yay for tests.
I'm not sure name is the right name for this property, but it is consistent with what we've been using.

Comment thread test/generator/template_values_test.rb Outdated
end

class ClassBasedTestTemplateValuesFactory
class ClassBasedTestTemplateValuesFactory < TestTemplateValuesFactory
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You like tests to be way more DRY than I do.
I'm not sure this is a good idea.
(But it's not wrong.)

Comment thread test/generator/template_values_test.rb Outdated
include TemplateValuesFactory
end

class ClassBasedTestTemplateValuesFactory < TestTemplateValuesFactory
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It goes away anyway. Yay.

}
end

def test_abbreviated_commit_hash
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, not core ruby functionality.
That it is implemented using an attr_reader is irrelevant.

Request: omit this commit.


def exercise_name_camel
exercise_name.split('_').map(&:capitalize).join
exercise.name.camel_case
Copy link
Copy Markdown
Contributor

@Insti Insti May 19, 2017

Choose a reason for hiding this comment

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

slug is the canonical value for problem identity.
This should be exercise.slug.camel_case
But either way it's a Demeter violation, so should be just exercise.test_class_name

exercise_name_camel is a slightly misleading method name here given it's usage is to determine the test class name used in the template. But this should be a separate PR/refactoring. Issue: #651

@@ -3,20 +3,27 @@ module Generator
class TemplateValues
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The original intention of TemplateValues was that it it should be a dumb container and would only contain the template values available to the erb file. The initialize method provided one place where it was possible to see exactly all the properties that would be available to the erb.

It is the responsibility of the TemplateValuesFactory to construct the necessary values.

If that is the goal, then there is probably a nicer way of implementing this but I'm not sure this commit is heading in that direction.

Comment thread lib/generator.rb
# Doesn't update the version information.
class GenerateTests < ImplementationDelegator
def call
create_tests_file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this 👍

Copy link
Copy Markdown
Contributor

@Insti Insti left a comment

Choose a reason for hiding this comment

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

Nice work.

Many of my comments apply to the whole commit the comment is part of rather than that specific place.

I've marked things I feel strongly need changing with Request:
(beware: Github has hidden some of them under show outdated)

@Insti
Copy link
Copy Markdown
Contributor

Insti commented Jun 13, 2017

I've extracted the best parts from this PR in: #677 and will continue the refactoring from there.

@Insti Insti closed this Jun 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants