Sha256: 1c428977ff689ac27d861dc54d1597ff7471bae509400116aacc1c5db1889881

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

module BetterRailsDebugger::Parser::Ruby
  class Extension
    @@classes = Hash.new(ActiveSupport::HashWithIndifferentAccess.new)
    # Define the position of the extension. The position define when should be executed, if for example we have Ext1 and
    # Ext2, with position 2 and 1, then Ext2 it's going to be executed before Ext1. This is useful for an extension that
    # depends of another one
    def self.position(position)
      # TODO: Allow to set position before another extension of after that one
      raise ArgumentError.new "Expected Integer or Float" unless position.kind_of? Integer or position.kind_of? Float
      @@classes[self.class][:position] = position
    end

    # Define the name of the extension.
    def self.name(extension_name)
      raise ArgumentError.new "Argument must define to_s method" unless extension_name.respond_to? :to_s
      @@classes[self.class][:name] = extension_name.to_s
    end

    def self.config_for(klass)
      @@classes[klass]
    end

    def self.sorted_extensions
      ::BetterRailsDebugger::Parser::Ruby::Extension.descendants.sort_by do |klass|
        config = config_for klass
        # Classes without position goes at bottom
        config[:position] || Float::INFINITY
      end
    end

    def initialize(processor)
      @processor = processor
    end

    def setup

    end

    def run()
      raise ScriptError.new "Please, define run method"
    end

    private

    def processor
      @processor
    end
  end
end
require_relative 'basic_extensions/context_definer'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
better_rails_debugger-0.2.1 lib/better_rails_debugger/parser/ruby/extension.rb
better_rails_debugger-0.2.0 lib/better_rails_debugger/parser/ruby/extension.rb
better_rails_debugger-0.1.1 lib/better_rails_debugger/parser/ruby/extension.rb