Sha256: 775c9670069d37dd25ebf348be8f5bc95669deccf68fe267a474f341b40cf6bf

Contents?: true

Size: 990 Bytes

Versions: 19

Compression:

Stored size: 990 Bytes

Contents

module Simplabs

  module Excellent

    module Parsing

      class ResbodyContext < SexpContext #:nodoc:

        STATEMENT_NODES = [:fcall, :return, :attrasgn, :vcall, :call, :str, :lit, :hash, :false, :true, :nil]

        def initialize(exp, parent)
          super
          @contains_statements = contains_statements?
        end

        def has_statements?
          @contains_statements
        end

        private

          def contains_statements?(exp = @exp)
            return true if STATEMENT_NODES.include?(exp.node_type)
            return true if assigning_other_than_exception_to_local_variable?(exp)
            return true if (exp[1][0] == :array && exp[2][0] == :array rescue false)
            return true if exp.children.any? { |child| contains_statements?(child) }
          end

          def assigning_other_than_exception_to_local_variable?(exp)
            exp.node_type == :lasgn && exp[2].to_a != [:gvar, :$!]
          end

      end

    end

  end

end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
simplabs-excellent-1.2.1 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.2.2 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.3.0 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.3.1 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.4.0 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.4.1 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.4.2 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.5.0 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.5.1 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.5.2 lib/simplabs/excellent/parsing/resbody_context.rb
simplabs-excellent-1.5.3 lib/simplabs/excellent/parsing/resbody_context.rb
excellent-2.1.1 lib/simplabs/excellent/parsing/resbody_context.rb
excellent-2.1.0 lib/simplabs/excellent/parsing/resbody_context.rb
excellent-2.0.1 lib/simplabs/excellent/parsing/resbody_context.rb
excellent-2.0.0 lib/simplabs/excellent/parsing/resbody_context.rb
excellent-1.7.1 lib/simplabs/excellent/parsing/resbody_context.rb
excellent-1.7.0 lib/simplabs/excellent/parsing/resbody_context.rb
excellent-1.6.0 lib/simplabs/excellent/parsing/resbody_context.rb
excellent-1.5.4 lib/simplabs/excellent/parsing/resbody_context.rb