Sha256: ce036bbc5ca9c0c2d28fbfe2ea4d5f790f148e6f2b0151cba480d8e23afd295f

Contents?: true

Size: 1.42 KB

Versions: 38

Compression:

Stored size: 1.42 KB

Contents

require "watir-webdriver/core_ext/string"

module YARD
  module Handlers
    module Watir
      #
      # @private
      # 
      
      class AttributesHandler < YARD::Handlers::Ruby::Base
        handles method_call(:attributes)

        TYPES = {
          :string => "String",
          :bool => "Boolean",
          :int => "Integer"
        }

        def process
          attributes = try_eval

          if attributes.nil?
            p :ignoring => statement.source, :in => namespace.to_s
            return
          end

          TYPES.each do |type, return_type|
            if attributes.member? type
              create_attributes attributes[type], return_type
            end
          end
        end

        private

        def create_attributes(names, return_type)
          names.each do |attribute_name|
            p :adding => "#{namespace}##{attribute_name}"
            attribute_name = "#{attribute_name}?".to_sym if return_type == "Boolean"
            register MethodObject.new(namespace, attribute_name, scope) do |o|
              o.visibility = :public
              o.explicit   = false
              o.docstring.add_tag YARD::Tags::Tag.new(:return, "", return_type)
            end
          end
        end

        def try_eval
          eval "{#{statement.parameters.source}}"
        rescue SyntaxError, StandardError
          nil
        end

      end # AttributesHandler
    end # Watir
  end # Handlers
end

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
watir-webdriver-0.2.1 lib/yard/handlers/watir.rb
watir-webdriver-0.2.0 lib/yard/handlers/watir.rb
watir-webdriver-0.2.0.dev2 lib/yard/handlers/watir.rb
watir-webdriver-0.2.0.dev lib/yard/handlers/watir.rb
watir-webdriver-0.1.9 lib/yard/handlers/watir.rb
watir-webdriver-0.1.8 lib/yard/handlers/watir.rb
watir-webdriver-0.1.7 lib/yard/handlers/watir.rb
watir-webdriver-0.1.6 lib/yard/handlers/watir.rb
watir-webdriver-0.1.5 lib/yard/handlers/watir.rb
watir-webdriver-0.1.4 lib/yard/handlers/watir.rb
watir-webdriver-0.1.3 lib/yard/handlers/watir.rb
watir-webdriver-0.1.2 lib/yard/handlers/watir.rb
ayanko-watir-webdriver-0.1.1.1 lib/yard/handlers/watir.rb
watir-webdriver-0.1.1 lib/yard/handlers/watir.rb
watir-webdriver-0.1.0 lib/yard/handlers/watir.rb
watir-webdriver-0.0.9 lib/yard/handlers/watir.rb
watir-webdriver-0.0.8 lib/yard/handlers/watir.rb
watir-webdriver-0.0.7 lib/yard/handlers/watir.rb