Sha256: 44b3b54bd783588f5718f6543fb606d506f90f9373df734dc38a4275b137bf58

Contents?: true

Size: 777 Bytes

Versions: 2

Compression:

Stored size: 777 Bytes

Contents

require 'simplabs/excellent/checks/name_check'

module Simplabs

  module Excellent

    module Checks

      # Checks a class name to make sure it matches the specified pattern.
      # 
      # Keeping to a consistent naming convention makes your code easier to read.
      class ClassNameCheck < NameCheck

        DEFAULT_PATTERN = /^[A-Z]{1}[a-zA-Z0-9]*$/
      
        def initialize(options = {})
          pattern = options[:pattern] || DEFAULT_PATTERN
          super([:class], pattern)
        end
      
        def find_name(node)
          node[1].class == Symbol ? node[1] : node[1].last
        end

        protected

          def error_args(node)
            ['Bad class name {{class}}.', { :class => node[1] }]
          end

      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simplabs-excellent-1.0.0 lib/simplabs/excellent/checks/class_name_check.rb
simplabs-excellent-1.0.1 lib/simplabs/excellent/checks/class_name_check.rb