mini-guard 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f001b81ccfda3679858442acc17dba4336286c6b67ecd4da8df944cfe1046408
4
+ data.tar.gz: 8ecb04d9008f39f645f9174fb6aac0aeeda468104c842e2875a9c075187ff40d
5
+ SHA512:
6
+ metadata.gz: a05f931a4244988d2e58ffe596c46ac057272f96c17122ba41fda050037ff7682a78b76929c1fe64fe6f6b352feb9bbafe5ffd771d319315e7bff53a78946b26
7
+ data.tar.gz: da0bbd69e0a33a014b3fcd84fce8c657c16ff536f3c6b36413ebd22043f921c22309ea854355b821f59cc6f0c0045991240d89ebdc3f33c3a0bc1b98876f84c4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in mini-guard.gemspec
6
+ gemspec
@@ -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/mg ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/mini/guard.rb"
4
+
5
+ Mini::Guard.run
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/mini/guard.rb"
4
+
5
+ Mini::Guard.run
@@ -0,0 +1,126 @@
1
+ require 'rake'
2
+ require 'active_support/inflector'
3
+ require 'shellany/sheller'
4
+ require 'listen'
5
+
6
+ if defined?(Pry)
7
+ require 'pry'
8
+ end
9
+
10
+ require_relative "guard/version"
11
+
12
+ module Mini
13
+ module Guard
14
+ def Guard.run
15
+ puts "Start watching files (app, views and specs) ..."
16
+ puts "Ctrl+C to stop"
17
+
18
+ begin
19
+ XConfiguration.validate
20
+ files = XIndex.run
21
+ listener = Listen.to('app', 'spec') do |modified, added, removed|
22
+ new_files = XIndex.run
23
+ XFileCommands.new(new_files - files).execute
24
+ files = new_files
25
+ end
26
+ listener.start
27
+ sleep
28
+ rescue NotRailsAndSpecApp => ex
29
+ puts ex.message
30
+ puts "Exiting ..."
31
+ rescue SystemExit, Interrupt
32
+ puts "Exiting ..."
33
+ end
34
+ end
35
+
36
+ class NotRailsAndSpecApp < StandardError
37
+ def NotRailsAndSpecApp.error
38
+ NotRailsAndSpecApp.new("Make sure you run this command in Rails app root folder (with rspec specs and optionally with spring gem added)")
39
+ end
40
+ end
41
+
42
+ class XConfiguration
43
+ def XConfiguration.rspec
44
+ File.exist?("bin/rspec") ? "bin/rspec" : "rspec"
45
+ end
46
+
47
+ def XConfiguration.validate
48
+ raise NotRailsAndSpecApp.error unless File.directory?("app") && File.directory?("spec")
49
+ end
50
+ end
51
+
52
+ class XFile
53
+ attr_reader :path, :size, :last_modified, :associations
54
+
55
+ def initialize(path, code:, specs:, views:)
56
+ @path = path
57
+ stat = File.stat(path)
58
+ @size = stat.size
59
+ @last_modified = stat.ctime
60
+ @associations = find_associations(code: code, specs: specs, views: views)
61
+ end
62
+
63
+ def to_s; "file: #{path} size: #{size} last modified: #{last_modified} associations: #{associations}"; end
64
+ def hash; "#{self.path}:#{self.last_modified}".hash; end
65
+ def eql?(xfile); self.path == xfile.path && self.last_modified == xfile.last_modified; end
66
+
67
+ private
68
+
69
+ def is_factory?; path =~ /^spec\/factories/; end
70
+ def is_code?; path =~ /^app\//; end
71
+ def is_model?; path =~ /^app\/models/; end
72
+ def is_view?; path =~ /^app\/views/; end
73
+ def basename; File.basename(path, ".*"); end
74
+ def view_path; path.split('/')[2..-2].join('/'); end
75
+
76
+ def find_associations(code:, specs:, views:)
77
+ if is_view?
78
+ specs.select{|e| e =~ /^spec\/controllers\/#{view_path}/}
79
+ elsif is_code?
80
+ if is_model?
81
+ specs.select{|e| e =~ /#{basename}/}
82
+ else
83
+ specs.select{|e| e =~ /#{basename}_spec/}
84
+ end
85
+ else
86
+ if is_factory?
87
+ specs.select{|e| e =~ /spec\/models\/(#{basename}|#{basename.singularize})_spec/}
88
+ else
89
+ [path]
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ class XFileCommands
96
+ attr_reader :xassociations
97
+
98
+ def initialize(xfiles)
99
+ @xassociations = xfiles.inject([]) {|res, e| res += e.associations}
100
+ end
101
+
102
+ def execute
103
+ if execute?
104
+ puts "executing: #{command}"
105
+ puts Shellany::Sheller.stdout(command)
106
+ end
107
+ end
108
+
109
+ private
110
+
111
+ def execute?; xassociations.any?; end
112
+ def command; "#{XConfiguration.rspec} #{xassociations.join(' ')}"; end
113
+ end
114
+
115
+ class XIndex
116
+ def XIndex.run
117
+ code = FileList.new('app/**/*.rb')
118
+ specs = FileList.new('spec/**/*_spec.rb', 'spec/factories/*.rb')
119
+ views = FileList.new('app/views/**/*.*')
120
+ (code + specs + views).collect do |path|
121
+ XFile.new(path, code: code, specs: specs, views: views)
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,5 @@
1
+ module Mini
2
+ module Guard
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.describe Mini::Guard do
2
+ it "has a version number" do
3
+ expect(Mini::Guard::VERSION).not_to be nil
4
+ end
5
+
6
+ it "does something useful" do
7
+ expect(false).to eq(true)
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "mini/guard"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mini-guard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Igor Kasyanchuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: listen
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: shellany
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Run specs when you edit your files in a smart way (in app, views, specs
112
+ folder).
113
+ email:
114
+ - igorkasyanchuk@gmail.com
115
+ executables:
116
+ - mg
117
+ - mini-guard
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - Gemfile
122
+ - Rakefile
123
+ - bin/mg
124
+ - bin/mini-guard
125
+ - lib/mini/guard.rb
126
+ - lib/mini/guard/version.rb
127
+ - spec/mini/guard_spec.rb
128
+ - spec/spec_helper.rb
129
+ homepage: https://github.com/igorkasyanchuk/mini-guard
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ - bin
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.7.6
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: Very simple rspec specs executor.
154
+ test_files: []