Class: Tuttle::RailsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tuttle/rails_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#check_reload_status

Instance Method Details

#assetsObject



65
66
67
68
# File 'app/controllers/tuttle/rails_controller.rb', line 65

def assets
  @sprockets = Rails.application.assets
  # TODO: revisit detection of "engines" which are classified as processors, transformers, etc.
end

#cacheObject



82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/tuttle/rails_controller.rb', line 82

def 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 = Rails.cache
  @cache_events = Tuttle::Instrumenter.events.select {|e| /cache_(read|write)\.active_support/ =~ e.name }
  @tuttle_cache_events = Tuttle::Instrumenter.cache_events
end

#controllersObject



11
12
13
14
15
16
17
18
19
# File 'app/controllers/tuttle/rails_controller.rb', line 11

def controllers
  # TODO: Both ObjectSpace and .descendants approaches have issues with class reloading during development
  # 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! {|controller| controller <= Tuttle::ApplicationController || controller.abstract?}
  @controllers.sort_by!(&:name)
end

#databaseObject



35
36
37
# File 'app/controllers/tuttle/rails_controller.rb', line 35

def database
  @conn = ActiveRecord::Base.connection
end

#enginesObject



21
22
23
# File 'app/controllers/tuttle/rails_controller.rb', line 21

def engines
  @engines = Rails::Engine.subclasses.map(&:instance)
end

#generatorsObject



25
26
27
28
# File 'app/controllers/tuttle/rails_controller.rb', line 25

def generators
  Rails::Generators.lookup! if 'true' == params[:load_all_generators]
  @generators = Rails::Generators.subclasses.group_by(&:base_name)
end

#helpersObject



57
58
59
60
61
62
63
# File 'app/controllers/tuttle/rails_controller.rb', line 57

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

#indexObject



8
9
# File 'app/controllers/tuttle/rails_controller.rb', line 8

def index
end

#instrumentationObject



77
78
79
80
# File 'app/controllers/tuttle/rails_controller.rb', line 77

def instrumentation
  @events = Tuttle::Instrumenter.events
  @event_counts = Tuttle::Instrumenter.event_counts
end

#modelsObject



30
31
32
33
# File 'app/controllers/tuttle/rails_controller.rb', line 30

def models
  @models = ActiveRecord::Base.descendants
  @models.sort_by!(&:name)
end

#routesObject



70
71
72
73
74
75
# File 'app/controllers/tuttle/rails_controller.rb', line 70

def routes
  @routes = Rails.application.routes.routes.collect do |route|
    Tuttle::Presenters::ActionDispatch::Routing::RouteWrapper.new(route)
  end
  # TODO: include engine-mounted routes
end

#schema_cacheObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/tuttle/rails_controller.rb', line 39

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