meta_commit_ruby_support 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 92e6f234ecea325e18fb4bad8a850b6f3795bc87
4
+ data.tar.gz: bf9067405e0c9ce54551392a2e1ab55d184d3cc2
5
+ SHA512:
6
+ metadata.gz: b557532f65e31701c468c9b3af93a271bc515a678fdeaee5816c97918fbf02bec8f465c0d7dc695b72698e218c28fe99e551abd69448ccbe0be05284f7d8d293
7
+ data.tar.gz: a1ddfefb90359a140b95fca90f1068acb4b3176a19add2cbd3f25816cb449f8c279f6322e3173fb6dd37041e37ddacb2cb48cea2a9b3bf89df5fc97463ffe124
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.15.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at stasdobrovolskiy@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in meta_commit_ruby_support.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Stanislav Dobrovolskiy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # meta_commit ruby support
2
+ [![Build Status](https://travis-ci.org/meta-commit/ruby_support.svg?branch=master)](https://travis-ci.org/meta-commit/ruby_support)
3
+
4
+ This gem adds ruby (version 2.3) support to [meta_commit](https://github.com/usernam3/meta_commit) commands
5
+
6
+ ## Installation
7
+
8
+ Install gem :
9
+
10
+ $ gem install meta_commit_ruby_support
11
+
12
+ ## Usage
13
+
14
+ To add ruby support to meta_commit runner for specific repository you need to :
15
+
16
+ - edit meta_commit.yml file of repo
17
+ - add `ruby_support` to list of extensions
18
+
19
+ Now meta_commit knows that repository requires ruby support and will load this gem
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "meta_commit_ruby_support"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class ChangesInMethod < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE && !old_ast_path.target_node.empty_ast? && !new_ast_path.target_node.empty_ast? && is_in_context_of_method?(old_ast_path) && is_in_context_of_method?(new_ast_path)
5
+ end
6
+
7
+ def string_representation
8
+ if is_in_context_of_class?(@new_ast_path)
9
+ return "changes in #{name_of_context_class(new_ast_path)}##{name_of_context_method(new_ast_path)}"
10
+ end
11
+ "changes in ##{name_of_context_method(new_ast_path)}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class ClassCreation < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_ADDITION && !new_ast_path.target_node.empty_ast? && (new_ast_path.target_node.is_class? || is_name_of_class?(new_ast_path))
5
+ end
6
+
7
+ def string_representation
8
+ if @new_ast_path.target_node.is_class?
9
+ if is_in_context_of_module?(@new_ast_path)
10
+ return "created #{name_of_context_module(new_ast_path)}::#{new_ast_path.target_node.class_name}"
11
+ end
12
+ return "created class #{new_ast_path.class_name}"
13
+ end
14
+ if is_in_context_of_module?(@new_ast_path)
15
+ return "created #{name_of_context_module(new_ast_path)}::#{name_of_context_class(new_ast_path)}"
16
+ end
17
+ "created class #{name_of_context_class(new_ast_path)}"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class ClassDeletion < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_DELETION && !old_ast_path.target_node.empty_ast? && (old_ast_path.target_node.is_class? || is_name_of_class?(old_ast_path))
5
+ end
6
+
7
+ def string_representation
8
+ if @old_ast_path.target_node.is_class?
9
+ if is_in_context_of_module?(@old_ast_path)
10
+ return "removed class #{old_ast_path.target_node.class_name} from module #{name_of_context_module(old_ast_path)}"
11
+ end
12
+ end
13
+ "removed class #{name_of_context_class(old_ast_path)}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class ClassRename < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE && !old_ast_path.target_node.empty_ast? && !new_ast_path.target_node.empty_ast? && is_name_of_class?(old_ast_path) && is_name_of_class?(new_ast_path)
5
+ end
6
+
7
+ def string_representation
8
+ "renamed class #{name_of_context_class(old_ast_path)} to #{name_of_context_class(new_ast_path)}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,144 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ # Base class for diffs
3
+ # @attr [Symbol] diff_type
4
+ # @attr [String] commit_old
5
+ # @attr [String] commit_new
6
+ # @attr [String] old_file
7
+ # @attr [String] new_file
8
+ # @attr [String] old_lineno
9
+ # @attr [String] new_lineno
10
+ # @attr [MetaCommit::Models::ContextualAstNode] old_ast_path
11
+ # @attr [MetaCommit::Models::ContextualAstNode] new_ast_path
12
+ class Diff < MetaCommit::Contracts::Diff
13
+
14
+ TYPE_ADDITION = :addition
15
+ TYPE_DELETION = :deletion
16
+ TYPE_REPLACE = :replace
17
+ SUPPORTED_PARSERS = [MetaCommit::Extension::RubySupport::Parsers::Ruby]
18
+
19
+ attr_accessor :diff_type
20
+ attr_accessor :commit_old, :commit_new
21
+ attr_accessor :old_file, :new_file
22
+ attr_accessor :old_lineno, :new_lineno
23
+ attr_accessor :old_ast_path, :new_ast_path
24
+
25
+ # @param [Class] parser
26
+ # @return [Boolean]
27
+ def supports_parser?(parser)
28
+ SUPPORTED_PARSERS.include?(parser)
29
+ end
30
+
31
+ # @param [Symbol] type
32
+ # @param [String] old_file_name
33
+ # @param [String] new_file_name
34
+ # @param [String] old_ast_path
35
+ # @param [String] new_ast_path
36
+ # @return [Boolean]
37
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
38
+ true
39
+ end
40
+
41
+ # @return [String]
42
+ def inspect
43
+ string_representation
44
+ end
45
+
46
+ # @return [String]
47
+ def to_s
48
+ string_representation
49
+ end
50
+
51
+ # @return [String]
52
+ def string_representation
53
+ "#{diff_type} was performed"
54
+ end
55
+
56
+ # @return [Boolean]
57
+ def type_addition?
58
+ @diff_type == TYPE_ADDITION
59
+ end
60
+
61
+ # @return [Boolean]
62
+ def type_deletion?
63
+ @diff_type == TYPE_DELETION
64
+ end
65
+
66
+ # @return [Boolean]
67
+ def type_replace?
68
+ @diff_type == TYPE_REPLACE
69
+ end
70
+
71
+
72
+ # @param [Object] ast
73
+ # @param [Integer] depth
74
+ # @return [String]
75
+ def path_to_component(ast, depth=nil)
76
+ depth = -1 if depth.nil?
77
+ result = []
78
+ result.concat([name_of_context_module(ast), is_in_context_of_class?(ast) && depth < 1 ? '::' : '']) if is_in_context_of_module?(ast) && depth < 2
79
+ result.concat([name_of_context_class(ast)]) if is_in_context_of_class?(ast) && depth < 1
80
+ result.concat(['#', name_of_context_method(ast)]) if is_in_context_of_method?(ast) && depth < 0
81
+ result.join('')
82
+ end
83
+
84
+ # on created class only first line goes to diff
85
+ # @param [MetaCommit::Model::ContextualAstNode] ast
86
+ def is_name_of_class?(ast)
87
+ (ast.target_node.ast.type == :const) and (ast.context_nodes.length > 1) and (ast.context_nodes[ast.context_nodes.length - 1 - 1].ast.type == :class)
88
+ end
89
+
90
+ # on created module only first line goes to diff
91
+ # @param [MetaCommit::Model::ContextualAstNode] ast
92
+ def is_name_of_module?(ast)
93
+ (ast.target_node.ast.type == :const) and (ast.context_nodes.length > 1) and (ast.context_nodes[ast.context_nodes.length - 1 - 1].ast.type == :module)
94
+ end
95
+
96
+ # @param [MetaCommit::Model::ContextualAstNode] ast
97
+ def name_of_context_module(ast)
98
+ ast.context_nodes.reverse.each do |parent|
99
+ return parent.module_name if parent.is_module?
100
+ end
101
+ end
102
+
103
+ # @param [MetaCommit::Model::ContextualAstNode] ast
104
+ def name_of_context_class(ast)
105
+ ast.context_nodes.reverse.each do |parent|
106
+ return parent.class_name if parent.is_class?
107
+ end
108
+ end
109
+
110
+ # @param [MetaCommit::Model::ContextualAstNode] ast
111
+ def name_of_context_method(ast)
112
+ ast.context_nodes.reverse.each do |parent|
113
+ return parent.method_name if parent.is_method?
114
+ end
115
+ end
116
+
117
+ # @param [MetaCommit::Model::ContextualAstNode] ast
118
+ # @return [Boolean]
119
+ def is_in_context_of_module?(ast)
120
+ ast.context_nodes.each do |parent|
121
+ return true if parent.is_module?
122
+ end
123
+ false
124
+ end
125
+
126
+ # @param [MetaCommit::Model::ContextualAstNode] ast
127
+ # @return [Boolean]
128
+ def is_in_context_of_class?(ast)
129
+ ast.context_nodes.each do |parent|
130
+ return true if parent.is_class?
131
+ end
132
+ false
133
+ end
134
+
135
+ # @param [MetaCommit::Model::ContextualAstNode] ast
136
+ # @return [Boolean]
137
+ def is_in_context_of_method?(ast)
138
+ ast.context_nodes.each do |parent|
139
+ return true if parent.is_method?
140
+ end
141
+ false
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,14 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class InitializeChanged < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE &&
5
+ !old_ast_path.target_node.empty_ast? && !new_ast_path.target_node.empty_ast? &&
6
+ is_in_context_of_method?(old_ast_path) && is_in_context_of_method?(new_ast_path) &&
7
+ name_of_context_method(old_ast_path) == 'initialize' && name_of_context_method(new_ast_path) == 'initialize'
8
+ end
9
+
10
+ def string_representation
11
+ "changes in initialization of #{path_to_component(new_ast_path, 0)}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class MethodCreation < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_ADDITION && !new_ast_path.target_node.empty_ast? && (new_ast_path.target_node.is_method? || is_in_context_of_method?(new_ast_path))
5
+ end
6
+
7
+ def string_representation
8
+ if @new_ast_path.target_node.is_method?
9
+ if is_in_context_of_module?(@new_ast_path)
10
+ if is_in_context_of_class?(@new_ast_path)
11
+ return "created #{name_of_context_module(new_ast_path)}::#{name_of_context_class(new_ast_path)}##{new_ast_path.target_node.method_name}"
12
+ end
13
+ return "created #{name_of_context_module(new_ast_path)}##{new_ast_path.target_node.method_name}"
14
+ end
15
+ if is_in_context_of_class?(@new_ast_path)
16
+ return "created #{name_of_context_class(new_ast_path)}##{new_ast_path.target_node.method_name}"
17
+ end
18
+ end
19
+ "changes in method #{name_of_context_method(new_ast_path)}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class MethodDeletion < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_DELETION && !old_ast_path.target_node.empty_ast? && (old_ast_path.target_node.is_method? || is_in_context_of_method?(old_ast_path))
5
+ end
6
+
7
+ def string_representation
8
+ if @old_ast_path.target_node.is_method?
9
+ if is_in_context_of_module?(@old_ast_path)
10
+ if is_in_context_of_class?(@old_ast_path)
11
+ return "removed #{name_of_context_module(old_ast_path)}::#{name_of_context_class(old_ast_path)}##{old_ast_path.target_node.method_name}"
12
+ end
13
+ return "removed method #{old_ast_path.target_node.method_name} from module #{name_of_context_module(old_ast_path)}"
14
+ end
15
+ if is_in_context_of_class?(@old_ast_path)
16
+ return "removed #{name_of_context_class(old_ast_path)}##{old_ast_path.target_node.method_name}"
17
+ end
18
+ end
19
+ "changes in method #{name_of_context_method(old_ast_path)}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class ModuleCreation < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_ADDITION && !new_ast_path.target_node.empty_ast? && (new_ast_path.target_node.is_module? || is_name_of_module?(new_ast_path))
5
+ end
6
+
7
+ def string_representation
8
+ if @new_ast_path.target_node.is_module?
9
+ return "created module #{new_ast_path.target_node.module_name}"
10
+ end
11
+ "created module #{name_of_context_module(new_ast_path)}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class ModuleDeletion < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_DELETION && !old_ast_path.target_node.empty_ast? && (old_ast_path.target_node.is_module? || is_name_of_module?(old_ast_path))
5
+ end
6
+
7
+ def string_representation
8
+ if @old_ast_path.target_node.is_module?
9
+ return "removed module #{old_ast_path.target_node.module_name}"
10
+ end
11
+ "removed module #{name_of_context_module(old_ast_path)}"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module MetaCommit::Extension::RubySupport::Diffs
2
+ class ModuleRename < Diff
3
+ def supports_change(type, old_file_name, new_file_name, old_ast_path, new_ast_path)
4
+ type == MetaCommit::Extension::RubySupport::Diffs::Diff::TYPE_REPLACE && !old_ast_path.target_node.empty_ast? && !new_ast_path.target_node.empty_ast? && is_name_of_module?(old_ast_path) && is_name_of_module?(new_ast_path)
5
+ end
6
+
7
+ def string_representation
8
+ "renamed module #{name_of_context_module(old_ast_path)} to #{name_of_context_module(new_ast_path)}"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ module MetaCommit::Extension::RubySupport
2
+ # Package interface
3
+ class Locator < MetaCommit::Contracts::Locator
4
+ # @return [Array] parser classes that package provides
5
+ def parsers
6
+ [
7
+ MetaCommit::Extension::RubySupport::Parsers::Ruby,
8
+ ]
9
+ end
10
+
11
+ # @return [Array] diff classes that package provides
12
+ def diffs
13
+ [
14
+ MetaCommit::Extension::RubySupport::Diffs::InitializeChanged,
15
+ MetaCommit::Extension::RubySupport::Diffs::ClassCreation,
16
+ MetaCommit::Extension::RubySupport::Diffs::ClassDeletion,
17
+ MetaCommit::Extension::RubySupport::Diffs::ClassRename,
18
+ MetaCommit::Extension::RubySupport::Diffs::MethodCreation,
19
+ MetaCommit::Extension::RubySupport::Diffs::MethodDeletion,
20
+ MetaCommit::Extension::RubySupport::Diffs::ChangesInMethod,
21
+ MetaCommit::Extension::RubySupport::Diffs::ModuleCreation,
22
+ MetaCommit::Extension::RubySupport::Diffs::ModuleDeletion,
23
+ MetaCommit::Extension::RubySupport::Diffs::ModuleRename,
24
+ MetaCommit::Extension::RubySupport::Diffs::Diff,
25
+ ]
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,74 @@
1
+ module MetaCommit::Extension::RubySupport::Models
2
+ # Adapter which implements MetaCommit::Contracts::Ast contract and wraps Parser::AST::Node
3
+ # @attr [Array<Parser::AST::Node>] ast
4
+ class Ast < MetaCommit::Contracts::Ast
5
+ attr_reader :ast
6
+
7
+ # @param [Parser::AST::Node] ast
8
+ def initialize(ast)
9
+ @ast = ast
10
+ end
11
+
12
+ # @return [Array<MetaCommit::Contracts::Ast>]
13
+ def children
14
+ @ast.children
15
+ .map {|child| Ast.new(child)}
16
+ end
17
+
18
+ # @return [Integer]
19
+ def first_line
20
+ return unless @ast.respond_to?(:location)
21
+ begin
22
+ return @ast.location.first_line
23
+ rescue NoMethodError
24
+ return nil
25
+ end
26
+ end
27
+
28
+ # @return [Integer]
29
+ def last_line
30
+ return unless @ast.respond_to?(:location)
31
+ begin
32
+ return @ast.location.last_line
33
+ rescue NoMethodError
34
+ return nil
35
+ end
36
+ end
37
+
38
+ # @return [Boolean]
39
+ def empty_ast?
40
+ @ast.nil?
41
+ end
42
+
43
+ # @return [Boolean]
44
+ def is_module?
45
+ @ast.type == :module
46
+ end
47
+
48
+ # @return [Boolean]
49
+ def is_class?
50
+ @ast.type == :class
51
+ end
52
+
53
+ # @return [Boolean]
54
+ def is_method?
55
+ @ast.type == :def
56
+ end
57
+
58
+ # @return [String]
59
+ def module_name
60
+ @ast.children.first.children.last.to_s
61
+ end
62
+
63
+ # @return [String]
64
+ def class_name
65
+ @ast.children.first.children.last.to_s
66
+ end
67
+
68
+ # @return [String]
69
+ def method_name
70
+ @ast.children.first.to_s
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,38 @@
1
+ require "parser/current"
2
+
3
+ module MetaCommit::Extension::RubySupport::Parsers
4
+ class Ruby < MetaCommit::Contracts::Parser
5
+
6
+ # @return [Array<String>]
7
+ def self.supported_file_extensions
8
+ ['rb']
9
+ end
10
+
11
+ # @return [Boolean]
12
+ def self.supports_syntax?(source_code)
13
+ begin
14
+ Parser::CurrentRuby.parse(source_code)
15
+ rescue Parser::SyntaxError
16
+ return false
17
+ end
18
+ true
19
+ end
20
+
21
+ # @param [String] source_code
22
+ # @return [MetaCommit::Extension::RubySupport::Models::Ast]
23
+ def parse(source_code)
24
+ begin
25
+ parsed_ast = parser.parse(source_code)
26
+ MetaCommit::Extension::RubySupport::Models::Ast.new(parsed_ast)
27
+ rescue Parser::SyntaxError
28
+ raise MetaCommit::Contracts::Errors::SourceCodeParsingError.new("can't parse '#{source_code}' using #{self.class}")
29
+ end
30
+ end
31
+
32
+ def parser
33
+ @parser ||= Parser::CurrentRuby
34
+ end
35
+
36
+ protected :parser
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ module MetaCommit
2
+ module Extension
3
+ module RubySupport
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ require "meta_commit_ruby_support/version"
2
+
3
+ module MetaCommit
4
+ module Extension
5
+ module RubySupport
6
+ end
7
+ end
8
+ end
9
+
10
+ require "meta_commit_contracts"
11
+ # parsers
12
+ require "meta_commit_ruby_support/parsers/ruby"
13
+ # diffs
14
+ require "meta_commit_ruby_support/diffs/diff"
15
+ require "meta_commit_ruby_support/diffs/class_creation"
16
+ require "meta_commit_ruby_support/diffs/class_deletion"
17
+ require "meta_commit_ruby_support/diffs/class_rename"
18
+ require "meta_commit_ruby_support/diffs/method_creation"
19
+ require "meta_commit_ruby_support/diffs/method_deletion"
20
+ require "meta_commit_ruby_support/diffs/changes_in_method"
21
+ require "meta_commit_ruby_support/diffs/module_creation"
22
+ require "meta_commit_ruby_support/diffs/module_deletion"
23
+ require "meta_commit_ruby_support/diffs/module_rename"
24
+ require "meta_commit_ruby_support/diffs/initialize_changed"
25
+ # models
26
+ require "meta_commit_ruby_support/models/ast"
27
+
28
+ require "meta_commit_ruby_support/locator"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "meta_commit_ruby_support/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "meta_commit_ruby_support"
8
+ spec.version = MetaCommit::Extension::RubySupport::VERSION
9
+ spec.authors = ["Stanislav Dobrovolskiy"]
10
+ spec.email = ["uusername@protonmail.ch"]
11
+
12
+ spec.summary = %q{meta_commit extension adds ruby language support}
13
+ spec.homepage = "https://github.com/meta_commit/ruby_support"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^(test|spec|features)/})}
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_runtime_dependency "meta_commit_contracts", "~> 0.1.2"
20
+ spec.add_runtime_dependency "parser", "2.3.0"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.15"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.6"
25
+ spec.add_development_dependency "rspec-mocks", "~> 3.6"
26
+ spec.add_development_dependency "coveralls", "~> 0.8"
27
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meta_commit_ruby_support
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Stanislav Dobrovolskiy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: meta_commit_contracts
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: parser
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 2.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-mocks
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.8'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.8'
111
+ description:
112
+ email:
113
+ - uusername@protonmail.ch
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/meta_commit_ruby_support.rb
129
+ - lib/meta_commit_ruby_support/diffs/changes_in_method.rb
130
+ - lib/meta_commit_ruby_support/diffs/class_creation.rb
131
+ - lib/meta_commit_ruby_support/diffs/class_deletion.rb
132
+ - lib/meta_commit_ruby_support/diffs/class_rename.rb
133
+ - lib/meta_commit_ruby_support/diffs/diff.rb
134
+ - lib/meta_commit_ruby_support/diffs/initialize_changed.rb
135
+ - lib/meta_commit_ruby_support/diffs/method_creation.rb
136
+ - lib/meta_commit_ruby_support/diffs/method_deletion.rb
137
+ - lib/meta_commit_ruby_support/diffs/module_creation.rb
138
+ - lib/meta_commit_ruby_support/diffs/module_deletion.rb
139
+ - lib/meta_commit_ruby_support/diffs/module_rename.rb
140
+ - lib/meta_commit_ruby_support/locator.rb
141
+ - lib/meta_commit_ruby_support/models/ast.rb
142
+ - lib/meta_commit_ruby_support/parsers/ruby.rb
143
+ - lib/meta_commit_ruby_support/version.rb
144
+ - meta_commit_ruby_support.gemspec
145
+ homepage: https://github.com/meta_commit/ruby_support
146
+ licenses:
147
+ - MIT
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.5.1
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: meta_commit extension adds ruby language support
169
+ test_files: []