yard-mongoid 0.0.2 → 0.0.3.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +5 -2
- data/MIT-LICENSE +20 -0
- data/lib/yard/mongoid.rb +2 -3
- data/lib/yard/mongoid/extensions.rb +1 -1
- data/lib/yard/mongoid/field_handler.rb +47 -10
- data/lib/yard/mongoid/helpers.rb +13 -2
- data/lib/yard/mongoid/legacy/field_handler.rb +11 -11
- data/lib/yard/mongoid/version.rb +1 -1
- data/yard-mongoid.gemspec +10 -8
- metadata +41 -45
- data/Gemfile.lock +0 -16
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
© 2011-2013 Alexander Semyonov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/yard/mongoid.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'yard/mongoid/extensions'
|
2
|
+
require 'yard/mongoid/helpers'
|
3
|
+
|
1
4
|
module YARD
|
2
5
|
module Mongoid
|
3
6
|
class FieldHandler < YARD::Handlers::Ruby::AttributeHandler
|
@@ -7,23 +10,57 @@ module YARD
|
|
7
10
|
handles method_call(:field)
|
8
11
|
|
9
12
|
def process
|
10
|
-
|
11
|
-
mscope = scope
|
12
|
-
name = statement.parameters[0].last
|
13
|
+
name = statement.parameters[0].last
|
13
14
|
|
14
15
|
if name.type == :symbol
|
15
16
|
name = name.source[1..-1]
|
16
17
|
|
17
|
-
|
18
|
-
register_field_setter(
|
19
|
-
register_field_presence(
|
20
|
-
register_field_change(
|
21
|
-
register_field_changed(
|
22
|
-
register_field_was(
|
23
|
-
register_field_reset(
|
18
|
+
register_field_getter(effected_namespace, name, scope, class_name, default_value)
|
19
|
+
register_field_setter(effected_namespace, name, scope)
|
20
|
+
register_field_presence(effected_namespace, name, scope)
|
21
|
+
register_field_change(effected_namespace, name, scope)
|
22
|
+
register_field_changed(effected_namespace, name, scope)
|
23
|
+
register_field_was(effected_namespace, name, scope)
|
24
|
+
register_field_reset(effected_namespace, name, scope)
|
24
25
|
super
|
25
26
|
end
|
26
27
|
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def class_name
|
32
|
+
return @class_name if instance_variable_defined?(:@class_name)
|
33
|
+
|
34
|
+
if statement.parameters.size > 2
|
35
|
+
statement.parameters[1].source.split(/,\s*/).each do |key_and_value|
|
36
|
+
if key_and_value =~ hash_args[:type]
|
37
|
+
@class_name = $2
|
38
|
+
break
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
@class_name ||= 'String'
|
43
|
+
end
|
44
|
+
|
45
|
+
def default_value
|
46
|
+
return @default_value if instance_variable_defined?(:@default_value)
|
47
|
+
|
48
|
+
if statement.parameters.size > 2
|
49
|
+
statement.parameters[1].source.split(/,\s*/).each do |key_and_value|
|
50
|
+
if key_and_value =~ /(:default\s*=>|default:)\s*(.+)\s*$/
|
51
|
+
@default_value = $2
|
52
|
+
break
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@default_value ||= nil
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
|
61
|
+
def hash_args
|
62
|
+
@hash_args ||= Hash.new { |hash, key| hash[key] = /(:#{key.to_s}\s*=>|#{key.to_s}:)\s*([A-Z][A-Za-z0-9]*)/ }
|
63
|
+
end
|
27
64
|
end
|
28
65
|
end
|
29
66
|
end
|
data/lib/yard/mongoid/helpers.rb
CHANGED
@@ -10,12 +10,17 @@ module YARD
|
|
10
10
|
# @param [NamespaceObject] namespace the namespace
|
11
11
|
# @param [String, Symbol] name the method name
|
12
12
|
# @param [Symbol] scope +:instance+ or +:class+
|
13
|
-
def register_field_getter(namespace, name, scope = :instance)
|
13
|
+
def register_field_getter(namespace, name, scope = :instance, type = 'Object', default_value = nil)
|
14
14
|
register_new_method_object(namespace, name, scope) do |o|
|
15
|
+
o.group = MONGOID_FIELDS
|
15
16
|
o.visibility = :public
|
16
17
|
o.source = statement.source
|
17
18
|
o.signature = "def #{name}"
|
18
|
-
|
19
|
+
end.tap do |o|
|
20
|
+
docstring = o.docstring.empty? ? "Field #{name}" : o.docstring
|
21
|
+
docstring += "\n@return [#{type}] "
|
22
|
+
docstring += "(defaults to: +#{default_value}+) " if default_value
|
23
|
+
o.docstring = docstring
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
@@ -26,6 +31,7 @@ module YARD
|
|
26
31
|
# @param [Symbol] scope +:instance+ or +:class+
|
27
32
|
def register_field_setter(namespace, name, scope = :instance)
|
28
33
|
register_new_method_object(namespace, "#{name}=", scope) do |o|
|
34
|
+
o.group = MONGOID_FIELDS
|
29
35
|
o.visibility = :public
|
30
36
|
o.source = statement.source
|
31
37
|
o.signature = "def #{name}=(value)"
|
@@ -41,6 +47,7 @@ module YARD
|
|
41
47
|
# @param [Symbol] scope +:instance+ or +:class+
|
42
48
|
def register_field_presence(namespace, name, scope = :instance)
|
43
49
|
register_new_method_object(namespace, "#{name}?", scope) do |o|
|
50
|
+
o.group = MONGOID_FIELDS
|
44
51
|
o.visibility = :public
|
45
52
|
o.source = statement.source
|
46
53
|
o.signature = "def #{name}?"
|
@@ -54,6 +61,7 @@ module YARD
|
|
54
61
|
# @param [Symbol] scope +:instance+ or +:class+
|
55
62
|
def register_field_change(namespace, name, scope = :instance)
|
56
63
|
register_new_method_object(namespace, "#{name}_change", scope) do |o|
|
64
|
+
o.group = MONGOID_FIELDS
|
57
65
|
o.visibility = :public
|
58
66
|
o.source = statement.source
|
59
67
|
o.signature = "def #{name}_change"
|
@@ -67,6 +75,7 @@ module YARD
|
|
67
75
|
# @param [Symbol] scope +:instance+ or +:class+
|
68
76
|
def register_field_changed(namespace, name, scope = :instance)
|
69
77
|
register_new_method_object(namespace, "#{name}_changed?", scope) do |o|
|
78
|
+
o.group = MONGOID_FIELDS
|
70
79
|
o.visibility = :public
|
71
80
|
o.source = statement.source
|
72
81
|
o.signature = "def #{name}_changed?"
|
@@ -80,6 +89,7 @@ module YARD
|
|
80
89
|
# @param [Symbol] scope +:instance+ or +:class+
|
81
90
|
def register_field_was(namespace, name, scope = :instance)
|
82
91
|
register_new_method_object(namespace, "#{name}_was", scope) do |o|
|
92
|
+
o.group = MONGOID_FIELDS
|
83
93
|
o.visibility = :public
|
84
94
|
o.source = statement.source
|
85
95
|
o.signature = "def #{name}_was"
|
@@ -93,6 +103,7 @@ module YARD
|
|
93
103
|
# @param [Symbol] scope +:instance+ or +:class+
|
94
104
|
def register_field_reset(namespace, name, scope = :instance)
|
95
105
|
register_new_method_object(namespace, "reset_#{name}!", scope) do |o|
|
106
|
+
o.group = MONGOID_FIELDS
|
96
107
|
o.visibility = :public
|
97
108
|
o.source = statement.source
|
98
109
|
o.signature = "def reset_#{name}!"
|
@@ -1,24 +1,24 @@
|
|
1
|
+
require 'yard/mongoid/helpers'
|
2
|
+
|
1
3
|
module YARD
|
2
4
|
module Mongoid
|
3
5
|
module Legacy
|
4
6
|
class FieldHandler < YARD::Handlers::Ruby::Legacy::AttributeHandler
|
5
|
-
include Helpers
|
7
|
+
include YARD::Mongoid::Helpers
|
6
8
|
|
7
9
|
handles /\Afield\s+:/
|
8
10
|
|
9
11
|
def process
|
10
|
-
nobj = namespace
|
11
|
-
mscope = scope
|
12
12
|
name = statement.tokens[2,1].to_s[1..-1]
|
13
13
|
|
14
|
-
|
15
|
-
register_field_setter(
|
16
|
-
register_field_presence(
|
17
|
-
register_field_change(
|
18
|
-
register_field_changed(
|
19
|
-
register_field_was(
|
20
|
-
register_field_reset(
|
21
|
-
super
|
14
|
+
register_field_getter(namespace, name, scope)
|
15
|
+
#register_field_setter(namespace, name, scope)
|
16
|
+
#register_field_presence(namespace, name, scope)
|
17
|
+
#register_field_change(namespace, name, scope)
|
18
|
+
#register_field_changed(namespace, name, scope)
|
19
|
+
#register_field_was(namespace, name, scope)
|
20
|
+
#register_field_reset(namespace, name, scope)
|
21
|
+
#super
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/lib/yard/mongoid/version.rb
CHANGED
data/yard-mongoid.gemspec
CHANGED
@@ -1,21 +1,23 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path(
|
3
|
-
require
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'yard/mongoid/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
|
-
s.name =
|
6
|
+
s.name = 'yard-mongoid'
|
7
7
|
s.version = Yard::Mongoid::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
|
-
s.authors = [
|
10
|
-
s.email =
|
11
|
-
s.homepage =
|
9
|
+
s.authors = ['Alexander Semyonov']
|
10
|
+
s.email = %w(al@semyonov.us)
|
11
|
+
s.homepage = 'http://rubygems.org/gems/yard-mongoid'
|
12
12
|
s.summary = %q{A Yard plugin for parsing Mongoid model syntax.}
|
13
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
14
|
|
15
|
-
s.rubyforge_project =
|
15
|
+
s.rubyforge_project = 'yard-mongoid'
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split("\n")
|
18
18
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
-
s.require_paths =
|
20
|
+
s.require_paths = %w(lib)
|
21
|
+
|
22
|
+
s.add_dependency 'yard', '~> 0.8.4'
|
21
23
|
end
|
metadata
CHANGED
@@ -1,37 +1,43 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard-mongoid
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3.pre
|
5
|
+
prerelease: 6
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Alexander Semyonov
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
date: 2013-03-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: yard
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.4
|
30
|
+
description: Once yard-mongoid is installed, YARD will automatically load the plugin
|
31
|
+
when ever the `yard doc` utility is ran on a project.
|
32
|
+
email:
|
24
33
|
- al@semyonov.us
|
25
34
|
executables: []
|
26
|
-
|
27
35
|
extensions: []
|
28
|
-
|
29
36
|
extra_rdoc_files: []
|
30
|
-
|
31
|
-
files:
|
37
|
+
files:
|
32
38
|
- .gitignore
|
33
39
|
- Gemfile
|
34
|
-
-
|
40
|
+
- MIT-LICENSE
|
35
41
|
- Rakefile
|
36
42
|
- lib/yard-mongoid.rb
|
37
43
|
- lib/yard/mongoid.rb
|
@@ -41,39 +47,29 @@ files:
|
|
41
47
|
- lib/yard/mongoid/legacy/field_handler.rb
|
42
48
|
- lib/yard/mongoid/version.rb
|
43
49
|
- yard-mongoid.gemspec
|
44
|
-
has_rdoc: true
|
45
50
|
homepage: http://rubygems.org/gems/yard-mongoid
|
46
51
|
licenses: []
|
47
|
-
|
48
52
|
post_install_message:
|
49
53
|
rdoc_options: []
|
50
|
-
|
51
|
-
require_paths:
|
54
|
+
require_paths:
|
52
55
|
- lib
|
53
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
57
|
none: false
|
55
|
-
requirements:
|
56
|
-
- -
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
|
59
|
-
|
60
|
-
- 0
|
61
|
-
version: "0"
|
62
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
63
|
none: false
|
64
|
-
requirements:
|
65
|
-
- -
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
|
68
|
-
segments:
|
69
|
-
- 0
|
70
|
-
version: "0"
|
64
|
+
requirements:
|
65
|
+
- - ! '>'
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.3.1
|
71
68
|
requirements: []
|
72
|
-
|
73
69
|
rubyforge_project: yard-mongoid
|
74
|
-
rubygems_version: 1.
|
70
|
+
rubygems_version: 1.8.23
|
75
71
|
signing_key:
|
76
72
|
specification_version: 3
|
77
73
|
summary: A Yard plugin for parsing Mongoid model syntax.
|
78
74
|
test_files: []
|
79
|
-
|
75
|
+
has_rdoc:
|