yard-mongoid 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in yard-mongoid.gemspec
4
+ gemspec
5
+
6
+ gem 'yard', '~> 0.6.1'
data/Gemfile.lock ADDED
@@ -0,0 +1,16 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ yard-mongoid (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ yard (0.6.1)
10
+
11
+ PLATFORMS
12
+ ruby
13
+
14
+ DEPENDENCIES
15
+ yard (~> 0.6.1)
16
+ yard-mongoid!
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,20 @@
1
+ module YARD
2
+ module Mongoid
3
+ module Extensions
4
+ protected
5
+ def effected_namespace
6
+ if statement.type == :command_call
7
+ context = statement.jump(:var_ref)
8
+
9
+ unless context.source == 'self'
10
+ return ensure_loaded!(
11
+ Registry.resolve(namespace, context.source)
12
+ )
13
+ end
14
+ end
15
+
16
+ return namespace
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ module YARD
2
+ module Mongoid
3
+ class FieldHandler < YARD::Handlers::Ruby::AttributeHandler
4
+ include Extensions
5
+ include Helpers
6
+
7
+ handles method_call(:field)
8
+
9
+ def process
10
+ nobj = effected_namespace
11
+ mscope = scope
12
+ name = statement.parameters[0].last
13
+
14
+ if name.type == :symbol
15
+ name = name.source[1..-1]
16
+
17
+ #register_field_getter(nobj, name, mscope)
18
+ register_field_setter(nobj, name, mscope)
19
+ register_field_presence(nobj, name, mscope)
20
+ register_field_change(nobj, name, mscope)
21
+ register_field_changed(nobj, name, mscope)
22
+ register_field_was(nobj, name, mscope)
23
+ register_field_reset(nobj, name, mscope)
24
+ super
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,103 @@
1
+ module YARD
2
+ module Mongoid
3
+ module Helpers
4
+ def register_new_method_object(namespace, name, scope = :instance, &block)
5
+ register self.class.const_get(:MethodObject).new(namespace, name, scope, &block)
6
+ end
7
+
8
+ # Creates and registers a new +name+ method in +namespace+
9
+ # with an instance or class +scope+
10
+ # @param [NamespaceObject] namespace the namespace
11
+ # @param [String, Symbol] name the method name
12
+ # @param [Symbol] scope +:instance+ or +:class+
13
+ def register_field_getter(namespace, name, scope = :instance)
14
+ register_new_method_object(namespace, name, scope) do |o|
15
+ o.visibility = :public
16
+ o.source = statement.source
17
+ o.signature = "def #{name}"
18
+ o.docstring = "Returns the value of attribute #{name}"
19
+ end
20
+ end
21
+
22
+ # Creates and registers a new +name+= method in +namespace+
23
+ # with an instance or class +scope+
24
+ # @param [NamespaceObject] namespace the namespace
25
+ # @param [String, Symbol] name the method name
26
+ # @param [Symbol] scope +:instance+ or +:class+
27
+ def register_field_setter(namespace, name, scope = :instance)
28
+ register_new_method_object(namespace, "#{name}=", scope) do |o|
29
+ o.visibility = :public
30
+ o.source = statement.source
31
+ o.signature = "def #{name}=(value)"
32
+ o.parameters = [['value', nil]]
33
+ o.docstring = "Sets the attribute #{name}\n@param value the value to set the attribute #{name} to."
34
+ end
35
+ end
36
+
37
+ # Creates and registers a new +name+? method in +namespace+
38
+ # with an instance or class +scope+
39
+ # @param [NamespaceObject] namespace the namespace
40
+ # @param [String, Symbol] name the method name
41
+ # @param [Symbol] scope +:instance+ or +:class+
42
+ def register_field_presence(namespace, name, scope = :instance)
43
+ register_new_method_object(namespace, "#{name}?", scope) do |o|
44
+ o.visibility = :public
45
+ o.source = statement.source
46
+ o.signature = "def #{name}?"
47
+ end
48
+ end
49
+
50
+ # Creates and registers a new +name+_change method in +namespace+
51
+ # with an instance or class +scope+
52
+ # @param [NamespaceObject] namespace the namespace
53
+ # @param [String, Symbol] name the method name
54
+ # @param [Symbol] scope +:instance+ or +:class+
55
+ def register_field_change(namespace, name, scope = :instance)
56
+ register_new_method_object(namespace, "#{name}_change", scope) do |o|
57
+ o.visibility = :public
58
+ o.source = statement.source
59
+ o.signature = "def #{name}_change"
60
+ end
61
+ end
62
+
63
+ # Creates and registers a new +name+_changed? method in +namespace+
64
+ # with an instance or class +scope+
65
+ # @param [NamespaceObject] namespace the namespace
66
+ # @param [String, Symbol] name the method name
67
+ # @param [Symbol] scope +:instance+ or +:class+
68
+ def register_field_changed(namespace, name, scope = :instance)
69
+ register_new_method_object(namespace, "#{name}_changed?", scope) do |o|
70
+ o.visibility = :public
71
+ o.source = statement.source
72
+ o.signature = "def #{name}_changed?"
73
+ end
74
+ end
75
+
76
+ # Creates and registers a new +name+_was method in +namespace+
77
+ # with an instance or class +scope+
78
+ # @param [NamespaceObject] namespace the namespace
79
+ # @param [String, Symbol] name the method name
80
+ # @param [Symbol] scope +:instance+ or +:class+
81
+ def register_field_was(namespace, name, scope = :instance)
82
+ register_new_method_object(namespace, "#{name}_was", scope) do |o|
83
+ o.visibility = :public
84
+ o.source = statement.source
85
+ o.signature = "def #{name}_was"
86
+ end
87
+ end
88
+
89
+ # Creates and registers a new reset_+name+! method in +namespace+
90
+ # with an instance or class +scope+
91
+ # @param [NamespaceObject] namespace the namespace
92
+ # @param [String, Symbol] name the method name
93
+ # @param [Symbol] scope +:instance+ or +:class+
94
+ def register_field_reset(namespace, name, scope = :instance)
95
+ register_new_method_object(namespace, "reset_#{name}!", scope) do |o|
96
+ o.visibility = :public
97
+ o.source = statement.source
98
+ o.signature = "def reset_#{name}!"
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,26 @@
1
+ module YARD
2
+ module Mongoid
3
+ module Legacy
4
+ class FieldHandler < YARD::Handlers::Ruby::Legacy::AttributeHandler
5
+ include Helpers
6
+
7
+ handles /\Afield\s+:/
8
+
9
+ def process
10
+ nobj = namespace
11
+ mscope = scope
12
+ name = statement.tokens[2,1].to_s[1..-1]
13
+
14
+ #register_field_getter(nobj, name, mscope)
15
+ register_field_setter(nobj, name, mscope)
16
+ register_field_presence(nobj, name, mscope)
17
+ register_field_change(nobj, name, mscope)
18
+ register_field_changed(nobj, name, mscope)
19
+ register_field_was(nobj, name, mscope)
20
+ register_field_reset(nobj, name, mscope)
21
+ super
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Yard
2
+ module Mongoid
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module YARD
2
+ module Mongoid
3
+ autoload :VERSION, 'yard/mongoid/version'
4
+ autoload :Extensions, 'yard/mongoid/extensions'
5
+ autoload :Helpers, 'yard/mongoid/helpers'
6
+ end
7
+ end
8
+
9
+ require 'yard/mongoid/field_handler'
10
+ require 'yard/mongoid/legacy/field_handler'
@@ -0,0 +1 @@
1
+ require 'yard/mongoid'
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "yard/mongoid/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "yard-mongoid"
7
+ s.version = Yard::Mongoid::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Alexander Semyonov"]
10
+ s.email = ["al@semyonov.us"]
11
+ s.homepage = "http://rubygems.org/gems/yard-mongoid"
12
+ s.summary = %q{A Yard plugin for parsing Mongoid model syntax.}
13
+ s.description = %q{Once yard-mongoid is installed, YARD will automatically load the plugin when ever the `yard doc` utility is ran on a project.}
14
+
15
+ s.rubyforge_project = "yard-mongoid"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-mongoid
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Alexander Semyonov
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-08 00:00:00 +04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Once yard-mongoid is installed, YARD will automatically load the plugin when ever the `yard doc` utility is ran on a project.
23
+ email:
24
+ - al@semyonov.us
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Gemfile.lock
35
+ - Rakefile
36
+ - lib/yard-mongoid.rb
37
+ - lib/yard/mongoid.rb
38
+ - lib/yard/mongoid/extensions.rb
39
+ - lib/yard/mongoid/field_handler.rb
40
+ - lib/yard/mongoid/helpers.rb
41
+ - lib/yard/mongoid/legacy/field_handler.rb
42
+ - lib/yard/mongoid/version.rb
43
+ - yard-mongoid.gemspec
44
+ has_rdoc: true
45
+ homepage: http://rubygems.org/gems/yard-mongoid
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ hash: 3
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ requirements: []
72
+
73
+ rubyforge_project: yard-mongoid
74
+ rubygems_version: 1.3.7
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: A Yard plugin for parsing Mongoid model syntax.
78
+ test_files: []
79
+