Sha256: 93409df565005531eea8ef5e2e1bf7eff240c01b0a5443565ddee13df693f9b6

Contents?: true

Size: 1.82 KB

Versions: 9

Compression:

Stored size: 1.82 KB

Contents

module Footnotes
  module Notes
    class AssignsNote < AbstractNote
      @@ignored_assigns = [
                            :@real_format,
                            :@before_filter_chain_aborted,
                            :@performed_redirect,
                            :@performed_render,
                            :@_params,
                            :@_response,
                            :@url,
                            :@template,
                            :@_request,
                            :@db_rt_before_render,
                            :@db_rt_after_render,
                            :@view_runtime,
                            :@marked_for_same_origin_verification
                          ]
      cattr_accessor :ignored_assigns, :instance_writter => false
      @@ignored_assigns_pattern = /^@_/
      cattr_accessor :ignored_assigns_pattern, :instance_writter => false

      def initialize(controller)
        @controller = controller
      end

      def title
        "Assigns (#{assigns.size})"
      end

      def valid?
        assigns.present?
      end

      def content
        mount_table(to_table, :summary => "Debug information for #{title}")
      end

      protected
        def to_table
          table = assigns.inject([]) do |rr, var|
            class_name = assigned_value(var).class.name
            var_name = var.to_s
            rr << ["<strong>#{var.to_s}</strong>" + "<br /><em>#{class_name}</em>", escape(assigned_value(var).inspect)]
          end

          table.unshift(['Name', 'Value'])
        end

        def assigns
          @assigns ||= @controller.instance_variables.map {|v| v.to_sym}.select {|v| v.to_s !~ ignored_assigns_pattern } - ignored_assigns
        end

        def assigned_value(key)
          @controller.instance_variable_get(key)
        end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rails-footnotes-4.1.8 lib/rails-footnotes/notes/assigns_note.rb
rails-footnotes-4.1.7 lib/rails-footnotes/notes/assigns_note.rb
rails-footnotes-4.1.6 lib/rails-footnotes/notes/assigns_note.rb
rails-footnotes-4.1.5 lib/rails-footnotes/notes/assigns_note.rb
rails-footnotes-4.1.4 lib/rails-footnotes/notes/assigns_note.rb
rails-footnotes-4.1.3 lib/rails-footnotes/notes/assigns_note.rb
rails-footnotes-4.1.2 lib/rails-footnotes/notes/assigns_note.rb
rails-footnotes-4.1.1 lib/rails-footnotes/notes/assigns_note.rb
rails-footnotes-4.1.0 lib/rails-footnotes/notes/assigns_note.rb