Sha256: 9b932d9de0bc716a72ac8a6b260c1152ea51589db87e55e46cfbf05054a5dcce

Contents?: true

Size: 1.89 KB

Versions: 6

Compression:

Stored size: 1.89 KB

Contents

module Inch
  module Language
    module Elixir
      module CodeObject
        # Proxy class for method parameters
        class FunctionParameterObject
          def initialize(attributes)
            @attributes = attributes
          end

          def [](key)
            @attributes[key]
          end

          IGNORE_NAME_PREFIX = "_"
          BAD_NAME_EXCEPTIONS = %w(id)
          BAD_NAME_THRESHOLD = 3

          # @return [Boolean] +true+ if the name of the parameter is
          #   uncommunicative
          def bad_name?
            return false if BAD_NAME_EXCEPTIONS.include?(name)
            name.size < BAD_NAME_THRESHOLD || name =~ /[0-9]$/
          end

          # @return [Boolean] +true+ if the parameter is a block
          def block?
            self[:block?]
          end

          # @return [Boolean] +true+ if an additional description given?
          def described?
            self[:described?] || ignore?
          end

          # @return [Boolean] +true+ if the parameter is mentioned in the docs
          def mentioned?
            self[:mentioned?] || ignore?
          end

          def name
            self[:name]
          end
          alias_method :fullname, :name

          # @return [Boolean] +true+ if the parameter is a splat argument
          def splat?
            self[:splat?]
          end

          # @return [Boolean] +true+ if the type of the parameter is defined
          def typed?
            self[:typed?] || ignore?
          end

          def unnamed?
            name == ''
          end

          # @return [Boolean] +true+ if the parameter is mentioned in the docs,
          #   but not present in the method's signature
          def wrongly_mentioned?
            self[:wrongly_mentioned?]
          end

          private

          def ignore?
            name.start_with?(IGNORE_NAME_PREFIX)
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
inch-0.9.0.rc1 lib/inch/language/elixir/code_object/function_parameter_object.rb
inch-0.8.0 lib/inch/language/elixir/code_object/function_parameter_object.rb
inch-0.8.0.rc2 lib/inch/language/elixir/code_object/function_parameter_object.rb
inch-0.8.0.rc1 lib/inch/language/elixir/code_object/function_parameter_object.rb
inch-0.7.1 lib/inch/language/elixir/code_object/function_parameter_object.rb
inch-0.7.0 lib/inch/language/elixir/code_object/function_parameter_object.rb