mudguard 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64fb401ff5f77f335af75d7c170a03be012b6ee2a366fb45ddef276e897f8da8
4
- data.tar.gz: c14cd31398dd33c3838f07ddcb8b5c09c0c08cf3e57f046c89f6069fa7679aef
3
+ metadata.gz: 704ed528bcdd940b57ef601a5841eb5585ba5a32b2ef2ae9c184e8f544daba00
4
+ data.tar.gz: 18603a36e5cc7e95569d3c184df7ec9955ec6d11f1cb299ad9790b20d09f4b88
5
5
  SHA512:
6
- metadata.gz: 7173bd1ae058ace1f8b3f86909d7b8de3c0229b5886041f8922b777f37ab58ed6d2617d7488dd9813421f2eaa4d723c1bf64dd14b21f0ea9a5a20a986e1d432c
7
- data.tar.gz: 86bc09949d76af31395484859911a29d5f8dd6b2d9f6963ce1c7415e7b4a8d4ef92a347e8155e6b1784f881c779841c7625e81577812b669a3a0673b780c06a7
6
+ metadata.gz: f136a1d09aa59ffc8f71a842cfef6b513ac1c381d4fe09d7a0660921008b7780f5e595782d343c27f6899d9edd6fe3af6729a3b12bc15aff183129455aa1a36e
7
+ data.tar.gz: 51bc6a0961d73cfad36c32d359c34a22eb0faaf31bf38ca67cbba7c626f6995a25267c3004776744dcacd7b15779e9c1b0778e0ac7c5633ef40ff9c045a1a04c
data/.rubocop.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  AllCops:
2
2
  Exclude:
3
3
  - 'bin/*'
4
+ - 'spec/lib/test_projects/**/*.rb'
4
5
 
5
6
  Style/StringLiterals:
6
7
  EnforcedStyle: double_quotes
@@ -9,6 +10,7 @@ Metrics/BlockLength:
9
10
  Exclude:
10
11
  - 'spec/**/*.rb'
11
12
  - 'lib/tasks/**/*.rake'
13
+ - 'mudguard.gemspec'
12
14
 
13
15
  Style/Documentation:
14
16
  Exclude:
@@ -22,3 +24,7 @@ Style/HashTransformKeys:
22
24
 
23
25
  Style/HashTransformValues:
24
26
  Enabled: true
27
+
28
+ Layout/LineLength:
29
+ Description: 'Limit lines to 100 characters.'
30
+ Max: 100
data/Gemfile.lock CHANGED
@@ -1,19 +1,59 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mudguard (0.1.0)
4
+ mudguard (0.1.1)
5
+ parser (~> 2.7)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  ast (2.4.0)
11
+ byebug (11.0.1)
12
+ coderay (1.1.2)
10
13
  diff-lcs (1.3)
14
+ ffi (1.12.2)
15
+ formatador (0.2.5)
16
+ guard (2.16.1)
17
+ formatador (>= 0.2.4)
18
+ listen (>= 2.7, < 4.0)
19
+ lumberjack (>= 1.0.12, < 2.0)
20
+ nenv (~> 0.1)
21
+ notiffany (~> 0.0)
22
+ pry (>= 0.9.12)
23
+ shellany (~> 0.0)
24
+ thor (>= 0.18.1)
25
+ guard-compat (1.2.1)
26
+ guard-rspec (4.7.3)
27
+ guard (~> 2.1)
28
+ guard-compat (~> 1.1)
29
+ rspec (>= 2.99.0, < 4.0)
11
30
  jaro_winkler (1.5.4)
31
+ listen (3.2.1)
32
+ rb-fsevent (~> 0.10, >= 0.10.3)
33
+ rb-inotify (~> 0.9, >= 0.9.10)
34
+ lumberjack (1.2.4)
35
+ method_source (0.9.2)
36
+ nenv (0.3.0)
37
+ notiffany (0.1.3)
38
+ nenv (~> 0.1)
39
+ shellany (~> 0.0)
12
40
  parallel (1.19.1)
