yard-sequel 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 073ce59843dbdb8f357321e2deabfa0b201c064d
4
+ data.tar.gz: 1797e658e7baa1ef8fa21aa58bac9f45c9ec2958
5
+ SHA512:
6
+ metadata.gz: a29270319e1ed42d99f0d90658a525b704568831f59d35ed70a10b551e45db5f497294b7e073b0c45c1dc3c360d4d9dd30e2da9529dd576c55ec151d5cd8b2ef
7
+ data.tar.gz: 5543778bc9c3d94c1f1aace225bd0707cf40e6661a8b76ca209e7109e8c6620046b4ed4917c11abd345797d3ba3d9691607dcdbf6ec39dd89ea588171d7969f2
data/.yardopts ADDED
@@ -0,0 +1,5 @@
1
+ --title "YARD Sequel Plugin"
2
+ --no-private
3
+ --protected
4
+ --markup markdown
5
+ lib/**/*.rb
@@ -0,0 +1,20 @@
1
+ require 'sequel'
2
+ require 'yard'
3
+
4
+ Sequel.extension :inflector
5
+
6
+ # The YARD base module
7
+ module YARD
8
+ # The YARD handlers module
9
+ module Handlers
10
+ # The module for YARD ruby handlers
11
+ module Ruby
12
+ # Module for documenting Sequel code.
13
+ # @author Kai Moschcau
14
+ module Sequel
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ require_relative 'yard-sequel/associations'
@@ -0,0 +1,18 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module Sequel
5
+ # Module for documention Sequel associations.
6
+ # @author Kai Moschcau
7
+ module Associations
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+
14
+ require_relative 'associations/association_handler'
15
+ require_relative 'associations/mixins'
16
+
17
+ require_relative 'associations/many_to_one_handler'
18
+ require_relative 'associations/one_to_many_handler'
@@ -0,0 +1,101 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module Sequel
5
+ module Associations
6
+ # The basic method handler class for Sequel associations.
7
+ # @author Kai Moschcau
8
+ class AssociationHandler < YARD::Handlers::Ruby::MethodHandler
9
+ protected
10
+
11
+ # Adds a parameter tag to a method object.
12
+ # @param [YARD::CodeObjects::MethodObject] method
13
+ # The method to add the parameter tag to.
14
+ # @param [String] name The name of the parameter.
15
+ # @param [String] class_name The class name of the parameter.
16
+ # @param [String] description The description of the parameter.
17
+ # @return [void]
18
+ def add_param_tag(method, name, class_name, description)
19
+ method.parameters << [name, nil]
20
+ method.docstring.add_tag(
21
+ YARD::Tags::Tag.new(
22
+ :param,
23
+ description,
24
+ class_name,
25
+ name
26
+ )
27
+ )
28
+ end
29
+
30
+ # @return [String] the name of the association
31
+ def association_name
32
+ @statement.parameters.first.jump(:ident).source
33
+ end
34
+
35
+ # @param [String] name The name of the method object.
36
+ # @return [YARD::CodeObjects::MethodObject] a method object.
37
+ def create_method_object(name)
38
+ method = YARD::CodeObjects::MethodObject.new(
39
+ namespace,
40
+ name
41
+ )
42
+ register_and_tag(method)
43
+ method
44
+ end
45
+
46
+ # Sets or replaces the return tag on a passed method object.
47
+ # @param (see #void_return_tag)
48
+ # @param [String] class_name The class name of the return value.
49
+ # @param [String] description The description of the return value.
50
+ # @return (see #void_return_tag)
51
+ def return_tag(method, class_name, description)
52
+ method.docstring.delete_tags(:return)
53
+ method.docstring.add_tag(
54
+ YARD::Tags::Tag.new(
55
+ :return,
56
+ description,
57
+ class_name
58
+ )
59
+ )
60
+ end
61
+
62
+ # Sets or replaces the return tag on a passed method object with a
63
+ # void return tag.
64
+ # @param [YARD::CodeObjects::MethodObject] method
65
+ # The method object to set the return tag on.
66
+ # @return [void]
67
+ def void_return_tag(method)
68
+ method.docstring.delete_tags(:return)
69
+ method.docstring.add_tag(
70
+ YARD::Tags::Tag.new(
71
+ :return,
72
+ nil,
73
+ 'void'
74
+ )
75
+ )
76
+ end
77
+
78
+ private
79
+
80
+ # Registers the source of a given method object and sets some tags.
81
+ # @param [YARD::CodeObjects::MethodObject] method
82
+ # The method object to register and tag.
83
+ # @return [void]
84
+ def register_and_tag(method)
85
+ unless method.is_a? YARD::CodeObjects::MethodObject
86
+ raise(
87
+ ArgumentError,
88
+ 'The given method has to be a '\
89
+ "#{YARD::CodeObjects::MethodObject}"
90
+ )
91
+ end
92
+ register(method)
93
+ method.dynamic = true
94
+ method[:sequel] = :association
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,26 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module Sequel
5
+ module Associations
6
+ # The handler class for Sequel many_to_one associations.
7
+ # @author Kai Moschcau
8
+ class ManyToOneHandler < AssociationHandler
9
+ include YARD::Handlers::Ruby::Sequel::Associations::DatasetMethod
10
+ include YARD::Handlers::Ruby::Sequel::Associations::ToOneMethods
11
+
12
+ handles method_call(:many_to_one)
13
+ namespace_only
14
+
15
+ process do
16
+ create_to_one_getter
17
+ create_to_one_setter
18
+
19
+ create_dataset_method
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'mixins/dataset_method'
2
+ require_relative 'mixins/to_many_methods'
3
+ require_relative 'mixins/to_one_methods'
@@ -0,0 +1,25 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module Sequel
5
+ module Associations
6
+ # Provides methods for creating the dataset method object.
7
+ # @author Kai Moschcau
8
+ module DatasetMethod
9
+ # @return [YARD::CodeObjects::MethodObject] the dataset method
10
+ # object.
11
+ def create_dataset_method
12
+ method = create_method_object("#{association_name}_dataset")
13
+ return_tag(
14
+ method,
15
+ 'Sequel::Dataset',
16
+ 'the association\'s dataset.'
17
+ )
18
+ method
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,78 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module Sequel
5
+ module Associations
6
+ # Provides methods for creating the to_many method objects.
7
+ # @author Kai Moschcau
8
+ module ToManyMethods
9
+ # @return [YARD::CodeObjects::MethodObject] the to_many adder method
10
+ # object.
11
+ def create_to_many_adder
12
+ name = association_name
13
+ method = create_method_object("add_#{name.singularize}")
14
+ method.docstring += "Associates the passed #{name.classify} "\
15
+ 'with `self`.'
16
+ add_param_tag(
17
+ method,
18
+ name.singularize,
19
+ name.classify,
20
+ "The #{name.classify} to associate with `self`."
21
+ )
22
+ return_tag(
23
+ method,
24
+ name.classify,
25
+ "the associated #{name.classify}."
26
+ )
27
+ method
28
+ end
29
+
30
+ # @return [YARD::CodeObjects::MethodObject] the to_many clearer
31
+ # method object.
32
+ def create_to_many_clearer
33
+ name = association_name
34
+ method = create_method_object("remove_all_#{name}")
35
+ method.docstring += 'Removes the association of all '\
36
+ "#{name.classify.pluralize} with `self`."
37
+ void_return_tag(method)
38
+ method
39
+ end
40
+
41
+ # @return [YARD::CodeObjects::MethodObject] the to_many getter
42
+ # method object.
43
+ def create_to_many_getter
44
+ name = association_name
45
+ method = create_method_object(name)
46
+ return_tag(
47
+ method,
48
+ "Array<#{name.classify}>",
49
+ "the associated #{name.classify.pluralize}."
50
+ )
51
+ method
52
+ end
53
+
54
+ # @return [YARD::CodeObjects::MethodObject] the to_many remover
55
+ # method object.
56
+ def create_to_many_remover
57
+ name = association_name
58
+ method = create_method_object(
59
+ "remove_#{name.singularize}"
60
+ )
61
+ method.docstring += 'Removes the association of the passed '\
62
+ "#{name.classify} with `self`."
63
+ add_param_tag(
64
+ method,
65
+ name.singularize,
66
+ name.classify,
67
+ "The #{name.classify} to remove the association with `self` "\
68
+ 'from.'
69
+ )
70
+ void_return_tag(method)
71
+ method
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,47 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module Sequel
5
+ module Associations
6
+ # Provides methods for creating the to_one method objects.
7
+ # @author Kai Moschcau
8
+ module ToOneMethods
9
+ # @return [YARD::CodeObjects::MethodObject] the to_one getter method
10
+ # object.
11
+ def create_to_one_getter
12
+ name = association_name
13
+ method = create_method_object(name)
14
+ return_tag(
15
+ method,
16
+ name.classify,
17
+ "the associated #{name.classify}."
18
+ )
19
+ method
20
+ end
21
+
22
+ # @return [YARD::CodeObjects::MethodObject] the to_one setter method
23
+ # object.
24
+ def create_to_one_setter
25
+ name = association_name
26
+ method = create_method_object("#{name}=")
27
+ method.docstring += "Associates the passed #{name.classify} "\
28
+ 'with `self`.'
29
+ add_param_tag(
30
+ method,
31
+ name,
32
+ name.classify,
33
+ "The #{name.classify} to associate with `self`."
34
+ )
35
+ return_tag(
36
+ method,
37
+ name.classify,
38
+ "the associated #{name.classify}."
39
+ )
40
+ method
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,28 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module Sequel
5
+ module Associations
6
+ # The handler class for Sequel one_to_many associations.
7
+ # @author Kai Moschcau
8
+ class OneToManyHandler < AssociationHandler
9
+ include YARD::Handlers::Ruby::Sequel::Associations::DatasetMethod
10
+ include YARD::Handlers::Ruby::Sequel::Associations::ToManyMethods
11
+
12
+ handles method_call(:one_to_many)
13
+ namespace_only
14
+
15
+ process do
16
+ create_to_many_adder
17
+ create_to_many_clearer
18
+ create_to_many_getter
19
+ create_to_many_remover
20
+
21
+ create_dataset_method
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,22 @@
1
+ module YARD
2
+ module Handlers
3
+ module Ruby
4
+ module Sequel
5
+ # The major version number.
6
+ # Used for changes that are not backwards compatible.
7
+ V_MAJOR = 0
8
+
9
+ # The minor version number.
10
+ # Used for changes that are backwards compatible.
11
+ V_MINOR = 1
12
+
13
+ # The build version number.
14
+ # Used for internal changes.
15
+ V_BUILD = 0
16
+
17
+ # The version of the Sequel models.
18
+ VERSION = Gem::Version.new("#{V_MAJOR}.#{V_MINOR}.#{V_BUILD}")
19
+ end
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard-sequel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kai Moschcau
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awesome_print
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '9.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '9.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '11.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sequel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.41'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.41'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ description: This gem provides automatic YARD documentation for theSequel Gem.
98
+ email: kai.moschcau@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".yardopts"
104
+ - lib/yard-sequel.rb
105
+ - lib/yard-sequel/associations.rb
106
+ - lib/yard-sequel/associations/association_handler.rb
107
+ - lib/yard-sequel/associations/many_to_one_handler.rb
108
+ - lib/yard-sequel/associations/mixins.rb
109
+ - lib/yard-sequel/associations/mixins/dataset_method.rb
110
+ - lib/yard-sequel/associations/mixins/to_many_methods.rb
111
+ - lib/yard-sequel/associations/mixins/to_one_methods.rb
112
+ - lib/yard-sequel/associations/one_to_many_handler.rb
113
+ - lib/yard-sequel/version.rb
114
+ homepage:
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - "~>"
125
+ - !ruby/object:Gem::Version
126
+ version: '2.3'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.5.1
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Provides automatic YARD documentation for Sequel Gem
138
+ test_files: []