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

upgrade roar to current version #242

Merged
merged 2 commits into from
Feb 2, 2016

Conversation

ashtonthomas
Copy link
Contributor

We define a subclass of Roar::Decorator and include some modules which have had their namespace changed in roar 1.0.0.

Roar has seen a lot of new developments recently with support for hypermedia attributes. These changes along with the general value of not restricting dependency versions when we don't need to should merit this pull request.

In this pull request:

  • unpin roar (remove the pessimistic version control)
  • leave the minimum version at 0.12.0 as we need this for our decorator feature
  • support both pre/post 1.0.0 (currently using a LoadError rescue)

@ashtonthomas
Copy link
Contributor Author

We really only need to bump roar to 1.0.0 to get the change to namespaces

@darbyfrey
Copy link
Contributor

Could we change it to support both pre 1.0 and 1.x versions of Roar? Ideally, I think the individual services should decide which version they want to use and Napa should support all versions

@ashtonthomas ashtonthomas force-pushed the upgrade_roar branch 2 times, most recently from 65613c6 to c6ba31b Compare December 7, 2015 12:59
@ashtonthomas
Copy link
Contributor Author

@darbyfrey, is there a pattern for supporting different versions like you suggest?

I used a LoadError rescue and this seems to work. I've updated this pull request to support pre and post namespace refactoring. I have change the gemspec to allow higher version changes. Also, the Coercion didn't need a namespace prefix to work.

I tested this with an internal app and set roar to ~> 0.12.0 (0.12.9) as well as 1.0.0 and HEAD versions of roar.

Thoughts?

@ashtonthomas ashtonthomas changed the title [DISCUSS] upgrade roar to current version upgrade roar to current version Dec 7, 2015
@darbyfrey
Copy link
Contributor

While this would work, it's not very clear why you're doing the begin/rescue, etc.

A simple way to do it would be wrap a conditional around the VERSION value. So, something like:

if Roar::VERSION > 'x.y.z'
  # load files
else
  # load other files
end

Are the dependencies clear enough that you could use this approach?

@@ -25,7 +25,7 @@ Gem::Specification.new do |gem|
gem.add_dependency 'virtus', '~> 1.0.0'
gem.add_dependency 'grape', '~> 0.10.0'
gem.add_dependency 'grape-swagger', '~> 0.9.0'
gem.add_dependency 'roar', '~> 0.12.0'
gem.add_dependency 'roar', '>= 0.12.0'

Choose a reason for hiding this comment

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

This could use a specific pessimistic approach.

So we could do gem.add_dependency 'roar', '>= 0.12.0', '< 2.0.0'

@ochagata
Copy link

I agree that it shouldn't cause a LoadError and instead use an if/else clause.

@ashtonthomas
Copy link
Contributor Author

@darbyfrey I've used your approach. Yeah, that makes perfect sense. I was just totally unsure of the better way to do it. Thanks for the tip.

@ochagata, I've added the pessimistic upper bound limiting roar to 1.x

@ochagata
Copy link

👍

if Roar::VERSION >= '1.0.0'
require 'roar/json'
require 'roar/coercion'
REPRESENTER_JSON_MODULE = Roar::JSON
Copy link
Contributor

Choose a reason for hiding this comment

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

This will set a global constant in any app that uses Napa.

Any reason you can't pull this conditional around the include within the Representer class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a good call. will look into doing this

@ashtonthomas
Copy link
Contributor Author

@darbyfrey, I removed the constant, but I'm still not sure if this is the most appropriate method

@darbyfrey
Copy link
Contributor

This seems fine to me. You could add a helper method to wrap the version check to be more explicit about what you're doing, but that's not totally necessary.

+1 from me. Anyone else?

@shaqq
Copy link
Contributor

shaqq commented Jan 4, 2016

LGTM +1

@darbyfrey
Copy link
Contributor

@ashtonthomas, will you add a note for this change into the CHANGELOG? Then we can merge it in.

- this is two years out of date
- Removes Representer and Feature namespace
- added more stuff for JSONAPI, hypermedia
- This is going to bump the Representer gem which could cause issues for some project

update our representer to work with various versions of roar

allow for higher versions of roar

prefer version check over load error

pessimistic on upper version of roar

avoid using a global constant to include JSON module
@ashtonthomas
Copy link
Contributor Author

@darbyfrey, sorry for the delay. I rebased with master and added the changelog

@darbyfrey
Copy link
Contributor

Thanks @ashtonthomas!

darbyfrey added a commit that referenced this pull request Feb 2, 2016
upgrade roar to current version
@darbyfrey darbyfrey merged commit 489ef5b into bellycard:master Feb 2, 2016
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