Class: Tuttle::RailsController

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

Instance Method Summary collapse

Instance Method Details

#assetsObject



67
68
69
70
71
# File 'app/controllers/tuttle/rails_controller.rb', line 67

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

#cacheObject



89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/tuttle/rails_controller.rb', line 89

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

#controllersObject



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

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



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

def database
  @conn = ActiveRecord::Base.connection
  @data_sources = @conn.respond_to?(:data_sources) ? @conn.data_sources : @conn.tables
end

#enginesObject



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

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

#generatorsObject



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

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

#helpersObject



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

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
10
# File 'app/controllers/tuttle/rails_controller.rb', line 8

def index
  @config_options = Tuttle::ConfigurationRegistry.data.to_a.sort_by!(&:first)
end

#instrumentationObject



84
85
86
87
# File 'app/controllers/tuttle/rails_controller.rb', line 84

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

#modelsObject



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

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

#routesObject



73
74
75
76
77
78
79
80
81
82
# File 'app/controllers/tuttle/rails_controller.rb', line 73

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_cacheObject



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

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