lib/raisin/rails/routes.rb in raisin-0.0.5 vs lib/raisin/rails/routes.rb in raisin-0.1.0
- old
+ new
@@ -1,42 +1,37 @@
-require 'raisin/version_constraint'
+require 'raisin/routing'
module ActionDispatch::Routing
class Mapper
- #
- #
- #
- def mount_api(raisin_api)
- raisin_api.versions.each do |version, routes|
- next if routes.empty?
+ def api(options, &block)
+ return unless block_given?
- send(:constraints, Raisin::VersionConstraint.new(version)) {
- routes.each do |method, path, endpoint|
- send(method, path, to: endpoint)
- end
- }
- end
- end
- end
+ version = options[:version].to_s
+ is_default = options.fetch(:default, false)
- class RouteSet
- class Dispatcher
+ raise 'Version is missing in constraint' if version.blank?
- #
- # Allow to use controller like 'UsersAPI' instead of 'UsersController'
- #
- def controller_reference_with_api(controller_param)
- controller_name = "#{controller_param.camelize}Api"
- unless controller = @controllers[controller_param]
- controller = @controllers[controller_param] =
- ActiveSupport::Dependencies.reference(controller_name)
+ @api_resources = true
+
+ send(:constraints, Raisin::Routing::VersionConstraint.new(version, is_default)) do
+ send(:scope, module: version) do
+ yield
end
- controller.get(controller_name)
- rescue NameError
- controller_reference_without_api(controller_param)
end
+ ensure
+ @api_resources = nil
+ end
- alias_method_chain :controller_reference, :api
+ def resources(*resources, &block)
+ if @api_resources
+ options = resources.extract_options!
+ options[:except] ||= []
+ options[:except].concat([:new, :edit])
+ super(*resources, options)
+ else
+ super
+ end
end
+
end
end
\ No newline at end of file