file_police 0.0.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ M2RiZjI0M2Q2MzM2N2UwZmMyYWRkZDQxM2U0Y2JhYWU1YWJjY2NkZg==
5
+ data.tar.gz: !binary |-
6
+ OTQ2NTA5ODAyNDI4NDA5ODI4N2NiOTk0MmQ4ZGIwYWMxNmNjODc4Mg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ OGMwNzBkZjIyODA4MWZiZTQxMTZjZmE4ODM4NWJiNWE2MjllZjExNGEwNTBi
10
+ MmJlMWJiZDIwNzZmYzExMjFiMTQ3MmE1NmQ5ZTFkMWU1YzQ3NTc1MzQwNWZi
11
+ MDgwYTIzZWI0MzVkYmI0MThkMzc3ZjRhNjU2MzVhNmVjY2Q1ZjM=
12
+ data.tar.gz: !binary |-
13
+ OGI3MzY2OTE3NzA0MzBjNzNkYWQ4NTkyNDY4YjQ3ZWE3MDc2OWFjN2ZhZGQ4
14
+ NzUzMWQ1Y2I4NWM2NTQyZGVlMGJlOWJlMmM3MWNlNmY4ZTU5MTcyYmU2OTVj
15
+ NjBjZjM3MmRjNzA3ZWMxNmQ0M2QxYTgwYmZmMWUxYWY2MDMzMTA=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ bin
18
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in file_police.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,27 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ file_police (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.4)
10
+ rake (10.1.0)
11
+ rspec (2.13.0)
12
+ rspec-core (~> 2.13.0)
13
+ rspec-expectations (~> 2.13.0)
14
+ rspec-mocks (~> 2.13.0)
15
+ rspec-core (2.13.1)
16
+ rspec-expectations (2.13.0)
17
+ diff-lcs (>= 1.1.3, < 2.0)
18
+ rspec-mocks (2.13.1)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.3)
25
+ file_police!
26
+ rake
27
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Adam Wead
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # FilePolice
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'file_police'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install file_police
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ # Rake task for getting an irb session
5
+ desc "Open an irb session preloaded with this library"
6
+ task :console do
7
+ sh "irb -rubygems -I lib -r file_police.rb"
8
+ end
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'file_police/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "file_police"
8
+ spec.version = FilePolice::VERSION
9
+ spec.authors = ["Adam Wead"]
10
+ spec.email = ["amsterdamos@gmail.com"]
11
+ spec.description = "Policing our files"
12
+ spec.summary = "Policing our files"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,53 @@
1
+ # Checks the name of a file in our backlog for proper format.
2
+ #
3
+ # Ex.
4
+ # > good = BacklogFile.new(filepath)
5
+ # > good.errors
6
+ # => []
7
+ # > bad = BacklogFile.new(filepath)
8
+ # > bad.errors
9
+ # => ["This is bad", "That is bad"]
10
+ #
11
+ class FilePolice::BacklogFile
12
+
13
+ attr_accessor :collection, :box, :folder, :name, :number, :errors
14
+
15
+ def initialize path
16
+ parts = File.basename(path, File.extname(path)).split("_")
17
+ self.errors = Array.new
18
+ if parts.length == 5
19
+ validate_collection(parts[0])
20
+ validate_box(parts[1])
21
+ validate_folder(parts[2])
22
+ self.name = parts[3]
23
+ validate_number(parts[4])
24
+ else
25
+ self.errors << "Filename does not have 5 segments separated by underscores (_)"
26
+ end
27
+ end
28
+
29
+ # Should match strings like ARC0001
30
+ def validate_collection collection = String.new
31
+ self.errors << "#{collection} does not match ARC#### format" unless collection.match(/^ARC[0-9]{4,4}$/)
32
+ self.collection = collection
33
+ end
34
+
35
+ # Should match strings like BX1
36
+ def validate_box box = String.new
37
+ self.errors << "#{box} does not match BX# format" unless box.match(/^BX[0-9]{1,3}$/)
38
+ self.box = box
39
+ end
40
+
41
+ # Should match strings like FL1
42
+ def validate_folder folder = String.new
43
+ self.errors << "#{folder} does not match FL# format" unless folder.match(/^FL[0-9]{1,3}$/)
44
+ self.folder = folder
45
+ end
46
+
47
+ # Sould be numbers only
48
+ def validate_number number = String.new
49
+ self.errors << "#{number} does not match number format" unless number.match(/^[0-9]{1,4}$/)
50
+ self.number = number
51
+ end
52
+
53
+ end
@@ -0,0 +1,10 @@
1
+ class FilePolice::Ticket
2
+
3
+ attr_accessor :file, :violations
4
+
5
+ def initialize file, violations
6
+ self.file = file
7
+ self.violations = violations
8
+ end
9
+
10
+ end
@@ -0,0 +1,3 @@
1
+ module FilePolice
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ require 'csv'
2
+
3
+ module FilePolice
4
+
5
+ def self.version
6
+ FilePolice::VERSION
7
+ end
8
+
9
+ # Patrol a directory and return tickets for any violations
10
+ def self.patrol path, tickets = Array.new
11
+ Dir.glob(File.join(path, "**/*")).each do |file|
12
+ tickets << Ticket.new(File.basename(file), FilePolice::BacklogFile.new(file).errors) unless File.directory?(file)
13
+ end
14
+ return tickets
15
+ end
16
+
17
+ end
18
+
19
+ require 'file_police/backlog_file'
20
+ require 'file_police/ticket'
@@ -0,0 +1,68 @@
1
+ require 'spec_helper'
2
+
3
+ describe FilePolice::BacklogFile do
4
+
5
+ describe "valid filenames" do
6
+
7
+ before :each do
8
+ @sample = FilePolice::BacklogFile.new("ARC0001_BX1_FL1_name_001.tif")
9
+ end
10
+
11
+ it "must have no errors" do
12
+ @sample.errors.should be_empty
13
+ end
14
+
15
+ it "must have a collection" do
16
+ @sample.collection.should == "ARC0001"
17
+ end
18
+
19
+ it "must have a box" do
20
+ @sample.box.should == "BX1"
21
+ end
22
+
23
+ it "must have a folder" do
24
+ @sample.folder.should == "FL1"
25
+ end
26
+
27
+ it "must have some kind of name" do
28
+ @sample.name.should == "name"
29
+ end
30
+
31
+ it "must have a number for the file" do
32
+ @sample.number.should == "001"
33
+ end
34
+
35
+ end
36
+
37
+ describe "an invalid filename" do
38
+
39
+ it "has too many parts" do
40
+ invalid = FilePolice::BacklogFile.new("ARC0001_BX1_FL4_name_extra_001.tif")
41
+ invalid.errors.should include "Filename does not have 5 segments separated by underscores (_)"
42
+ end
43
+
44
+ its "has not enough parts" do
45
+ invalid = FilePolice::BacklogFile.new("ARC0001_BX1_001.tif")
46
+ invalid.errors.should include "Filename does not have 5 segments separated by underscores (_)"
47
+ end
48
+
49
+ it "has an incorrect collection" do
50
+ ["ARC-001_x_x_x_x", "ARC1_x_x_x_x", "ARC 001_x_x_x_x" ].each do |file|
51
+ invalid = FilePolice::BacklogFile.new(file)
52
+ invalid.errors.should include "#{invalid.collection} does not match ARC#### format"
53
+ end
54
+ end
55
+
56
+ it "has an incorrect box" do
57
+ invalid = FilePolice::BacklogFile.new("ARC0001_box2_FL4_name_001.tif")
58
+ invalid.errors.should include "box2 does not match BX# format"
59
+ end
60
+
61
+ it "has an incorrect folder" do
62
+ invalid = FilePolice::BacklogFile.new("ARC0001_BX1_folder3_name_001.tif")
63
+ invalid.errors.should include "folder3 does not match FL# format"
64
+ end
65
+
66
+ end
67
+
68
+ end
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe FilePolice do
4
+
5
+ describe "::patrol" do
6
+ it "should return an array of tickets with violations" do
7
+ tickets = FilePolice.patrol("spec/fixtures/bad")
8
+ tickets.should be_kind_of Array
9
+ tickets.first.should be_kind_of FilePolice::Ticket
10
+ tickets.collect { |t| t.file unless t.violations.empty? }.should include "ARC0001_box11_FL1_name_001.tif"
11
+ end
12
+
13
+ it "should return an array of tickets without violations" do
14
+ tickets = FilePolice.patrol("spec/fixtures/good")
15
+ tickets.collect { |t| t.file unless t.violations.empty? }.compact.should be_empty
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,12 @@
1
+ require 'file_police'
2
+ RSpec.configure do |config|
3
+ config.treat_symbols_as_metadata_keys_with_true_values = true
4
+ config.run_all_when_everything_filtered = true
5
+ config.filter_run :focus
6
+
7
+ # Run specs in random order to surface order dependencies. If you find an
8
+ # order dependency and want to debug it, you can fix the order by providing
9
+ # the seed, which is printed after each run.
10
+ # --seed 1234
11
+ config.order = 'random'
12
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe FilePolice::Ticket do
4
+
5
+ before :each do
6
+ @ticket = FilePolice::Ticket.new("foo", ["issue1", "issue2"])
7
+ end
8
+
9
+ it "should have a file" do
10
+ @ticket.file.should == "foo"
11
+ end
12
+
13
+ it "should violations" do
14
+ @ticket.violations.should == ["issue1", "issue2"]
15
+ end
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: file_police
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Wead
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-01 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: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: rspec
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
+ description: Policing our files
56
+ email:
57
+ - amsterdamos@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - file_police.gemspec
70
+ - lib/file_police.rb
71
+ - lib/file_police/backlog_file.rb
72
+ - lib/file_police/ticket.rb
73
+ - lib/file_police/version.rb
74
+ - spec/backlog_file_spec.rb
75
+ - spec/fixtures/bad/ARC 0001_BX1_FL1_name_001.tif
76
+ - spec/fixtures/bad/ARC0001_BX1_FL1_001.tif
77
+ - spec/fixtures/bad/ARC0001_BX1_FL1_name_001.tif
78
+ - spec/fixtures/bad/ARC0001_box11_FL1_name_001.tif
79
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0100.tif
80
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0101.tif
81
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0102.tif
82
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0103.tif
83
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0104.tif
84
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0105.tif
85
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0106.tif
86
+ - spec/fixtures/good/nested/ARC0136_BX1_FL2_FanLetters_0106.tif
87
+ - spec/police_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/ticket_spec.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Policing our files
114
+ test_files:
115
+ - spec/backlog_file_spec.rb
116
+ - spec/fixtures/bad/ARC 0001_BX1_FL1_name_001.tif
117
+ - spec/fixtures/bad/ARC0001_BX1_FL1_001.tif
118
+ - spec/fixtures/bad/ARC0001_BX1_FL1_name_001.tif
119
+ - spec/fixtures/bad/ARC0001_box11_FL1_name_001.tif
120
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0100.tif
121
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0101.tif
122
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0102.tif
123
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0103.tif
124
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0104.tif
125
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0105.tif
126
+ - spec/fixtures/good/ARC0136_BX1_FL2_FanLetters_0106.tif
127
+ - spec/fixtures/good/nested/ARC0136_BX1_FL2_FanLetters_0106.tif
128
+ - spec/police_spec.rb
129
+ - spec/spec_helper.rb
130
+ - spec/ticket_spec.rb