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 CHANGED
@@ -1,3 +1,4 @@
1
1
  pkg/*
2
2
  *.gem
3
3
  .bundle
4
+ Gemfile.lock
data/Gemfile CHANGED
@@ -1,6 +1,9 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in yard-mongoid.gemspec
4
4
  gemspec
5
5
 
6
- gem 'yard', '~> 0.6.1'
6
+ group :development do
7
+ gem 'rake'
8
+ gem 'mongoid', '~> 3.0'
9
+ end
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,8 +1,7 @@
1
+ require 'yard/mongoid/version'
1
2
  module YARD
2
3
  module Mongoid
3
- autoload :VERSION, 'yard/mongoid/version'
4
- autoload :Extensions, 'yard/mongoid/extensions'
5
- autoload :Helpers, 'yard/mongoid/helpers'
4
+ MONGOID_FIELDS = 'Mongoid Fields'
6
5
  end
7
6
  end
8
7
 
@@ -13,7 +13,7 @@ module YARD
13
13
  end
14
14
  end
15
15
 
16
- return namespace
16
+ namespace
17
17
  end
18
18
  end
19
19
  end
@@ -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
- nobj = effected_namespace
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
- #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)
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
@@ -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
- o.docstring = "Returns the value of attribute #{name}"
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
- #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
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
@@ -1,5 +1,5 @@
1
1
  module Yard
2
2
  module Mongoid
3
- VERSION = "0.0.2"
3
+ VERSION = '0.0.3.pre'
4
4
  end
5
5
  end
data/yard-mongoid.gemspec CHANGED
@@ -1,21 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "yard/mongoid/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'yard/mongoid/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "yard-mongoid"
6
+ s.name = 'yard-mongoid'
7
7
  s.version = Yard::Mongoid::VERSION
8
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"
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 = "yard-mongoid"
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 = ["lib"]
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
- hash: 27
5
- prerelease: false
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
- 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:
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
- - Gemfile.lock
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
- hash: 3
59
- segments:
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
- hash: 3
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.3.7
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:
data/Gemfile.lock DELETED
@@ -1,16 +0,0 @@
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!