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



53
54
55
56
# File 'app/controllers/tuttle/rails_controller.rb', line 53

def assets
  @sprockets = Rails.application.assets
  @engines = Sprockets::VERSION >= '3' ?  @sprockets.instance_variable_get(:@config)[:engines] : @sprockets.instance_variable_get(:@engines)
end

#cacheObject



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

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



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

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

#helpersObject



49
50
51
# File 'app/controllers/tuttle/rails_controller.rb', line 49

def helpers
  @helpers = ::ApplicationController.send(:modules_for_helpers,[:all])
end

#indexObject



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

def index
  Rails::Generators.lookup! if Rails::Generators.subclasses.empty?
end

#inflectorsObject



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

def inflectors
  @test_word = params[:test_word] || ''

  @plurals = ActiveSupport::Inflector.inflections.plurals
  @singulars = ActiveSupport::Inflector.inflections.singulars
  @uncountables = ActiveSupport::Inflector.inflections.uncountables
  @humans = ActiveSupport::Inflector.inflections.humans
  @acronyms = ActiveSupport::Inflector.inflections.acronyms
end

#instrumentationObject



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

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

#modelsObject



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

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

#routesObject



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

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



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/tuttle/rails_controller.rb', line 31

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