Class: Tuttle::RailsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Tuttle::RailsController
- Defined in:
- app/controllers/tuttle/rails_controller.rb
Instance Method Summary collapse
- #assets ⇒ Object
- #cache ⇒ Object
- #controllers ⇒ Object
- #database ⇒ Object
- #engines ⇒ Object
- #generators ⇒ Object
- #helpers ⇒ Object
- #index ⇒ Object
- #instrumentation ⇒ Object
- #models ⇒ Object
- #routes ⇒ Object
- #schema_cache ⇒ Object
Instance Method Details
#assets ⇒ Object
81 82 83 84 85 |
# File 'app/controllers/tuttle/rails_controller.rb', line 81 def assets @sprockets_env = Rails.application.assets @assets_config = Rails.application.config.assets # TODO: revisit detection of "engines" which are classified as processors, transformers, etc. end |
#cache ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/tuttle/rails_controller.rb', line 103 def cache @cache = Rails.cache # TODO: make cache instrumentation controllable - this will automatically turn in on in Rails < 4.2 # Instrumentation is always on in Rails 4.2+ # if Rails::VERSION::STRING =~ /^4\.1\./ && !ActiveSupport::Cache::Store.instrument # ActiveSupport::Cache::Store.instrument = true # end # @cache_events = Tuttle::Instrumenter.events.select {|e| /cache_(read|write)\.active_support/ =~ e.name } # @tuttle_cache_events = Tuttle::Instrumenter.cache_events end |
#controllers ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/tuttle/rails_controller.rb', line 15 def controllers @routes = Rails.application.routes.routes.collect do |route| Tuttle::Presenters::ActionDispatch::Routing::RouteWrapper.new(route) end # It seems likely that .descendants will work best when Tuttle and Rails classes are not modified # but both approaches also require eager_load to be true # @controllers = ObjectSpace.each_object(::Class).select {|klass| klass < ActionController::Base } @controllers = ActionController::Base.descendants @controllers.reject! do |controller| controller.abstract? || controller <= Tuttle::ApplicationController end # Rails 5.1 introduced Rails::ApplicationController which really should be abstract if defined?(Rails::ApplicationController) @controllers.reject! { |controller| controller == Rails::ApplicationController } end @controllers.sort_by!(&:name) end |
#database ⇒ Object
50 51 52 53 |
# File 'app/controllers/tuttle/rails_controller.rb', line 50 def database @conn = ActiveRecord::Base.connection @data_sources = @conn.respond_to?(:data_sources) ? @conn.data_sources : @conn.tables end |
#engines ⇒ Object
36 37 38 |
# File 'app/controllers/tuttle/rails_controller.rb', line 36 def engines @engines = Rails::Engine.subclasses.map(&:instance) end |
#generators ⇒ Object
40 41 42 43 |
# File 'app/controllers/tuttle/rails_controller.rb', line 40 def generators Rails::Generators.lookup! if params[:load_all_generators] == 'true' @generators = Rails::Generators.subclasses.group_by(&:base_name) end |
#helpers ⇒ Object
73 74 75 76 77 78 79 |
# File 'app/controllers/tuttle/rails_controller.rb', line 73 def helpers # TODO: Rails.application.helpers.instance_methods # helper_symbol = Rails.application.helpers.instance_methods.first # Rails.application.helpers.instance_method(helper_symbol).owner # Rails.application.helpers.instance_method(helper_symbol).parameters @helpers = ::ApplicationController.send(:modules_for_helpers, [:all]) end |
#index ⇒ Object
11 12 13 |
# File 'app/controllers/tuttle/rails_controller.rb', line 11 def index @config_options = Tuttle::ConfigurationRegistry.data.to_a.sort_by!(&:first) end |
#instrumentation ⇒ Object
98 99 100 101 |
# File 'app/controllers/tuttle/rails_controller.rb', line 98 def instrumentation @events = Tuttle::Instrumenter.events @event_counts = Tuttle::Instrumenter.event_counts end |
#models ⇒ Object
45 46 47 48 |
# File 'app/controllers/tuttle/rails_controller.rb', line 45 def models @models = ActiveRecord::Base.descendants.reject { |model| model.abstract_class? || !model.table_exists? } @models.sort_by!(&:name) end |
#routes ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/tuttle/rails_controller.rb', line 87 def routes @routes = Rails.application.routes.routes.collect do |route| Tuttle::Presenters::ActionDispatch::Routing::RouteWrapper.new(route) end if params[:recognize_path] @path_to_recognize = params[:recognize_path] @recognized_paths = recognize_paths(params[:recognize_path]) end # TODO: include engine-mounted routes end |
#schema_cache ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/tuttle/rails_controller.rb', line 55 def schema_cache @schema_cache_filename = File.join(Rails.application.config.paths['db'].first, 'schema_cache.dump') if File.file?(@schema_cache_filename) @schema_cache = Marshal.load(File.binread(@schema_cache_filename)) end # TODO: wrap in a facade and handle unloaded file @schema_cache ||= ActiveRecord::ConnectionAdapters::SchemaCache.new(nil) # TODO: consider allowing a schema cache clear! # TODO: consider allowing a schema_cache.dump reload # if @schema_cache.version && params[:reload_schema_cache_dump] # ActiveRecord::Base.connection.schema_cache = @schema_cache.dup # end @connection_schema_cache = ActiveRecord::Base.connection.schema_cache # Note: Rails 5 should also support ActiveRecord::Base.connection_pool.respond_to?(:schema_cache) end |