13
41
  parser (2.7.0.4)
14
42
  ast (~> 2.4.0)
43
+ pry (0.12.2)
44
+ coderay (~> 1.1.0)
45
+ method_source (~> 0.9.0)
46
+ pry-byebug (3.7.0)
47
+ byebug (~> 11.0)
48
+ pry (~> 0.10)
49
+ pry-doc (1.0.0)
50
+ pry (~> 0.11)
51
+ yard (~> 0.9.11)
15
52
  rainbow (3.0.0)
16
- rake (10.5.0)
53
+ rake (13.0.1)
54
+ rb-fsevent (0.10.3)
55
+ rb-inotify (0.10.1)
56
+ ffi (~> 1.0)
17
57
  rexml (3.2.4)
18
58
  rspec (3.9.0)
19
59
  rspec-core (~> 3.9.0)
@@ -37,17 +77,25 @@ GEM
37
77
  ruby-progressbar (~> 1.7)
38
78
  unicode-display_width (>= 1.4.0, < 1.7)
39
79
  ruby-progressbar (1.10.1)
80
+ shellany (0.0.1)
81
+ thor (1.0.1)
40
82
  unicode-display_width (1.6.1)
83
+ yard (0.9.24)
41
84
 
42
85
  PLATFORMS
43
86
  ruby
44
87
 
45
88
  DEPENDENCIES
46
89
  bundler (~> 2.0)
90
+ guard (~> 2.1)
91
+ guard-rspec (~> 4.7)
47
92
  mudguard!
48
- rake (~> 10.0)
49
- rspec (~> 3.0)
50
- rubocop
93
+ pry (~> 0.12)
94
+ pry-byebug (~> 3.7)
95
+ pry-doc (~> 1.0)
96
+ rake (~> 13.0)
97
+ rspec (~> 3.9)
98
+ rubocop (~> 0.80)
51
99
 
52
100
  BUNDLED WITH
