yard-activerecord 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- YzQxYzljYjFkODJmOWU1NmQ4YjA0NzFiNGQwMjJlODgyZTg2MjA3NA==
5
- data.tar.gz: !binary |-
6
- N2I0MjRjZjI1OGMzZWFkMjZiMjExYTBjZWEzZWMwZmM5MDIyMGMwMA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- OWFjZTE3OTVjN2JiODcxMGQ4NmE1NmEzYTY0MWUyNzNkYmFlM2RhNTI0MWI2
10
- OWU3YzUzNDFlOWE4MjhiZDZmZmQ5YzNkZWEwYTljNTU1NDcwN2E5MWE0ZGVm
11
- NTVlM2U2YzgzNDAzMGYyNzUyYzliNzMzN2Q2Mjc4Mzc3ZWE2OTc=
12
- data.tar.gz: !binary |-
13
- YTIzNGM4NGJhNmYzZmI2MTY3Yjc4Y2ZiMDQ3ZTRjYWYzODdlMDE4NWQzMjJj
14
- MDlkNjU2MGFiN2FlMWRiNDdjMzlkMjc0OWI2MTM4NThmODM0NWQ0NjIxZDE2
15
- OWNlNmVjZTU3NmNlN2MyMTcwMTM4NzUwMWRlZjkxZDI4ZTMyMzY=
2
+ SHA1:
3
+ metadata.gz: 7004249aaeef940d9c42dcd0b0b70d1b79132458
4
+ data.tar.gz: 74166e2dbe0f6a0e1bac5ebf82ea9b314fc0ce07
5
+ SHA512:
6
+ metadata.gz: ee09ea1271e6f0739b5ed17928d2079c04da45c65a88cfdb48e20b677dc790d1b0caca1265324afc76a5c89a321d756e7ab4180d760720693b4566a37eb59c76
7
+ data.tar.gz: 486069183cbb3b5b7d175f6659fa3da539e31847537781f2262c2ed036d9360f0f5c3cdb18b45ae2ac21e26e90f44fa4113af12054a5467f3ae5390c11d7b28a
data/README.md CHANGED
@@ -1,4 +1,8 @@
1
- # YARD ActiveRecord Plugin #
1
+ # YARD ActiveRecord Plugin
2
+
3
+ [![Version](http://img.shields.io/gem/v/yard-activerecord.svg?style=flat-square)](https://rubygems.org/gems/yard-activerecord)
4
+ [![Downloads](http://img.shields.io/gem/dt/yard-activerecord.svg?style=flat-square)](https://rubygems.org/gems/yard-activerecord)
5
+ [![Open Github issues](http://img.shields.io/github/issues/theodorton/yard-activerecord.svg?style=flat-square)](https://github.com/theodorton/yard-activerecord/issues)
2
6
 
3
7
  A YARD extension that handles and interprets methods used when developing
4
8
  applications with ActiveRecord. The extension handles attributes,
@@ -6,7 +10,7 @@ associations, delegates and scopes. A must for any Rails app using YARD as
6
10
  documentation plugin.
7
11
 
8
12
 
9
- ## Installation ##
13
+ ## Installation
10
14
 
11
15
  Run the following command in order to load YARD plugins:
12
16
 
@@ -14,7 +18,7 @@ Run the following command in order to load YARD plugins:
14
18
  $ yard config load_plugins true
15
19
  ```
16
20
 
17
- ## Attributes ##
21
+ ## Attributes
18
22
 
19
23
  In order for this plugin to document any database attributes you need to add
20
24
  `schema.rb` to your list of files. This is preferably done with in `.yardopts`
@@ -56,27 +60,39 @@ Example:
56
60
 
57
61
  The documentation will then be skipped for this table/class.
58
62
 
59
- ## Associations ##
63
+ ## Associations
60
64
 
61
65
  The plugin handles `has_one`, `belongs_to`, `has_many` and
62
66
  `has_and_belongs_to_many` associations. The annotation for each association
63
67
  includes a link to the referred model. For associations with a list of objects
64
68
  the documentation will simply be marked as `Array<ModelName>`.
65
69
 
66
- ## Delegates ##
70
+ ## Delegates
67
71
 
68
72
  The plugin handles `delegate`-methods and marks these delegated instance
69
73
  methods simply as aliases for the associated object.
70
74
 
71
- ## Scopes ##
75
+ ## Scopes
72
76
 
73
77
  The plugin will add class methods for any scopes you have defined in your
74
78
  models.
75
79
 
80
+ ## Validations ##
81
+
82
+ The plugin will add information about validations onto each field. It only handles
83
+ the new style validations in the form of:
84
+
85
+ validates :foo, :presence=>true, :length=>{ is: 6 }
86
+
87
+ Validations in the older form of:
76
88
 
77
- ## Other useful plugins ##
89
+ validates_presence_of :foo
90
+
91
+ are not supported.
92
+
93
+ ## Other useful plugins
78
94
 
79
95
  Check out:
80
-
96
+
81
97
  * [https://github.com/ogeidix/yard-rails-plugin](https://github.com/ogeidix/yard-rails-plugin)
82
98
 
@@ -3,6 +3,8 @@ require 'yard'
3
3
  module YARD::Handlers::Ruby::ActiveRecord
4
4
  end
5
5
 
6
+ YARD::Templates::Engine.register_template_path File.dirname(__FILE__) + '/../templates'
7
+
6
8
  root = File.expand_path(File.dirname(__FILE__))
7
9
  $LOAD_PATH << root unless $LOAD_PATH.include? root
8
10
 
@@ -18,3 +20,4 @@ require 'yard-activerecord/associations/has_and_belongs_to_many_handler'
18
20
  require 'yard-activerecord/delegations/delegate_handler'
19
21
 
20
22
  require 'yard-activerecord/scopes/scope_handler'
23
+ require 'yard-activerecord/validations/validates_handler'
@@ -8,13 +8,13 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
8
8
  def process
9
9
  namespace.groups << group_name unless namespace.groups.include? group_name
10
10
 
11
- object = YARD::CodeObjects::MethodObject.new(namespace, method_name)
11
+ object = register YARD::CodeObjects::MethodObject.new(namespace, method_name)
12
12
  object.group = group_name
13
- object.docstring = return_description
13
+ object.docstring = return_description if object.docstring.empty?
14
14
  object.docstring.add_tag get_tag(:return, '', class_name)
15
- object.docstring.add_tag get_tag(:see, 'http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html')
15
+ object.docstring.add_tag get_tag(:see, "ActiveRecord::Associations", nil,
16
+ 'http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html' )
16
17
  object.dynamic = true
17
- register object
18
18
  end
19
19
 
20
20
  def group_name
@@ -49,8 +49,8 @@ module YARD::Handlers::Ruby::ActiveRecord::Associations
49
49
  "An array of associated #{method_name}."
50
50
  end
51
51
 
52
- def get_tag(tag, text, return_classes = [])
53
- YARD::Tags::Tag.new(tag, text, [return_classes].flatten)
52
+ def get_tag(tag, text, return_classes = [], name=nil)
53
+ YARD::Tags::Tag.new(tag, text, [return_classes].flatten, name)
54
54
  end
55
55
  end
56
56
  end
@@ -14,14 +14,13 @@ module YARD::Handlers::Ruby::ActiveRecord::Delegations
14
14
  class_name = class_name.to_s.gsub(/\A.*\:/,'').capitalize
15
15
  params.each do |method_name|
16
16
  method_name.gsub!(/[\:\'\"]/,'')
17
- object = YARD::CodeObjects::MethodObject.new(namespace, method_name)
17
+ object = register YARD::CodeObjects::MethodObject.new(namespace, method_name)
18
18
  object.group = "Delegated Instance Attributes"
19
19
  object.docstring = "Alias for {#{class_name}##{method_name}}"
20
20
  object.docstring.add_tag get_tag(:return,
21
21
  "{#{class_name}##{method_name}}", 'Object')
22
- object.docstring.add_tag get_tag(:see,
22
+ object.docstring.add_tag get_tag(:see,"Module#delegate",nil,
23
23
  "http://api.rubyonrails.org/classes/Module.html#method-i-delegate")
24
- register object
25
24
  end
26
25
  group_name = "Delegated Instance Attributes"
27
26
  namespace.groups << group_name unless namespace.groups.include? group_name
@@ -29,8 +28,8 @@ module YARD::Handlers::Ruby::ActiveRecord::Delegations
29
28
 
30
29
  private
31
30
 
32
- def get_tag(tag, text, return_classes = [])
33
- YARD::Tags::Tag.new(tag, text, [return_classes].flatten)
31
+ def get_tag(tag, text, return_classes = [], name=nil)
32
+ YARD::Tags::Tag.new(tag, text, [return_classes].flatten,name)
34
33
  end
35
34
  end
36
35
  end
@@ -5,39 +5,43 @@ 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(:decimal)
8
9
  handles method_call(:timestamp)
9
10
  handles method_call(:datetime)
10
11
  handles method_call(:date)
11
-
12
+
12
13
  def process
13
14
  return unless statement.namespace.jump(:ident).source == 't'
14
15
  method_name = call_params.first
15
-
16
+
16
17
  return if method_name['_id'] # Skip all id fields, associations will handle that
17
-
18
+
18
19
  ensure_loaded! P(globals.klass)
19
20
  namespace = P(globals.klass)
20
21
  return if namespace.nil?
21
22
 
22
23
  method_definition = namespace.instance_attributes[method_name.to_sym] || {}
23
-
24
+
24
25
  { read: method_name, write: "#{method_name}=" }.each do |(rw, name)|
25
- next if method_definition[rw]
26
- rw_object = YARD::CodeObjects::MethodObject.new(namespace, name)
26
+ method = method_definition[rw]
27
+ if method
28
+ method.docstring.add_tag( get_tag(:return, '', class_name) ) unless method.has_tag?( :return )
29
+ next
30
+ end
31
+ rw_object = register YARD::CodeObjects::MethodObject.new(namespace, name)
27
32
  rw_object.docstring = description(name)
28
33
  rw_object.docstring.add_tag get_tag(:return, '', class_name)
29
34
  rw_object.dynamic = true
30
- register rw_object
31
35
  method_definition[rw] = rw_object
32
36
  end
33
37
 
34
38
  namespace.instance_attributes[method_name.to_sym] = method_definition
35
39
  end
36
-
40
+
37
41
  def description(method_name)
38
42
  '' # "Database field value of #{method_name}. Defined in {file:db/schema.rb}"
39
43
  end
40
-
44
+
41
45
  def get_tag(tag, text, return_classes)
42
46
  YARD::Tags::Tag.new(:return, text, [return_classes].flatten)
43
47
  end
@@ -6,12 +6,11 @@ module YARD::Handlers::Ruby::ActiveRecord::Scopes
6
6
  namespace_only
7
7
 
8
8
  def process
9
- object = YARD::CodeObjects::MethodObject.new(namespace, method_name, :class)
9
+ object = register YARD::CodeObjects::MethodObject.new(namespace, method_name, :class)
10
10
  object.docstring = return_description
11
11
  object.docstring.add_tag get_tag(:return, '', class_name)
12
- object.docstring.add_tag get_tag(:see,
13
- 'http://api.rubyonrails.org/classes/ActiveRecord/NamedScope/ClassMethods.html')
14
- register object
12
+ object.docstring.add_tag get_tag(:see,"ActiveRecord::Scoping", nil,
13
+ 'http://api.rubyonrails.org/classes/ActiveRecord/Scoping/Named/ClassMethods.html')
15
14
  end
16
15
 
17
16
  private
@@ -29,8 +28,8 @@ module YARD::Handlers::Ruby::ActiveRecord::Scopes
29
28
  "Array<#{namespace}>"
30
29
  end
31
30
 
32
- def get_tag(tag, text, return_classes = [])
33
- YARD::Tags::Tag.new(tag, text, [return_classes].flatten)
31
+ def get_tag(tag, text, return_classes = [],name=nil)
32
+ YARD::Tags::Tag.new(tag, text, [return_classes].flatten,name)
34
33
  end
35
34
  end
36
- end
35
+ end
@@ -0,0 +1,110 @@
1
+ require 'active_support/inflector'
2
+ require 'active_support/core_ext/array'
3
+
4
+ module YARD::Handlers::Ruby::ActiveRecord::Validate
5
+
6
+ # Links with a value of nil will be link to
7
+ # the Rails Validations guide.
8
+ # Other projects can add to the
9
+ STANDARD_LINKS = [
10
+ :acceptance,
11
+ :validates_associated,
12
+ :confirmation,
13
+ :exclusion,
14
+ :format,
15
+ :inclusion,
16
+ :length,
17
+ :numericality,
18
+ :presence,
19
+ :absence,
20
+ :uniqueness,
21
+ :validates_with,
22
+ :validates_each
23
+ ]
24
+
25
+ def self.add_validation_type( type, link )
26
+ @custom_types ||= {}
27
+ @custom_types[type.to_sym] = link
28
+ end
29
+
30
+ def self.link_for_validation( type )
31
+ type = type.downcase.to_sym
32
+ if STANDARD_LINKS.include?( type )
33
+ "http://edgeguides.rubyonrails.org/active_record_validations.html##{type}"
34
+ elsif @custom_types && link = @custom_types[ type ]
35
+ link
36
+ else
37
+ nil
38
+ end
39
+ end
40
+
41
+ # Define validations tag for later use
42
+ YARD::Tags::Library.define_tag("Validations", :validates )
43
+
44
+ # Document ActiveRecord validations.
45
+ # This handler handles the validates statement.
46
+ # It will parse the list of fields, the validation types and their options,
47
+ # and the optional :if/:unless clause.
48
+ # It only handles the newer Rails ":validates" syntax and does not
49
+ # recognize the older "validates_presence_of" type methods.
50
+ class ValidatesHandler < YARD::Handlers::Ruby::MethodHandler
51
+ namespace_only
52
+ handles method_call(:validates)
53
+ def process
54
+
55
+ validations = {}
56
+ attributes = []
57
+ conditions = {}
58
+
59
+ # Read each parameter to the statement and parse out
60
+ # it's type and intent
61
+ statement.parameters(false).compact.map do |param|
62
+ # list types are options
63
+ if param.type == :list
64
+ param.each do | n |
65
+ kw = n.jump(:label, :symbol_literal ).source.gsub(/:/,'')
66
+ # if/unless are conditions that apply to all the validations
67
+ if ['if','unless','on'].include?(kw)
68
+ conditions[ kw ] = n.children.last.source
69
+ else # otherwise it's type specific
70
+ opts = n.jump(:hash)
71
+ value = ( opts != n ) ? opts.source : nil
72
+ validations[ kw ] = value
73
+ end
74
+ end
75
+ elsif param.type == :symbol_literal
76
+ attributes << param.jump(:ident, :kw, :tstring_content).source
77
+ end
78
+ end
79
+
80
+ # abort in case we didn't parse anything
81
+ return if validations.empty?
82
+
83
+ # Loop through each attribute and set a tag on each
84
+ attributes.each do | attribute |
85
+ method_definition = namespace.instance_attributes[attribute.to_sym] || {}
86
+ method = method_definition[:read]
87
+ if ! method
88
+ meths = namespace.meths(:all => true)
89
+ method = meths.find {|m| m.name == attribute.to_sym }
90
+ end
91
+ # If the method isn't defined yet, go ahead and create one
92
+ if ! method
93
+ method = register YARD::CodeObjects::MethodObject.new(namespace, attribute )
94
+ method.scope = :instance
95
+ method.explicit = false
96
+ method_definition[:read] = method
97
+ namespace.instance_attributes[attribute.to_sym] = method_definition
98
+ end
99
+ tag = YARD::Tags::OptionTag.new(:validates, '', conditions ) #, [] )
100
+ tag.types = {} #[]
101
+ validations.each{ |arg,options|
102
+ tag.types[ arg ] = options
103
+ }
104
+ method.docstring.add_tag tag
105
+ end
106
+
107
+ end
108
+ end
109
+
110
+ end
@@ -1,5 +1,5 @@
1
1
  module YARD
2
2
  module ActiveRecord
3
- VERSION = "0.0.11"
3
+ VERSION = "0.0.12"
4
4
  end
5
5
  end
@@ -0,0 +1,15 @@
1
+ <p class="tag_title">Validations<% if @condition %> (<i><%= @condition %></i> )<% end %>:</p>
2
+ <ul class="validations">
3
+ <% for tag in @tags %>
4
+ <% tag.types.each do | type, options | %>
5
+ <li>
6
+ <% if link = YARD::Handlers::Ruby::ActiveRecord::Validate.link_for_validation( type ) %>
7
+ <%= linkify(link, type.capitalize ) %>
8
+ <% else %>
9
+ <%= type.capitalize %>
10
+ <% end %>
11
+ <% if options %> (<%= options %>) <% end %>
12
+ </li>
13
+ <% end %>
14
+ <% end %>
15
+ </ul>
@@ -0,0 +1,23 @@
1
+ def init
2
+ super
3
+ if object.has_tag?(:validates)
4
+ create_tag_methods([:validates])
5
+ sections << Section.new(:validates)
6
+ end
7
+ end
8
+
9
+ def validates
10
+ all_tags = object.tags(:validates)
11
+ out = ''
12
+ conditions = all_tags.map{| tag | tag.pair.to_s }.uniq.compact
13
+ conditions.each do | condition |
14
+ @tags = all_tags.select{|tag| tag.pair.to_s == condition }
15
+ condition = @tags.first.pair.map do | type, check |
16
+ check = linkify( check.gsub(/^:/,'#') ) if check =~/^:/ # it's a symbol, convert to link
17
+ "#{type} => #{check}"
18
+ end
19
+ @condition = condition.empty? ? nil : condition.join(',')
20
+ out << erb( :validations )
21
+ end
22
+ out
23
+ end
@@ -0,0 +1,7 @@
1
+ Validations<% if @condition %> (<%= @condition %> )<% end %>:
2
+ ---------
3
+ <% for tag in @tags %>
4
+ <% for type in tag.types %>
5
+ <%= type %>
6
+ <% end %>
7
+ <% end %>
metadata CHANGED
@@ -1,44 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theodor Tonum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-28 00:00:00.000000000 Z
11
+ date: 2014-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.8.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.8.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: ! "\n YARD-Activerecord is a YARD extension that handles and interprets
41
+ description: "\n YARD-Activerecord is a YARD extension that handles and interprets
42
42
  methods\n used when developing applications with ActiveRecord. The extension
43
43
  handles\n attributes, associations, delegates and scopes. A must for any Rails
44
44
  app\n using YARD as documentation plugin. "
@@ -48,7 +48,7 @@ executables: []
48
48
  extensions: []
49
49
  extra_rdoc_files: []
50
50
  files:
51
- - .gitignore
51
+ - ".gitignore"
52
52
  - Gemfile
53
53
  - LICENSE
54
54
  - README.md
@@ -66,7 +66,11 @@ files:
66
66
  - lib/yard-activerecord/fields/define_handler.rb
67
67
  - lib/yard-activerecord/fields/field_handler.rb
68
68
  - lib/yard-activerecord/scopes/scope_handler.rb
69
+ - lib/yard-activerecord/validations/validates_handler.rb
69
70
  - lib/yard-activerecord/version.rb
71
+ - templates/default/tags/html/validations.erb
72
+ - templates/default/tags/setup.rb
73
+ - templates/default/tags/text/validations.erb
70
74
  - test.rb
71
75
  - yard-activerecord.gemspec
72
76
  homepage: https://github.com/theodorton/yard-activerecord
@@ -79,19 +83,18 @@ require_paths:
79
83
  - lib
80
84
  required_ruby_version: !ruby/object:Gem::Requirement
81
85
  requirements:
82
- - - ! '>='
86
+ - - ">="
83
87
  - !ruby/object:Gem::Version
84
88
  version: '0'
85
89
  required_rubygems_version: !ruby/object:Gem::Requirement
86
90
  requirements:
87
- - - ! '>='
91
+ - - ">="
88
92
  - !ruby/object:Gem::Version
89
93
  version: '0'
90
94
  requirements: []
91
95
  rubyforge_project:
92
- rubygems_version: 2.0.6
96
+ rubygems_version: 2.2.2
93
97
  signing_key:
94
98
  specification_version: 4
95
99
  summary: ActiveRecord Handlers for YARD
96
100
  test_files: []
97
- has_rdoc: