remove rails dependencies
Hyperspec should depend on Rack rather than Rails, but still integrate with Rails if in a Rails environment.
HyperSpec
HyperSpec can now be run on top of Rack, and only optionally integrates with Rails.
HyperComponent
HyperComponent uses React-Rails to implement pre-rendering. However according to the React-Rails repo, there is no longer any dependency on Rails per se. Another option is have a look at https://github.com/prerender/prerender_rails, which may be a much better option going forward.
However, atm If Rails is not present, then you don't get any prerendering and everything else works. So this is not a hard dependency anyway.
HyperOperation
It should be possible to redo hyper-operation so that it is just a rack middle ware. There a few places it needs the "controller" to get things like x-csrf-token.
However there needs to be some way to get the acting_user which is currently assumed to be a method on ApplicationController, but I guess its all wound upwith how you would implement a session outside of rails. Any comments on how people do this in other Rack Frameworks would be appreciated.
HyperModel
This should depend only on hyper-operation for xport and active record, not rails, so once HyperOperation depends only on Rack, then HyperModel may be just done. However it is still very tied to ActiveRecord, but there is no problem using AR outside of Rails.
Some ideas on implementation details:
Rails dependencies go in files named rails.rb, inside of the gem's libs. That file then requires the rest of the gem. So hyper-component/rails would start with require hyper-component, and then have any rails specific dependencies.
Or we can continue to use the mechanism of checking for the existing of rails, before adding rails features.
Found this nice SO answer on how a gem can link in a middleware into rails:
https://stackoverflow.com/questions/5729737/automatically-add-rack-middleware-with-a-gem
require "tbbc/railtie" if defined? Rails in the outer file...
module TBBC
class Railtie < Rails::Railtie
initializer "tbbc.insert_middleware" do |app|
app.config.middleware.use "TBBC::Editor::Middleware"
end
end
end
I have also discovered that this seems to work to expand action view tags outside of the controller. No idea how robust it is.
def self.action_view
@action_view ||= ActionView::Base.new
end
def application!
@page = "#{self.class.action_view.javascript_include_tag('application')}\n#{@page}"
end
Hyper-spec is now only optionally dependent on Rails (well not quite released but its on edge, and documented) So you can also run Hyperspecs on Rack, or anything else that you can set up communication with the server.
Also will need to set Hyperstack.env : The following search list of environment variables works for newrelic:
RUBY_ENV RAILS_ENV APP_ENV RACK_ENV
So we should use that. (In otherwords find the first environment variable that is set and use that to initialize Hyperstack.env)