53
101
  2.1.4
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ rspec_options = {
4
+ cmd: "rspec",
5
+ notification: false,
6
+ failed_mode: :focus
7
+ }
8
+
9
+ guard "rspec", rspec_options do
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^lib/mudguard/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
12
+ watch(%r{^lib/mudguard/(.+)\.rb$}) { |m| Dir.glob("spec/lib/#{m[1]}_*.rb") }
13
+ watch("spec/spec_helper.rb") { "spec" }
14
+ end
data/bin/_guard-core ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application '_guard-core' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("guard", "_guard-core")
data/bin/guard ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'guard' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("guard", "guard")
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mudguard
4
+ class Error < StandardError
5
+ end
6
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby_analyser"
4
+
5
+ module Mudguard
6
+ # Contains the policies to be enforced
7
+ class Policies
8
+ def initialize(policies: [])
9
+ @policies = policies.map { |l| l.gsub(/\s/, "") }.map { |p| /^#{p}/ }
10
+ end
11
+
12
+ def check(sources)
13
+ sources.all? do |source|
14
+ dependencies = RubyAnalyser.find_mod_dependencies(source)
15
+ dependencies.all? do |d|
16
+ @policies.any? do |p|
17
+ d.match?(p)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "policies"
4
+
5
+ module Mudguard
6
+ # A file containing the Mudguard-Policies
7
+ class PolicyFile
8
+ def self.read(policy_file)
9
+ policy_exists = File.exist?(policy_file)
10
+
11
+ raise Error, "expected policy file #{policy_file} doesn't exists" unless policy_exists
12
+
13
+ Policies.new(policies: File.readlines(policy_file))
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "parser/current"
4
+
5
+ module Mudguard
6
+ # Analyses Ruby-Source and returns extracted information
7
+ class RubyAnalyser
8
+ class << self
9
+ def find_mod_dependencies(source)
10
+ begin
11
+ root = Parser::CurrentRuby.parse(source)
12
+ rescue Parser::SyntaxError
13
+ return []
14
+ end
15
+ return [] if root.nil?
16
+
17
+ process(root)
18
+ end
19
+
20
+ private
21
+
22
+ def process(node, module_name = "")
23
+ case node
24
+ when type?(:module)
25
+ process_module(node.children)
26
+ when type?(:class)
27
+ process_class(node.children, module_name)
28
+ when type?(:const)
29
+ ["#{module_name}->#{find_const_name(node.children)}"]
30
+ else
31
+ ignore_and_continue(node, module_name)
32
+ end
33
+ end
34
+
35
+ def ignore_and_continue(node, module_name)
36
+ case node
37
+ when children?
38
+ node.children.flat_map { |c| process(c, module_name) }
39
+ else
40
+ []
41
+ end
42
+ end
43
+
44
+ def process_module(children)
45
+ module_name = find_const_name(children[0].children)
46
+ process(children[1], module_name)
47
+ end
48
+
49
+ def process_class(children, module_name)
50
+ process(children[1], module_name)
51
+ end
52
+
53
+ def find_const_name(children)
54
+ return nil if children.nil?
55
+
56
+ module_name = find_const_name(children[0]&.children)
57
+ const_name = children[1].to_s
58
+ if module_name.nil?
59
+ const_name
60
+ else
61
+ "#{module_name}::#{const_name}"
62
+ end
63
+ end
64
+
65
+ def children?
66
+ ->(n) { n.respond_to?(:children) }
67
+ end
68
+
69
+ def type?(type)
70
+ ->(n) { n.respond_to?(:type) && n.type == type }
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mudguard
4
+ # Provides access to all ruby-files of a project
5
+ class RubyFiles
6
+ class << self
7
+ def all(project_path)
8
+ project_exists = Dir.exist?(project_path)
9
+
10
+ raise Error, "expected project #{project_path} doesn't exists" unless project_exists
11
+
12
+ ruby_files = File.join(project_path, "**", "*.rb")
13
+ Dir.glob(ruby_files).lazy
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mudguard
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/mudguard.rb CHANGED
@@ -1,8 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "mudguard/version"
4
+ require_relative "mudguard/policy_file"
5
+ require_relative "mudguard/ruby_files"
4
6
 
7
+ # Contains methods to check if your project is a bit muddy
5
8
  module Mudguard
6
- class Error < StandardError; end
7
- # Your code goes here...
9
+ class << self
10
+ def check(project_path)
11
+ policy_file_path = File.expand_path("MudguardFile", project_path)
12
+ policies = PolicyFile.read(policy_file_path)
13
+
14
+ files = RubyFiles.all(project_path).map { |f| File.read(f) }
15
+
16
+ policies.check(files)
17
+ end
18
+ end
8
19
  end
data/mudguard.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ["Jorg Jenni"]
11
11
  spec.email = ["jorg.jenni@jennius.co.uk"]
12
12
 
13
- spec.summary = "mudguard helps with your ruby project not becoming a "\
13
+ spec.summary = "mudguard helps your ruby project not becoming a "\
14
14
  "'Big ball of mud'"
15
15
  spec.homepage = "https://gibhub.com/Enceradeira/mudguard"
16
16
  spec.license = "MIT"
@@ -30,7 +30,14 @@ Gem::Specification.new do |spec|
30
30
  spec.require_paths = ["lib"]
31
31
 
32
32
  spec.add_development_dependency "bundler", "~> 2.0"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
- spec.add_development_dependency "rspec", "~> 3.0"
35
- spec.add_development_dependency "rubocop"
33
+ spec.add_development_dependency "guard", "~> 2.1"
34
+ spec.add_development_dependency "guard-rspec", "~> 4.7"
35
+ spec.add_development_dependency "pry", "~>0.12"
36
+ spec.add_development_dependency "pry-byebug", "~>3.7"
37
+ spec.add_development_dependency "pry-doc", "~>1.0"
38
+ spec.add_development_dependency "rake", "~>13.0"
39
+ spec.add_development_dependency "rspec", "~> 3.9"
40
+ spec.add_development_dependency "rubocop", "~>0.80"
41
+
42
+ spec.add_dependency "parser", "~>2.7"
36
43
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mudguard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorg Jenni
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-08 00:00:00.000000000 Z
11
+ date: 2020-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,48 +24,132 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '4.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '4.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-doc
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
27
97
  - !ruby/object:Gem::Dependency
28
98
  name: rake
29
99
  requirement: !ruby/object:Gem::Requirement
30
100
  requirements:
31
101
  - - "~>"
32
102
  - !ruby/object:Gem::Version
33
- version: '10.0'
103
+ version: '13.0'
34
104
  type: :development
35
105
  prerelease: false
36
106
  version_requirements: !ruby/object:Gem::Requirement
37
107
  requirements:
38
108
  - - "~>"
39
109
  - !ruby/object:Gem::Version
40
- version: '10.0'
110
+ version: '13.0'
41
111
  - !ruby/object:Gem::Dependency
42
112
  name: rspec
43
113
  requirement: !ruby/object:Gem::Requirement
44
114
  requirements:
45
115
  - - "~>"
46
116
  - !ruby/object:Gem::Version
47
- version: '3.0'
117
+ version: '3.9'
48
118
  type: :development
49
119
  prerelease: false
50
120
  version_requirements: !ruby/object:Gem::Requirement
51
121
  requirements:
52
122
  - - "~>"
53
123
  - !ruby/object:Gem::Version
54
- version: '3.0'
124
+ version: '3.9'
55
125
  - !ruby/object:Gem::Dependency
56
126
  name: rubocop
57
127
  requirement: !ruby/object:Gem::Requirement
58
128
  requirements:
59
- - - ">="
129
+ - - "~>"
60
130
  - !ruby/object:Gem::Version
61
- version: '0'
131
+ version: '0.80'
62
132
  type: :development
63
133
  prerelease: false
64
134
  version_requirements: !ruby/object:Gem::Requirement
65
135
  requirements:
66
- - - ">="
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.80'
139
+ - !ruby/object:Gem::Dependency
140
+ name: parser
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.7'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
67
151
  - !ruby/object:Gem::Version
68
- version: '0'
152
+ version: '2.7'
69
153
  description:
70
154
  email:
71
155
  - jorg.jenni@jennius.co.uk
@@ -80,18 +164,27 @@ files:
80
164
  - CODE_OF_CONDUCT.md
81
165
  - Gemfile
82
166
  - Gemfile.lock
167
+ - Guardfile
83
168
  - LICENSE.txt
84
169
  - README.md
85
170
  - Rakefile
171
+ - bin/_guard-core
86
172
  - bin/console
173
+ - bin/guard
87
174
  - bin/rake
88
175
  - bin/rubocop
89
176
  - bin/setup
90
177
  - lib/mudguard.rb
178
+ - lib/mudguard/error.rb
179
+ - lib/mudguard/policies.rb
180
+ - lib/mudguard/policy_file.rb
181
+ - lib/mudguard/ruby_analyser.rb
182
+ - lib/mudguard/ruby_files.rb
91
183
  - lib/mudguard/version.rb
92
184
  - lib/tasks/rubocop.rake
93
185
  - lib/tasks/test.rake
94
186
  - mudguard.gemspec
187
+ - pkg/mudguard-0.1.0.gem
95
188
  homepage: https://gibhub.com/Enceradeira/mudguard
96
189
  licenses:
97
190
  - MIT
@@ -117,5 +210,5 @@ rubyforge_project:
117
210
  rubygems_version: 2.7.6
118
211
  signing_key:
119
212
  specification_version: 4
120
- summary: mudguard helps with your ruby project not becoming a 'Big ball of mud'
213
+ summary: mudguard helps your ruby project not becoming a 'Big ball of mud'
121
214
  test_files: []