Sha256: ad351d1d6a272ba27e8d46256ed969ec3fe9ee7609fb8dca328f2c85e25e3539

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'yard-dm/extensions'

module YARD
  module DM
    class BelongsToHandler < YARD::Handlers::Ruby::Base

      include Extensions

      handles method_call(:belongs_to)

      def process
        nobj = effected_namespace
        mscope = scope
        name = statement.parameters[0].last

        if name.type == :symbol
          name = name.source[1..-1]

          register MethodObject.new(nobj, name, :class) do |o|
            o.visibility = :public
            o.source = statement.source
            o.signature = "def self.#{name}"
            o.parameters = [['repository', 'nil']]
          end

          register MethodObject.new(nobj, name, mscope) do |o|
            o.visibility = :public
            o.source = statement.source
            o.signature = "def #{name}"
          end

          register MethodObject.new(nobj, "#{name}=", mscope) do |o|
            o.visibility = :public
            o.source = statement.source
            o.signature = "def #{name}=(resource)"
            o.parameters = [['resource', nil]]
          end
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
yard-dm-0.1.1 lib/yard-dm/belongs_to_handler.rb
yard-dm-0.1.0 lib/yard-dm/belongs_to_handler.rb