Class Footnotes::Notes::ControllerNote
In: lib/rails-footnotes/notes/controller_note.rb
Parent: AbstractNote

Methods

Public Class methods

[Source]

# File lib/rails-footnotes/notes/controller_note.rb, line 6
      def initialize(controller)
        @controller = controller
      end

Public Instance methods

[Source]

# File lib/rails-footnotes/notes/controller_note.rb, line 14
      def link
        escape(Footnotes::Filter.prefix(controller_filename, controller_line_number + 1, 3))
      end

[Source]

# File lib/rails-footnotes/notes/controller_note.rb, line 10
      def row
        :edit
      end

[Source]

# File lib/rails-footnotes/notes/controller_note.rb, line 18
      def valid?
        prefix?
      end

Protected Instance methods

[Source]

# File lib/rails-footnotes/notes/controller_note.rb, line 33
        def action_index
          (controller_text =~ /def\s+#{@controller.action_name}[\s\(]/)
        end
Some controller classes come with the Controller:module and some don‘t

(anyone know why? — Duane)

[Source]

# File lib/rails-footnotes/notes/controller_note.rb, line 25
        def controller_filename
          File.join(File.expand_path(RAILS_ROOT), 'app', 'controllers', "#{@controller.class.to_s.underscore}.rb").sub('/controllers/controllers/', '/controllers/')
        end

[Source]

# File lib/rails-footnotes/notes/controller_note.rb, line 37
        def controller_line_number
          lines_from_index(controller_text, action_index) || 0
        end

[Source]

# File lib/rails-footnotes/notes/controller_note.rb, line 29
        def controller_text
          @controller_text ||= IO.read(controller_filename)
        end

[Source]

# File lib/rails-footnotes/notes/controller_note.rb, line 41
        def lines_from_index(string, index)
          return nil if string.blank? || index.blank?

          lines = string.to_a
          running_length = 0
          lines.each_with_index do |line, i|
            running_length += line.length
            if running_length > index
              return i
            end
          end
        end

[Validate]