yard-activerecord 0.0.7 → 0.0.8

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/README.md CHANGED
@@ -73,3 +73,10 @@ methods simply as aliases for the associated object.
73
73
  The plugin will add class methods for any scopes you have defined in your
74
74
  models.
75
75
 
76
+
77
+ ## Other useful plugins ##
78
+
79
+ Check out:
80
+
81
+ * [https://github.com/ogeidix/yard-rails-plugin](https://github.com/ogeidix/yard-rails-plugin)
82
+
@@ -6,7 +6,6 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
6
6
  namespace_only
7
7
 
8
8
  def process
9
- group_name = "Active Record Associations"
10
9
  namespace.groups << group_name unless namespace.groups.include? group_name
11
10
 
12
11
  object = YARD::CodeObjects::MethodObject.new(namespace, method_name)
@@ -18,6 +17,10 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
18
17
  register object
19
18
  end
20
19
 
20
+ def group_name
21
+ "Active Record Associations"
22
+ end
23
+
21
24
  private
22
25
  def method_name
23
26
  call_params[0]
@@ -36,9 +39,9 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
36
39
  end
37
40
  end
38
41
  if singularize == true
39
- ActiveSupport::Inflector.singularize method_name.capitalize
42
+ method_name.camelize.singularize
40
43
  else
41
- method_name.capitalize
44
+ method_name.camelize
42
45
  end
43
46
  end
44
47
 
@@ -4,9 +4,13 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
4
  class BelongsToHandler < SingularHandler
5
5
  handles method_call(:belongs_to)
6
6
 
7
+ def group_name
8
+ 'Belongs to'
9
+ end
10
+
7
11
  private
8
12
  def return_description
9
- "#{namespace} <b>belongs to</b> a #{class_name}"
13
+ ''
10
14
  end
11
15
  end
12
16
  end
@@ -4,8 +4,13 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
4
  class HasAndBelongsToManyHandler < PluralHandler
5
5
  handles method_call(:has_and_belongs_to_many)
6
6
 
7
+ def group_name
8
+ 'Has and belongs to many'
9
+ end
10
+
11
+ private
7
12
  def return_description
8
- "#{namespace} <b>has and belongs to many</b> #{method_name}"
13
+ ''
9
14
  end
10
15
  end
11
16
  end
@@ -4,8 +4,13 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
4
  class HasManyHandler < PluralHandler
5
5
  handles method_call(:has_many)
6
6
 
7
+ def group_name
8
+ 'Has many'
9
+ end
10
+
11
+ private
7
12
  def return_description
8
- "#{namespace} <b>has many</b> #{method_name}"
13
+ ''
9
14
  end
10
15
  end
11
16
  end
@@ -4,8 +4,13 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
4
  class HasOneHandler < SingularHandler
5
5
  handles method_call(:has_one)
6
6
 
7
+ def group_name
8
+ 'Has one'
9
+ end
10
+
11
+ private
7
12
  def return_description
8
- "#{namespace} <b>has one</b> #{method_name}"
13
+ ''
9
14
  end
10
15
  end
11
16
  end
@@ -5,9 +5,10 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
5
5
  def class_name
6
6
  "Array<#{super(true)}>"
7
7
  end
8
-
8
+
9
+ private
9
10
  def return_description
10
- "An array of associated #{method_name}"
11
+ "An array of associated #{method_name.humanize}"
11
12
  end
12
13
  end
13
14
  end
@@ -5,9 +5,10 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
5
5
  def class_name
6
6
  super(false)
7
7
  end
8
-
8
+
9
+ private
9
10
  def return_description
10
- "An associated #{method_name}"
11
+ "An associated {#{method_name.humanize}}"
11
12
  end
12
13
  end
13
14
  end
@@ -6,12 +6,17 @@ module YARD::Handlers::Ruby::ActiveRecord::Delegations
6
6
  namespace_only
7
7
 
8
8
  def process
9
- params = call_params
10
- class_name = params.pop.capitalize
9
+ params = statement.parameters
10
+ params.pop # we shouldn't have a block, so pop that off
11
+ params.map! { |p| p.source }
12
+ options, params = params.partition { |v| v =~ /\=\>|\:\s/ }
13
+ class_name = options.detect { |v| v =~ /to\:\s|\:to \=\>/ } unless options.length == 0
14
+ class_name = class_name.to_s.gsub(/\A.*\:/,'').capitalize
11
15
  params.each do |method_name|
16
+ method_name.gsub!(/[\:\'\"]/,'')
12
17
  object = YARD::CodeObjects::MethodObject.new(namespace, method_name)
13
18
  object.group = "Delegated Instance Attributes"
14
- object.docstring = "Please refer to {#{class_name}##{method_name}}"
19
+ object.docstring = "Alias for {#{class_name}##{method_name}}"
15
20
  object.docstring.add_tag get_tag(:return,
16
21
  "{#{class_name}##{method_name}}", 'Object')
17
22
  object.docstring.add_tag get_tag(:see,
@@ -28,4 +33,4 @@ module YARD::Handlers::Ruby::ActiveRecord::Delegations
28
33
  YARD::Tags::Tag.new(tag, text, [return_classes].flatten)
29
34
  end
30
35
  end
31
- end
36
+ end
@@ -5,18 +5,16 @@ module YARD::Handlers::Ruby::ActiveRecord::Fields
5
5
  handles method_call(:integer)
6
6
  handles method_call(:float)
7
7
  handles method_call(:boolean)
8
+ handles method_call(:timestamp)
8
9
  handles method_call(:datetime)
10
+ handles method_call(:date)
9
11
 
10
12
  def process
11
13
  return unless statement.namespace.jump(:ident).source == 't'
12
14
  method_name = call_params.first
13
- class_name = caller_method.capitalize
14
15
 
15
16
  return if method_name['_id'] # Skip all id fields, associations will handle that
16
17
 
17
- if class_name == "Datetime"
18
- class_name = "DateTime"
19
- end
20
18
  ensure_loaded! P(globals.klass)
21
19
  namespace = P(globals.klass)
22
20
  return if namespace.nil?
@@ -40,11 +38,21 @@ module YARD::Handlers::Ruby::ActiveRecord::Fields
40
38
  end
41
39
 
42
40
  def description(method_name)
43
- "Database field value of #{method_name}. Defined in {file:db/schema.rb}"
41
+ '' # "Database field value of #{method_name}. Defined in {file:db/schema.rb}"
44
42
  end
45
43
 
46
44
  def get_tag(tag, text, return_classes)
47
45
  YARD::Tags::Tag.new(:return, text, [return_classes].flatten)
48
46
  end
47
+
48
+ private
49
+
50
+ def class_name
51
+ if ['datetime', 'timestamp'].include?(caller_method)
52
+ 'DateTime'
53
+ else
54
+ caller_method.capitalize
55
+ end
56
+ end
49
57
  end
50
58
  end
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module ActiveRecord
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: