yard-activerecord2 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in yard-activerecord.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # YARD ActiveRecord Plugin #
2
+
3
+ A YARD extension that handles and interprets methods used when developing
4
+ applications with ActiveRecord. The extension handles attributes,
5
+ associations, delegates and scopes. A must for any Rails app using YARD as
6
+ documentation plugin.
7
+
8
+ ## Attributes ##
9
+
10
+ In order for this plugin to document any database attributes you need to add
11
+ `schema.rb` to your list of files. This is preferably done with in `.yardopts`.
12
+
13
+ The `schema.rb`-file should be added at the end as it needs all classes loaded
14
+ before it can add the attributes.
15
+
16
+ The plugin will then document all attributes in your documentation.
17
+
18
+ All attributes will be marked as writable. I will update the plugin to include
19
+ handling of `attr_accessible` at a later point.
20
+
21
+ Please note that any reference-fields that ends with `_id` will not be handled
22
+ as an attribute. Please see Associations.
23
+
24
+ There is an issue with namespaced classes. Currently this plugin will try and
25
+ fetch a class with a namespace if it does not find one at the first try.
26
+
27
+ Example:
28
+
29
+ Table name Class name
30
+ sales_people SalesPeople # does not exist
31
+ sales_people Sales::People # does exist
32
+
33
+ A problem then emerges if you have namespaces with two names.
34
+
35
+ Example:
36
+
37
+ Table name Class name
38
+ sales_force_people SalesForcePeople # does not exist
39
+ sales_force_people Sales::ForcePeople # does not exist
40
+
41
+ The documentation will then be skipped for this table/class.
42
+
43
+ ## Associations ##
44
+
45
+ The plugin handles `has_one`, `belongs_to`, `has_many` and
46
+ `has_and_belongs_to_many` associations. The annotation for each association
47
+ includes a link to the referred model. For associations with a list of objects
48
+ the documentation will simply be marked as `Array<ModelName>`.
49
+
50
+ ## Delegates ##
51
+
52
+ The plugin handles `delegate`-methods and marks these delegated instance
53
+ methods simply as aliases for the associated object.
54
+
55
+ ## Scopes ##
56
+
57
+ The plugin will add class methods for any scopes you have defined in your
58
+ models.
59
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,52 @@
1
+ require 'yard'
2
+ require 'active_support/inflector'
3
+
4
+ module YARD::Handlers::Ruby::ActiveRecord::Associations
5
+ class Base < YARD::Handlers::Ruby::MethodHandler
6
+ namespace_only
7
+
8
+ def process
9
+ object = YARD::CodeObjects::MethodObject.new(namespace, method_name)
10
+ object.group = "Active Record Associations"
11
+ object.docstring = return_description
12
+ object.docstring.add_tag get_tag(:return, '', class_name)
13
+ object.docstring.add_tag get_tag(:see, 'http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html')
14
+ object.dynamic = true
15
+ register object
16
+ group_name = "Active Record Associations"
17
+ namespace.groups << group_name unless namespace.groups.include? group_name
18
+ end
19
+
20
+ private
21
+ def method_name
22
+ call_params[0]
23
+ end
24
+
25
+ def class_name(singularize = false)
26
+ param_size = statement.parameters.size
27
+ if param_size > 2
28
+ i = 1
29
+ return_this = false
30
+ while i < param_size - 1
31
+ # May want to evaluate doing it this way
32
+ hash = eval('{' + statement.parameters[i].jump(:hash).source + '}')
33
+ return hash[:class_name] unless hash[:class_name].nil?
34
+ i += 1
35
+ end
36
+ end
37
+ if singularize == true
38
+ ActiveSupport::Inflector.singularize method_name.capitalize
39
+ else
40
+ method_name.capitalize
41
+ end
42
+ end
43
+
44
+ def return_description
45
+ "An array of associated #{method_name}."
46
+ end
47
+
48
+ def get_tag(tag, text, return_classes = [])
49
+ YARD::Tags::Tag.new(tag, text, [return_classes].flatten)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,12 @@
1
+ require_relative 'singular_handler'
2
+
3
+ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
+ class BelongsToHandler < SingularHandler
5
+ handles method_call(:belongs_to)
6
+
7
+ private
8
+ def return_description
9
+ "#{namespace} <b>belongs to</b> a #{class_name}"
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'plural_handler'
2
+
3
+ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
+ class HasAndBelongsToManyHandler < PluralHandler
5
+ handles method_call(:has_and_belongs_to_many)
6
+
7
+ def return_description
8
+ "#{namespace} <b>has and belongs to many</b> #{method_name}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'plural_handler'
2
+
3
+ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
+ class HasManyHandler < PluralHandler
5
+ handles method_call(:has_many)
6
+
7
+ def return_description
8
+ "#{namespace} <b>has many</b> #{method_name}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'singular_handler'
2
+
3
+ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
+ class HasOneHandler < SingularHandler
5
+ handles method_call(:has_one)
6
+
7
+ def return_description
8
+ "#{namespace} <b>has one</b> #{method_name}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'base'
2
+
3
+ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
+ class PluralHandler < Base
5
+ def class_name
6
+ "Array<#{super(true)}>"
7
+ end
8
+
9
+ def return_description
10
+ "An array of associated #{method_name}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'base'
2
+
3
+ module YARD::Handlers::Ruby::ActiveRecord::Associations
4
+ class SingularHandler < Base
5
+ def class_name
6
+ super(false)
7
+ end
8
+
9
+ def return_description
10
+ "An associated #{method_name}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ require 'yard'
2
+
3
+ module YARD::Handlers::Ruby::ActiveRecord::Delegations
4
+ class DelegateHandler < YARD::Handlers::Ruby::MethodHandler
5
+ handles method_call(:delegate)
6
+ namespace_only
7
+
8
+ def process
9
+ params = call_params
10
+ class_name = params.pop
11
+ class_name = class_name[:to] if class_name.is_a?(Hash) && class_name[:to]
12
+ class_name.capitalize!
13
+ params.each do |method_name|
14
+ object = YARD::CodeObjects::MethodObject.new(namespace, method_name)
15
+ object.group = "Delegated Instance Attributes"
16
+ object.docstring = "Please refer to {#{class_name}##{method_name}}"
17
+ object.docstring.add_tag get_tag(:return,
18
+ "{#{class_name}##{method_name}}", 'Object')
19
+ object.docstring.add_tag get_tag(:see,
20
+ "http://api.rubyonrails.org/classes/Module.html#method-i-delegate")
21
+ register object
22
+ end
23
+ group_name = "Delegated Instance Attributes"
24
+ namespace.groups << group_name unless namespace.groups.include? group_name
25
+ end
26
+
27
+ private
28
+
29
+ def get_tag(tag, text, return_classes = [])
30
+ YARD::Tags::Tag.new(tag, text, [return_classes].flatten)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+ require 'yard'
2
+ require 'active_support/inflector'
3
+
4
+ module YARD::Handlers::Ruby::ActiveRecord::Fields
5
+ class CreateTableHandler < YARD::Handlers::Ruby::MethodHandler
6
+ handles method_call(:create_table)
7
+
8
+ def process
9
+ return unless globals.ar_schema
10
+ globals.klass = ActiveSupport::Inflector.singularize call_params.first.camelize
11
+ if P(globals.klass).class == YARD::CodeObjects::Proxy
12
+ # Try module with the first part
13
+ globals.klass = globals.klass.underscore.split('_',2).map(&:camelize).join('::')
14
+ end
15
+ parse_block(statement.last.last)
16
+ globals.klass = nil
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module YARD::Handlers::Ruby::ActiveRecord::Fields
2
+ class DefineHandler < YARD::Handlers::Ruby::MethodHandler
3
+ handles method_call(:define)
4
+
5
+ def process
6
+ if statement.file == 'db/schema.rb'
7
+ globals.ar_schema = true
8
+ parse_block(statement.last.last)
9
+ globals.ar_schema = false
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,50 @@
1
+ module YARD::Handlers::Ruby::ActiveRecord::Fields
2
+ class FieldHandler < YARD::Handlers::Ruby::MethodHandler
3
+ handles method_call(:string)
4
+ handles method_call(:text)
5
+ handles method_call(:integer)
6
+ handles method_call(:float)
7
+ handles method_call(:boolean)
8
+ handles method_call(:datetime)
9
+
10
+ def process
11
+ return unless statement.namespace.jump(:ident).source == 't'
12
+ method_name = call_params.first
13
+ class_name = caller_method.capitalize
14
+
15
+ return if method_name['_id'] # Skip all id fields, associations will handle that
16
+
17
+ if class_name == "Datetime"
18
+ class_name = "DateTime"
19
+ end
20
+ ensure_loaded! P(globals.klass)
21
+ namespace = P(globals.klass)
22
+ return if namespace.nil?
23
+
24
+ r_object = YARD::CodeObjects::MethodObject.new(namespace, method_name)
25
+ r_object.docstring = description(method_name)
26
+ r_object.docstring.add_tag get_tag(:return, '', class_name)
27
+ r_object.dynamic = true
28
+ register r_object
29
+
30
+ w_object = YARD::CodeObjects::MethodObject.new(namespace, "#{method_name}=")
31
+ w_object.docstring = description(method_name)
32
+ w_object.docstring.add_tag get_tag(:return, '', class_name)
33
+ w_object.dynamic = true
34
+ register w_object
35
+
36
+ namespace.instance_attributes[method_name.to_sym] = {
37
+ read: r_object,
38
+ write: w_object
39
+ }
40
+ end
41
+
42
+ def description(method_name)
43
+ "Database field value of #{method_name}. Defined in {file:db/schema.rb}"
44
+ end
45
+
46
+ def get_tag(tag, text, return_classes)
47
+ YARD::Tags::Tag.new(:return, text, [return_classes].flatten)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,36 @@
1
+ require 'active_support/inflector'
2
+
3
+ module YARD::Handlers::Ruby::ActiveRecord::Scopes
4
+ class ScopeHandler < YARD::Handlers::Ruby::MethodHandler
5
+ handles method_call(:scope)
6
+ namespace_only
7
+
8
+ def process
9
+ object = YARD::CodeObjects::MethodObject.new(namespace, method_name, :class)
10
+ object.docstring = return_description
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
15
+ end
16
+
17
+ private
18
+ def method_name
19
+ call_params[0]
20
+ end
21
+
22
+ def return_description
23
+ "An array of #{ActiveSupport::Inflector.pluralize namespace.to_s} " +
24
+ "that are #{method_name.split('_').join(' ')}. " +
25
+ "<strong>Active Record Scope</strong>"
26
+ end
27
+
28
+ def class_name
29
+ "Array<#{namespace}>"
30
+ end
31
+
32
+ def get_tag(tag, text, return_classes = [])
33
+ YARD::Tags::Tag.new(tag, text, [return_classes].flatten)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module YARD
2
+ module ActiveRecord
3
+ VERSION = "0.0.7"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require 'yard'
2
+
3
+ module YARD::Handlers::Ruby::ActiveRecord
4
+ end
5
+
6
+ require_relative 'yard-activerecord/fields/create_table_handler'
7
+ require_relative 'yard-activerecord/fields/define_handler'
8
+ require_relative 'yard-activerecord/fields/field_handler'
9
+
10
+ require_relative 'yard-activerecord/associations/belongs_to_handler'
11
+ require_relative 'yard-activerecord/associations/has_one_handler'
12
+ require_relative 'yard-activerecord/associations/has_one_handler'
13
+ require_relative 'yard-activerecord/associations/has_and_belongs_to_many_handler'
14
+
15
+ require_relative 'yard-activerecord/delegations/delegate_handler'
16
+
17
+ require_relative 'yard-activerecord/scopes/scope_handler'
data/test.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'bundler/setup'
2
+ require 'yard-activerecord'
3
+
4
+ YARD::Handlers::Ruby::ActiveRecord::Fields::CreateTable.new
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'YARD'
3
+ require File.dirname(__FILE__) + '/lib/yard-activerecord'
4
+ require File.dirname(__FILE__) + '/lib/yard-activerecord/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "yard-activerecord2"
8
+ s.version = YARD::ActiveRecord::VERSION
9
+ s.authors = ["Theodor Tonum"]
10
+ s.email = ["theodor@tonum.no"]
11
+ s.homepage = ""
12
+ s.summary = %q{ActiveRecord Handlers for YARD}
13
+ s.description = %q{
14
+ YARD-Activerecord is a YARD extension that handles and interprets methods
15
+ used when developing applications with ActiveRecord. The extension handles
16
+ attributes, associations, delegates and scopes. A must for any Rails app
17
+ using YARD as documentation plugin. }
18
+
19
+ s.add_development_dependency 'yard', '>= 0.7.0'
20
+
21
+ s.files = `git ls-files`.split("\n")
22
+ s.require_path = "lib"
23
+ end
metadata CHANGED
@@ -1,12 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yard-activerecord2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Theodor Tonum
9
- - Kelly Martin
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
@@ -19,15 +18,15 @@ dependencies:
19
18
  requirements:
