projectionist 0.1.2 → 0.2.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 +4 -4
- data/.projections.json +3 -2
- data/README.md +2 -9
- data/lib/projectionist.rb +1 -0
- data/lib/projectionist/cli.rb +11 -2
- data/lib/projectionist/errors.rb +4 -0
- data/lib/projectionist/projections.rb +14 -4
- data/lib/projectionist/version.rb +1 -1
- data/spec/projections_spec.rb +37 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16e6dea120ab5ed04934ba4eba2b806bb7914dae
|
4
|
+
data.tar.gz: 99bf7258097f2de499f3d8eea2efe394c8244223
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8999a092b56b9310d31d6165c6008e5fd1225829d233fc4324e25c71d41733a13dfd82f8abb07bd3335b34a342c1656f5379d36cb4339d380f954f337357c9c
|
7
|
+
data.tar.gz: dd76f78c31bcfad72340011197e8768edaa6add7022655fefa86e9d33e70b44430a16fba98083c3bf07827b726be13e651653d412bd48c238fdc43684d0180ae
|
data/.projections.json
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
# Projectionist
|
7
7
|
|
8
|
-
|
8
|
+
Quickly edit project files using the [.projections.json](https://github.com/tpope/vim-projectionist) format
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
@@ -29,12 +29,5 @@ The command to edit `lib/whatever/test.rb` would be:
|
|
29
29
|
|
30
30
|
$ prj edit lib whatever/test
|
31
31
|
|
32
|
-
|
33
|
-
## Contributing
|
34
|
-
|
35
|
-
1. [Fork it](https://github.com/glittershark/projectionist/fork)
|
36
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
-
5. Create a new Pull Request
|
32
|
+
Note that there are two glob components here - `**` and `*`. When editing files, these components are separated by a `/`
|
40
33
|
|
data/lib/projectionist.rb
CHANGED
data/lib/projectionist/cli.rb
CHANGED
@@ -8,19 +8,28 @@ module Projectionist
|
|
8
8
|
def initialize(*)
|
9
9
|
@projections = Projectionist::Projections.new
|
10
10
|
super
|
11
|
+
rescue Projectionist::ProjectionError => error
|
12
|
+
$stderr.puts "ERROR: #{error.message}"
|
13
|
+
exit 1
|
11
14
|
end
|
12
15
|
|
13
16
|
desc 'edit <type> <file>', 'Edit the file for <type> named <file>'
|
14
17
|
option :editor
|
15
18
|
def edit(type, file)
|
16
|
-
editor = options[:editor] || ENV['EDITOR'] || `which vim`
|
17
19
|
file = @projections.file_for type, file
|
18
|
-
exec editor
|
20
|
+
exec "#{editor} #{file}"
|
19
21
|
end
|
20
22
|
|
21
23
|
desc 'list <type>', 'List all files for <type>'
|
22
24
|
def list(type)
|
23
25
|
puts @projections.files_for(type).join("\n")
|
24
26
|
end
|
27
|
+
|
28
|
+
no_commands do
|
29
|
+
def editor
|
30
|
+
editor = options[:editor] || ENV['VISUAL'] || ENV['EDITOR'] || 'vim'
|
31
|
+
editor.empty? ? 'vim' : editor
|
32
|
+
end
|
33
|
+
end
|
25
34
|
end
|
26
35
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'projectionist/errors'
|
2
3
|
|
3
4
|
module Projectionist
|
4
5
|
class Projections
|
@@ -14,6 +15,9 @@ module Projectionist
|
|
14
15
|
@json = get_json path
|
15
16
|
@json.each do |glob, options|
|
16
17
|
next unless options.key? 'type'
|
18
|
+
if glob.include? '**/*'
|
19
|
+
raise Projectionist::ProjectionError, 'Globs may not include `**/*`'
|
20
|
+
end
|
17
21
|
@types[options['type']] = options.merge('glob' => glob)
|
18
22
|
end
|
19
23
|
end
|
@@ -33,7 +37,9 @@ module Projectionist
|
|
33
37
|
|
34
38
|
def files_for(type)
|
35
39
|
return [] unless type? type
|
36
|
-
|
40
|
+
glob = @types[type]['glob']
|
41
|
+
glob = glob.sub('/*', '/**/*') unless glob.include? '**'
|
42
|
+
Dir.glob(glob).map { |p| File.expand_path p }
|
37
43
|
end
|
38
44
|
|
39
45
|
private
|
@@ -63,9 +69,13 @@ module Projectionist
|
|
63
69
|
def build_glob(glob, file)
|
64
70
|
# Split the passed file by `/`, then replace all globs that use `*` or
|
65
71
|
# `**` with components of the passed file, in order
|
66
|
-
|
67
|
-
|
68
|
-
|
72
|
+
if glob.include? '**'
|
73
|
+
file_components = file.split('/')
|
74
|
+
glob_components = glob.split(/\*+/)
|
75
|
+
glob_components.zip(file_components).flatten.compact.join('')
|
76
|
+
else
|
77
|
+
glob.sub(/\*/, file)
|
78
|
+
end
|
69
79
|
end
|
70
80
|
end
|
71
81
|
end
|
data/spec/projections_spec.rb
CHANGED
@@ -66,21 +66,28 @@ describe Projectionist::Projections do
|
|
66
66
|
expect(@projections.json_file_existed).to be false
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
context 'with `**/*` in projections' do
|
71
|
+
before { write_fixtures('test/**/*.rb' => { 'type' => 'disallowed' }) }
|
72
|
+
it 'raises an error' do
|
73
|
+
expect { @projections.load_file }.to raise_error Projectionist::ProjectionError
|
74
|
+
end
|
75
|
+
end
|
69
76
|
end
|
70
77
|
|
71
78
|
describe '#files_for' do
|
72
79
|
let(:test_dir) { File.join(fixture_folder, 'test') }
|
73
|
-
let(:test_files) { (1..10).map { |n| File.join(test_dir, "
|
80
|
+
let(:test_files) { (1..10).map { |n| File.join(test_dir, "#{n}_test.rb") } }
|
74
81
|
|
75
82
|
before do
|
76
|
-
write_fixtures('test
|
83
|
+
write_fixtures('test/*_test.rb' => { 'type' => 'test' })
|
77
84
|
Dir.mkdir(test_dir) unless Dir.exist? test_dir
|
78
85
|
|
79
86
|
test_files.each { |f| File.open(f, 'w') }
|
80
87
|
|
81
88
|
# make bad test files as well
|
82
89
|
5.times do |n|
|
83
|
-
file = File.join(test_dir, "
|
90
|
+
file = File.join(test_dir, "#{n}_bad.rb")
|
84
91
|
File.open(file, 'w')
|
85
92
|
end
|
86
93
|
|
@@ -98,6 +105,20 @@ describe Projectionist::Projections do
|
|
98
105
|
expect(@projections.files_for 'toast').to eq []
|
99
106
|
end
|
100
107
|
end
|
108
|
+
|
109
|
+
context 'with files in child directories' do
|
110
|
+
let(:test_subdir) { File.join(test_dir, 'subdir') }
|
111
|
+
let(:test_file_subdir) { File.join(test_subdir, 'subdir_test.rb') }
|
112
|
+
before do
|
113
|
+
Dir.mkdir(test_subdir) unless Dir.exist? test_subdir
|
114
|
+
File.open(test_file_subdir, 'w')
|
115
|
+
end
|
116
|
+
|
117
|
+
after { File.delete test_file_subdir }
|
118
|
+
|
119
|
+
subject { @projections.files_for('test') }
|
120
|
+
it { is_expected.to include test_file_subdir }
|
121
|
+
end
|
101
122
|
end
|
102
123
|
|
103
124
|
describe '#file_for' do
|
@@ -142,6 +163,18 @@ describe Projectionist::Projections do
|
|
142
163
|
end
|
143
164
|
end
|
144
165
|
|
166
|
+
context 'with files in child directories' do
|
167
|
+
let(:test_subdir) { File.join(test_dir, 'subdir') }
|
168
|
+
let(:test_file_subdir) { File.join(test_subdir, 'file.rb') }
|
169
|
+
before do
|
170
|
+
Dir.mkdir(test_subdir) unless Dir.exist? test_subdir
|
171
|
+
File.open(test_file_subdir, 'w')
|
172
|
+
end
|
173
|
+
|
174
|
+
subject { @projections.file_for('test', 'subdir/file') }
|
175
|
+
it { is_expected.to eq test_file_subdir }
|
176
|
+
end
|
177
|
+
|
145
178
|
context 'in a child directory' do
|
146
179
|
before { Dir.chdir test_dir }
|
147
180
|
subject { @projections.file_for('test', 'file') }
|
@@ -149,7 +182,7 @@ describe Projectionist::Projections do
|
|
149
182
|
end
|
150
183
|
end
|
151
184
|
|
152
|
-
context 'with
|
185
|
+
context 'with advanced globs' do
|
153
186
|
let(:test_dir) { File.join(fixture_folder, 'test', 'foobar') }
|
154
187
|
let(:test_file) { File.join(test_dir, 'test_file.rb') }
|
155
188
|
before do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: projectionist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Griffin Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- bin/prj
|
108
108
|
- lib/projectionist.rb
|
109
109
|
- lib/projectionist/cli.rb
|
110
|
+
- lib/projectionist/errors.rb
|
110
111
|
- lib/projectionist/projections.rb
|
111
112
|
- lib/projectionist/version.rb
|
112
113
|
- projectionist.gemspec
|