pre-commit 0.9.2 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ff1322d028fe5837cfde982be38e20eee79b4a0
4
- data.tar.gz: 8e5f8efaffab2c8afb5d2fafbdfd1ef30b424569
3
+ metadata.gz: 7d14a6ce5ee2717ae7d88d9fb68b80dbfd6380e1
4
+ data.tar.gz: 1358302054df917ca046543c2cb075c81323e0ce
5
5
  SHA512:
6
- metadata.gz: ae50c6a33ca6bc51724fd9f04f803281832d58873d38072e2c8b4690805e6d1b4aa1ab980887d8a6e589c4dd18fa400b31320593375f057947acc30449d4abe0
7
- data.tar.gz: b0d7901498f8aeca050530e769e5c4403678c556cd78fbab6a8a5482f3b53e4ccccaf28e6e4b228b27bfb65a3849ffe6b1660327ba19f2b5b8bd2a654cfc4c07
6
+ metadata.gz: 67c1e0fa3d6aa160683efe67aa0cc1f9540a73a284d1cc2dd5454ad45b1f4bb79e327c34e008fb92096edae4f4382a45a1d09ed862c000dc3d644e84c6717b02
7
+ data.tar.gz: 72d69a94f724d062ac47ee938e531e34c7d5f38b73ec900cb0846392e4536f3303000c5f06730bf941f918a8f517000070b17d30e5ca4f2e67ab3171aefbfd3a
@@ -1,27 +1,32 @@
1
1
  module PreCommit
2
2
  class MigrationCheck
3
- def self.call(staged_files)
4
- migration_present = migration_file_present?(staged_files)
5
- schema_change = schema_file_present?(staged_files)
3
+ class << self
4
+ def call(staged_files)
5
+ migration_files = migration_files(staged_files)
6
+ schema_files = schema_files(staged_files)
6
7
 
7
- if migration_present && !schema_change
8
- "It looks like you're adding a migration, but did not update the schema file"
9
- elsif schema_change && !migration_present
10
- "You're trying to change the schema without adding a migration file"
8
+ if migration_files.any? && schema_files.none?
9
+ "It looks like you're adding a migration, but did not update the schema file"
10
+ elsif migration_files.none? && schema_files.any?
11
+ "You're trying to change the schema without adding a migration file"
12
+ elsif migration_files.any? && schema_files.any?
13
+ versions = migration_files.map { |f| f[/\d+/] }
14
+ schema = schema_files.map { |f| File.read(f) }.join
15
+ missing_versions = versions.select { |version| !schema.include?(version) }
16
+ if missing_versions.any?
17
+ "You did not add the schema versions for #{versions.join(', ')} to #{schema_files.join(' or ')}"
18
+ end
19
+ end
11
20
  end
12
- end
13
21
 
14
- def self.migration_file_present?(staged_files)
15
- staged_files.any? { |file| file =~ /db\/migrate\/.*\.rb/ }
16
- end
22
+ private
17
23
 
18
- def self.schema_file_present?(staged_files)
19
- staged_files.any? do |file|
20
- basename = File.basename(file)
24
+ def migration_files(staged_files)
25
+ staged_files.grep(/db\/migrate\/.*\.rb/)
26
+ end
21
27
 
22
- [/schema\.rb/i, /structure.*\.sql/].any? do |regex|
23
- basename =~ regex
24
- end
28
+ def schema_files(staged_files)
29
+ staged_files.select { |f| File.basename(f) =~ /schema\.rb|structure.*\.sql/ }
25
30
  end
26
31
  end
27
32
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pre-commit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shajith Chacko, Josh Lubaway
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-16 00:00:00.000000000 Z
11
+ date: 2013-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs