Sha256: 4b7733030f3e72af3deec939fba314acf1dbf3e5c4e3de84c1b0eb74109dd654

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

module Simplabs

  module Excellent

    module Parsing

      class CallContext < SexpContext #:nodoc:

        include Comparable

        attr_reader :receiver
        attr_reader :method

        def initialize(exp, parent)
          super
          @receiver  = exp[1].is_a?(Sexp) ? (exp[1][1].nil? ? exp[1][2].to_s : exp[1][1].to_s) : nil
          @method    = exp[2].to_s
          @full_name = [@receiver, @method].compact.join('.')
          record_validation
          record_call
        end

        def <=>(other)
          @full_name <=> other.full_name
        end
        alias :eql? :'<=>'

        def hash
          @full_name.hash
        end

        private

          def record_call
            parent = @parent
            parent = parent.parent until parent.nil? || parent.is_a?(MethodContext) || parent.is_a?(BlockContext) || parent.is_a?(SingletonMethodContext)
            parent.record_call_to(self) if parent
          end

          def record_validation
            if ClassContext::VALIDATIONS.include?(@method) && @parent && @parent.is_a?(ClassContext) && @parent.active_record_model?
              @parent.validations << @method
            end
          end

      end

    end

  end

end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
simplabs-excellent-1.5.0 lib/simplabs/excellent/parsing/call_context.rb
simplabs-excellent-1.5.1 lib/simplabs/excellent/parsing/call_context.rb
simplabs-excellent-1.5.2 lib/simplabs/excellent/parsing/call_context.rb
simplabs-excellent-1.5.3 lib/simplabs/excellent/parsing/call_context.rb
excellent-1.5.4 lib/simplabs/excellent/parsing/call_context.rb