check_files 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: 289d84e6d22f2ce0f546cb2d8b2a9af7614413da
4
+ data.tar.gz: 9f3f0fa230535ab8ff0e3f898598d3ef41c386df
5
+ SHA512:
6
+ metadata.gz: e875d93fcd9b6dbee5a9e80a23bfeec8e714167ff4c5a34938da551d87d116b300ee54e37957d7a5db581eef0b1be4f41c086000ecde7ba4afce34bbf3ca7802
7
+ data.tar.gz: 839b099d814b6ed4e3d7600561c0082eb242b466baa01f7c0e13b19dc7dc978f0a98aa6a6cabf2834d0534e122c99248e694d9b3e8ceb8b27418f8d4b200ce21
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /log
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+ rvm:
5
+ - 2.3.1
6
+ before_install: gem install bundler
7
+ notifications:
8
+ email: false
9
+ env:
10
+ global:
11
+ secure: kYFQh6ljbxCjeVSblngOY+50qRbSigK/P+osQfxgAe0e5NLV14zUqChCnS8ipdPP86HyNxBLJlFlu08fEXmQSwQUd+7j87TWR6v9+UFebmvmMrewRdmcKgFJZI/cu9CP6dAc7Lh3mD/WPQOTuEDx7boXhkc3FCBIaDLtdcva2OrD6AFzfjWvZEPYC40OEZdLbpnkKEd8uOfYkd+vX7eUAhtlsXbXd5ZX9j55CbdXeVPhzI1GKbWQYWF5K0lQYgY+FBke6SmN8X7XjVIF0McA72X9V0I3xyjTEr0Rm/8JPnMXC9F5o8Rqh3sKkF2vRUhAZw9nvZI7BjZJhiudyrR7/JX+ErkLpFgNUqz6wBPsWBRv4zn25atdDIMHs5hYRVyPpLl0xtNKnJwUd6m/6aeUGP0B6x80sDx4CPVPSeFpJ+NbND2KYHxi9Aw2KqKwOBcZWVDwAjecewpUOJlnMX+3/g24FXkmFICc4zaJazCPiW6T2GR/YwIZiu0c5oapX/tU2QfNMZHY/6leFIcYc1mX5bLoaaYSuYKizncJe4EJnyEp5myapDq2mVYCol3HmhkgQ8Bd8T8WxLrFv1954xkd/npFMov+bHrnt5Cypbr+qTocnVHSA968m8YCTyNjzU5fvJgZweQKsFK1sPGHgHGiKlBeKc5syJo7QbH8N+j7VRc=
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at fnando.vieira@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nando Vieira
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,76 @@
1
+ # CheckFiles
2
+
3
+ [![Travis-CI](https://travis-ci.org/fnando/check_files.png)](https://travis-ci.org/fnando/check_files)
4
+ [![Code Climate](https://codeclimate.com/github/fnando/check_files/badges/gpa.svg)](https://codeclimate.com/github/fnando/check_files)
5
+ [![Test Coverage](https://codeclimate.com/github/fnando/check_files/badges/coverage.svg)](https://codeclimate.com/github/fnando/check_files/coverage)
6
+ [![Gem](https://img.shields.io/gem/v/check_files.svg)](https://rubygems.org/gems/check_files)
7
+ [![Gem](https://img.shields.io/gem/dt/check_files.svg)](https://rubygems.org/gems/check_files)
8
+
9
+ Ever forgot to restart the development web server when you change things like `Gemfile` or `config/environments/development.rb`? You're not alone. There are a lot of cases to keep in mind:
10
+
11
+ - You upgrade and/or remove/add gems to `Gemfile`.
12
+ - You change environment values (e.g. `config/environments/development.rb`).
13
+ - You change initializer values.
14
+ - You add/remove directories to/from `app`.
15
+ - You add/remove files to/from `config/locales`.
16
+ - You change configuration files living at `config/*.yml` .
17
+
18
+ With this gem you don't have to think about it. Every time you change files that require a restart, an exception will be raised and you'll know what you have to do.
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem "check_files", group: :development
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install check_files
35
+
36
+ ## Usage
37
+
38
+ You don't have to configure anything but there are some configurable values if you want. The following values are the defaults:
39
+
40
+ ```ruby
41
+ # The list of files/directories that must be checked.
42
+ # Patterns ended with /* will just check the entries list (not the content).
43
+ config.check_files.paths = [
44
+ "Gemfile.lock",
45
+ "config/initializers/**/*.rb",
46
+ "config/{application,boot,config,environment}.rb",
47
+ "config/*.yml",
48
+ "config/environments/**/*.rb",
49
+ "app/*",
50
+ "config/locales/**/*"
51
+ ]
52
+
53
+ # The notifier that will be used. By default it raises an exception on Rails < 5 or restarts the web server (Rails 5+).
54
+ # You can use CheckFiles::Notifiers::Exception, CheckFiles::Notifiers::Logging or CheckFiles::Notifiers::Restart (Rails 5+).
55
+ config.check_files.notifier = CheckFiles::Notifiers::Exception
56
+ ```
57
+
58
+ To overwrite any of these values, just create the initializer `config/initializers/check_files.rb` like the following:
59
+
60
+ ```ruby
61
+ Rails.configuration.check_files.notifier = CheckFiles::Notifiers::Logging
62
+ ```
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/check_files. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ t.warning = false
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "check_files"
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
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,25 @@
1
+ require "./lib/check_files/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "check_files"
5
+ spec.version = CheckFiles::VERSION
6
+ spec.authors = ["Nando Vieira"]
7
+ spec.email = ["fnando.vieira@gmail.com"]
8
+
9
+ spec.summary = "Check non-reloadable files changes on Rails apps"
10
+ spec.description = spec.summary
11
+ spec.homepage = "https://github.com/fnando/check_files"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.bindir = "exe"
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler"
20
+ spec.add_development_dependency "rake"
21
+ spec.add_development_dependency "minitest-utils"
22
+ spec.add_development_dependency "rails"
23
+ spec.add_development_dependency "pry-meta"
24
+ spec.add_development_dependency "codeclimate-test-reporter"
25
+ end
@@ -0,0 +1,28 @@
1
+ require "rails/railtie"
2
+
3
+ module CheckFiles
4
+ require "check_files/version"
5
+ require "check_files/railtie"
6
+ require "check_files/middleware"
7
+ require "check_files/checker"
8
+ require "check_files/notifiers/logging"
9
+ require "check_files/notifiers/exception"
10
+ require "check_files/notifiers/restart"
11
+
12
+ def self.config
13
+ Rails.application.config.check_files
14
+ end
15
+
16
+ def self.checkers
17
+ @checkers ||= config.paths.map {|path| Checker.new(path) }
18
+ end
19
+
20
+ def self.reset
21
+ @checkers = nil
22
+ end
23
+
24
+ def self.check!
25
+ change = checkers.find(&:changed?)
26
+ config.notifier.call(change) if change
27
+ end
28
+ end
@@ -0,0 +1,46 @@
1
+ module CheckFiles
2
+ class Checker
3
+ attr_reader :cache_path, :pattern
4
+
5
+ def initialize(pattern)
6
+ @pattern = pattern
7
+ pattern_digest = Digest::SHA1.hexdigest(pattern)
8
+ @cache_path = Rails.root.join("tmp/cache/#{pattern_digest}")
9
+ end
10
+
11
+ def current_digest
12
+ entries = Dir[pattern].sort
13
+ entries_digest = Digest::SHA1.hexdigest(entries.join)
14
+
15
+ if pattern.end_with?("/*")
16
+ entries_digest
17
+ else
18
+ content_digest = entries.map {|entry| compute_digest(entry) }.join
19
+ Digest::SHA1.hexdigest("#{entries_digest}#{content_digest}")
20
+ end
21
+ end
22
+
23
+ def previous_digest
24
+ cache_path.file? && cache_path.read
25
+ end
26
+
27
+ def changed?
28
+ prev_digest = previous_digest
29
+
30
+ if prev_digest
31
+ prev_digest != current_digest
32
+ else
33
+ update_cache && false
34
+ end
35
+ end
36
+
37
+ def update_cache
38
+ File.open(cache_path, "w") {|f| f << current_digest }
39
+ end
40
+
41
+ def compute_digest(entry)
42
+ content = File.exist?(entry) && File.read(entry)
43
+ Digest::SHA1.hexdigest("#{entry}-#{content}")
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,16 @@
1
+ module CheckFiles
2
+ class Middleware
3
+ def initialize(app)
4
+ @app = app
5
+ end
6
+
7
+ def call(env)
8
+ CheckFiles.check! unless asset?(env)
9
+ @app.call(env)
10
+ end
11
+
12
+ def asset?(env)
13
+ env["REQUEST_PATH"] =~ /\.(css|js|jpe?g|gif|svg|ico|swf|html)/
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module CheckFiles
2
+ module Notifiers
3
+ class Exception
4
+ def self.call(checker)
5
+ fail "You must restart the web development server; #{checker.pattern} has changed."
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module CheckFiles
2
+ module Notifiers
3
+ class Logging
4
+ def self.call(checker)
5
+ $stderr << "\n\e[0;31m=> You must restart your web development server; #{checker.pattern} has changed.\e[0m\n"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module CheckFiles
2
+ module Notifiers
3
+ class Restart < Logging
4
+ def self.call(checker)
5
+ $stderr << "\n\e[0;31m=> #{checker.pattern} has changed, so the web server was restarted. Please reload the page.\e[0m\n"
6
+ system "rails restart"
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,28 @@
1
+ module CheckFiles
2
+ class Railtie < Rails::Railtie
3
+ config.check_files = ActiveSupport::OrderedOptions.new
4
+
5
+ initializer "check_files" do
6
+ config.check_files.paths = [
7
+ "Gemfile.lock",
8
+ "config/initializers/**/*.rb",
9
+ "config/{application,boot,config,environment}.rb",
10
+ "config/*.yml",
11
+ "config/environments/**/*.rb",
12
+ "app/*",
13
+ "config/locales/**/*"
14
+ ]
15
+
16
+ Rails.application.config.middleware.use(Middleware)
17
+ config.check_files.notifier = if Rails::VERSION::STRING >= "5.0.0"
18
+ Notifiers::Restart
19
+ else
20
+ Notifiers::Exception
21
+ end
22
+
23
+ Rails.application.config.after_initialize do
24
+ CheckFiles.checkers.each(&:update_cache)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module CheckFiles
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: check_files
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nando Vieira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: minitest-utils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-meta
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: codeclimate-test-reporter
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Check non-reloadable files changes on Rails apps
98
+ email:
99
+ - fnando.vieira@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - check_files.gemspec
114
+ - lib/check_files.rb
115
+ - lib/check_files/checker.rb
116
+ - lib/check_files/middleware.rb
117
+ - lib/check_files/notifiers/exception.rb
118
+ - lib/check_files/notifiers/logging.rb
119
+ - lib/check_files/notifiers/restart.rb
120
+ - lib/check_files/railtie.rb
121
+ - lib/check_files/version.rb
122
+ homepage: https://github.com/fnando/check_files
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Check non-reloadable files changes on Rails apps
146
+ test_files: []