rightscale/praxis — pull request #27 by jasonayre (2014-09-06 19:53:28+00:00)
Title: Revert to using AS::Concern for controller

@blanquer first, around filter stuff looks awesome cant wait to try it. Thanks so much.

The recent merge however, broke alot of things in the gem I was working on, due to the fact that I was relying on ActiveSupport::Concern, and you reverted to manually including and extending. I'm not sure exactly what was breaking in terms of inheritance on your side, but I included a test showing inheritance working in a child class inheriting from the parent that had included Praxis::Controller. Also, its a shot in the dark here, but Im wondering if whatever behavior you were seeing could be due to the use of uninheritable class instance variables, as I saw a couple places in the code which those could be doing some troublesome things (and I was having issues with responses being registered in my app, had to make my own response management).

Anyways, the one in particular Im referring to is:
https://github.com/rightscale/praxis/blob/341ec7abbc18dd18932e86ebefec804552b7087d/lib/praxis/response.rb#L14

Ill open a separate issue for that actually (above example is totally unrelated to the problem itself, but as an overall example of an issue that could be solved by utilizing active support, i.e.)
``` ruby
class_attribute :response_name
class_attribute :status
```
And simply having the child class override those two attributes if necessary (as class_attribute respects inheritance and ruby class instance variables do not otherwise)

Active support has solved so many ruby headaches and/or has so many good tools, I for one would like to see it used more throughout the project. (load hooks is another one Id like to see). So, I think, even if whatever inheritance behavior you were seeing is still present with using active support concern, and the problem itself were unsolvable, it would be worth using it still due to the dependency management portion of it, and the hackery that anyone using Praxis and trying to use an AS Concern will have to go through.

Back to the original issue, an example of what was happening:

``` ruby
module Traxis
module Controller
extend ::ActiveSupport::Concern
include ::Praxis::Controller
include ::Traxis::ControllerHelpers
include ::Traxis::ControllerActions

included do
class_attribute :collection_options
class_attribute :resource_options

self.collection_options = ::ActiveSupport::OrderedOptions.new
self.resource_options = ::ActiveSupport::OrderedOptions.new

self.collection_options.merge!({
:json_root => name.demodulize.underscore.pluralize
})

self.resource_options.merge!({
:finder_param => :id,
:finder => :find,
:json_root => name.demodulize.underscore.singularize
})
end

module ClassMethods
def handles(resource_klass, collection:, resource:)
resource_options.merge!(class: resource_klass)
collection_options.merge!(collection)
resource_options.merge!(resource)
end

def resource_class
resource_options[:class]
end
end

def collection_options
self.class.collection_options
end

def resource_options
self.class.resource_options
end

def resource_class
self.class.resource_class
end
end
end
```

Was working pre removal of active support. Post, active support, I had to do the following hackery

``` ruby
module Traxis
module Controller
extend ::ActiveSupport::Concern

included do
include ::Praxis::Controller
include ::Traxis::ControllerHelpers
include ::Traxis::ControllerActions
class_attribute :collection_options
class_attribute :resource_options
```

Because the dependencies get loaded all out of order (i.e., in the actual app I was implementing this in):

``` ruby

module Concerns
module Authenticated
extend ::ActiveSupport::Concern
include ::Traxis::Controller

included do
before :action do |controller|
end
```

Breaks, with a "Before method does not exist"

Basically, it tries to define the method on the class implementing the authenticated concern, before actually including the modules it needs, due to the removal of AS::Concern

Which keep in mind, will mean that anyone use Praxis who wants to use a concern, will likely run into similar issues, which is why I am of the opinion that AS::Concern should be kept in as it was.