20
19
  - - ! '>='
21
20
  - !ruby/object:Gem::Version
22
- version: 0.8.3
23
- type: :runtime
21
+ version: 0.7.0
22
+ type: :development
24
23
  prerelease: false
25
24
  version_requirements: !ruby/object:Gem::Requirement
26
25
  none: false
27
26
  requirements:
28
27
  - - ! '>='
29
28
  - !ruby/object:Gem::Version
30
- version: 0.8.3
29
+ version: 0.7.0
31
30
  description: ! "\n YARD-Activerecord is a YARD extension that handles and interprets
32
31
  methods\n used when developing applications with ActiveRecord. The extension
33
32
  handles\n attributes, associations, delegates and scopes. A must for any Rails
@@ -37,7 +36,34 @@ email:
37
36
  executables: []
38
37
  extensions: []
39
38
  extra_rdoc_files: []
40
- files: []
39
+ files:
40
+ - .DS_Store
41
+ - .gitignore
42
+ - Gemfile
43
+ - README.md
44
+ - Rakefile
45
+ - lib/.DS_Store
46
+ - lib/yard-activerecord.rb
47
+ - lib/yard-activerecord/.DS_Store
48
+ - lib/yard-activerecord/associations/.DS_Store
49
+ - lib/yard-activerecord/associations/base.rb
50
+ - lib/yard-activerecord/associations/belongs_to_handler.rb
51
+ - lib/yard-activerecord/associations/has_and_belongs_to_many_handler.rb
52
+ - lib/yard-activerecord/associations/has_many_handler.rb
53
+ - lib/yard-activerecord/associations/has_one_handler.rb
54
+ - lib/yard-activerecord/associations/plural_handler.rb
55
+ - lib/yard-activerecord/associations/singular_handler.rb
56
+ - lib/yard-activerecord/delegations/.DS_Store
57
+ - lib/yard-activerecord/delegations/delegate_handler.rb
58
+ - lib/yard-activerecord/fields/.DS_Store
59
+ - lib/yard-activerecord/fields/create_table_handler.rb
60
+ - lib/yard-activerecord/fields/define_handler.rb
61
+ - lib/yard-activerecord/fields/field_handler.rb
62
+ - lib/yard-activerecord/scopes/.DS_Store
63
+ - lib/yard-activerecord/scopes/scope_handler.rb
64
+ - lib/yard-activerecord/version.rb
65
+ - test.rb
66
+ - yard-activerecord.gemspec
41
67
  homepage: ''
42
68
  licenses: []
43
69
  post_install_message: