Skip to content

Commit

Permalink
Added FieldHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Semyonov committed Oct 8, 2010
1 parent 3c1f028 commit 2f88c4e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/yard-mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
module Yard
module Mongoid
# Your code goes here...
end
end
require 'yard/mongoid'
8 changes: 8 additions & 0 deletions lib/yard/mongoid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module YARD
module Mongoid
autoload :VERSION, 'lib/mongoid/version'
autoload :Extensions, 'lib/mongoid/extensions'
end
end

require 'lib/mongoid/field_handler'
21 changes: 21 additions & 0 deletions lib/yard/mongoid/extensions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module YARD
module Mongoid
module Extensions
protected
def effected_namespace
if statement.type == :command_call
context = statement.jump(:var_ref)

unless context.source == 'self'
return ensure_loaded!(
Registry.resolve(namespace, context.source)
)
end
end

return namespace
end
end

end
end
44 changes: 44 additions & 0 deletions lib/yard/mongoid/field_handler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module YARD
module Mongoid
class FieldHandler < YARD::Handlers::Ruby::Base
include Extensions

handles method_call(:field)

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, 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}=(value)"
o.parameters = [['value', 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}?"
end
end
end
end
end
end
File renamed without changes.

0 comments on commit 2f88c4e

Please sign in to comment.