projectionist 0.2.0 → 0.3.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 +1 -0
- data/lib/projectionist/cli.rb +11 -4
- data/lib/projectionist/projections.rb +36 -10
- data/lib/projectionist/version.rb +1 -1
- data/spec/projections_spec.rb +32 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9337be5a0c417da30876568ce0719dbd92a30f5a
|
4
|
+
data.tar.gz: 9f1270e59465fac5cd6c8203a185613c7cbc2276
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ae8010ff3493f48a983e760d4ad2f602c348b0c682108045fe313efd15aa0f3fbe5ed748ebb70836cff83e347498bb782374f926189136838a7792894ef5b9e
|
7
|
+
data.tar.gz: 17d734a911774efb1997b66a4d1f774bc9d24f5201ef73c538b48298fbe3c541a0f46525f958db7dd0990d8d649c84799d61fc3987f977c9263479357fac1e8e
|
data/.projections.json
CHANGED
data/lib/projectionist/cli.rb
CHANGED
@@ -13,16 +13,23 @@ module Projectionist
|
|
13
13
|
exit 1
|
14
14
|
end
|
15
15
|
|
16
|
-
desc 'edit <type> <file>', 'Edit the file for <type> named <file>'
|
16
|
+
desc 'edit <type> [<file>]', 'Edit the file for <type> named <file>'
|
17
17
|
option :editor
|
18
|
-
def edit(type, file)
|
18
|
+
def edit(type, file='')
|
19
19
|
file = @projections.file_for type, file
|
20
20
|
exec "#{editor} #{file}"
|
21
21
|
end
|
22
22
|
|
23
|
-
desc 'list <type>', 'List all files for <type>'
|
23
|
+
desc 'list [-v|--verbose] <type>', 'List all files for <type>'
|
24
|
+
option :verbose, type: :boolean, aliases: '-v',
|
25
|
+
desc: "List full file paths instead of file names"
|
24
26
|
def list(type)
|
25
|
-
puts @projections.files_for(type).join("\n")
|
27
|
+
puts @projections.files_for(type, verbose: options[:verbose]).join("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
desc 'types', 'List all types'
|
31
|
+
def types
|
32
|
+
puts @projections.types.join("\n")
|
26
33
|
end
|
27
34
|
|
28
35
|
no_commands do
|
@@ -3,11 +3,10 @@ require 'projectionist/errors'
|
|
3
3
|
|
4
4
|
module Projectionist
|
5
5
|
class Projections
|
6
|
-
attr_reader :types
|
7
6
|
attr_reader :json_file_existed
|
8
7
|
|
9
8
|
def initialize
|
10
|
-
@
|
9
|
+
@type_hash = {}
|
11
10
|
load_file
|
12
11
|
end
|
13
12
|
|
@@ -18,28 +17,42 @@ module Projectionist
|
|
18
17
|
if glob.include? '**/*'
|
19
18
|
raise Projectionist::ProjectionError, 'Globs may not include `**/*`'
|
20
19
|
end
|
21
|
-
@
|
20
|
+
@type_hash[options['type']] = options.merge('glob' => glob)
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
25
24
|
def type?(type)
|
26
|
-
@
|
25
|
+
@type_hash.key?(type)
|
27
26
|
end
|
28
27
|
|
29
|
-
def
|
28
|
+
def types
|
29
|
+
@type_hash.keys
|
30
|
+
end
|
31
|
+
|
32
|
+
def file_for(type, name='')
|
30
33
|
return nil unless type? type
|
31
34
|
|
32
35
|
Dir.chdir @basedir
|
33
|
-
glob = build_glob(@
|
36
|
+
glob = build_glob(@type_hash[type]['glob'], name)
|
34
37
|
file = Dir.glob(glob)[0]
|
35
38
|
File.expand_path(file.nil? ? glob : file)
|
36
39
|
end
|
37
40
|
|
38
|
-
def files_for(type)
|
41
|
+
def files_for(type, options = {})
|
39
42
|
return [] unless type? type
|
40
|
-
|
41
|
-
glob =
|
42
|
-
Dir.glob(glob)
|
43
|
+
|
44
|
+
glob = glob_for type
|
45
|
+
files = Dir.glob(glob)
|
46
|
+
files.map do |p|
|
47
|
+
if options[:verbose]
|
48
|
+
File.expand_path(p)
|
49
|
+
else
|
50
|
+
p.match(glob_to_regex glob) do |m|
|
51
|
+
components = m.captures.reject(&:empty?).map { |s| s.sub('/', '') }
|
52
|
+
components.join('/')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
43
56
|
end
|
44
57
|
|
45
58
|
private
|
@@ -77,5 +90,18 @@ module Projectionist
|
|
77
90
|
glob.sub(/\*/, file)
|
78
91
|
end
|
79
92
|
end
|
93
|
+
|
94
|
+
def glob_for(type)
|
95
|
+
glob = @type_hash[type]['glob']
|
96
|
+
glob = glob.sub('/*', '/**/*') unless glob.include? '**'
|
97
|
+
glob
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def glob_to_regex(glob)
|
102
|
+
glob.match(/(.*)[*]{2}\/(.*)/) do |m|
|
103
|
+
m[1] + '([^\x00]*?)' + m[2].gsub('*', '([^/\x00]*?)')
|
104
|
+
end
|
105
|
+
end
|
80
106
|
end
|
81
107
|
end
|
data/spec/projections_spec.rb
CHANGED
@@ -21,7 +21,7 @@ describe Projectionist::Projections do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'loads the list of types' do
|
24
|
-
expect(@projections.types
|
24
|
+
expect(@projections.types).to eq ['test']
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'has a method to check if a given type exists' do
|
@@ -46,7 +46,7 @@ describe Projectionist::Projections do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'still loads the file' do
|
49
|
-
expect(@projections.types
|
49
|
+
expect(@projections.types).to eq ['test']
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'still sets a flag that the file existed' do
|
@@ -76,8 +76,11 @@ describe Projectionist::Projections do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
describe '#files_for' do
|
79
|
-
let(:test_dir)
|
80
|
-
let(:test_files)
|
79
|
+
let(:test_dir) { File.join(fixture_folder, 'test') }
|
80
|
+
let(:test_files) do
|
81
|
+
(1..10).map { |n| File.join(test_dir, "#{n}_test.rb") }
|
82
|
+
end
|
83
|
+
let(:test_filenames) { (1..10).map(&:to_s) }
|
81
84
|
|
82
85
|
before do
|
83
86
|
write_fixtures('test/*_test.rb' => { 'type' => 'test' })
|
@@ -96,7 +99,14 @@ describe Projectionist::Projections do
|
|
96
99
|
|
97
100
|
context 'with a valid type' do
|
98
101
|
it 'matches the correct files' do
|
99
|
-
expect(@projections.files_for 'test').to match_array(
|
102
|
+
expect(@projections.files_for 'test').to match_array(test_filenames)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'with verbose: true' do
|
107
|
+
it 'returns the full filepaths' do
|
108
|
+
expect(@projections.files_for 'test', verbose: true)
|
109
|
+
.to match_array(test_files)
|
100
110
|
end
|
101
111
|
end
|
102
112
|
|
@@ -107,8 +117,9 @@ describe Projectionist::Projections do
|
|
107
117
|
end
|
108
118
|
|
109
119
|
context 'with files in child directories' do
|
110
|
-
let(:test_subdir)
|
111
|
-
let(:test_file_subdir)
|
120
|
+
let(:test_subdir) { File.join(test_dir, 'subdir') }
|
121
|
+
let(:test_file_subdir) { File.join(test_subdir, 'subdir_test.rb') }
|
122
|
+
let(:test_file_subdir_name) { 'subdir/subdir' }
|
112
123
|
before do
|
113
124
|
Dir.mkdir(test_subdir) unless Dir.exist? test_subdir
|
114
125
|
File.open(test_file_subdir, 'w')
|
@@ -117,7 +128,7 @@ describe Projectionist::Projections do
|
|
117
128
|
after { File.delete test_file_subdir }
|
118
129
|
|
119
130
|
subject { @projections.files_for('test') }
|
120
|
-
it { is_expected.to include
|
131
|
+
it { is_expected.to include test_file_subdir_name }
|
121
132
|
end
|
122
133
|
end
|
123
134
|
|
@@ -196,5 +207,18 @@ describe Projectionist::Projections do
|
|
196
207
|
subject { @projections.file_for 'test', 'foobar/file' }
|
197
208
|
it { is_expected.to eq test_file }
|
198
209
|
end
|
210
|
+
|
211
|
+
context 'with singleton projections' do
|
212
|
+
let(:singleton_file) { File.join(fixture_folder, 'README.md') }
|
213
|
+
before do
|
214
|
+
write_fixtures('README.md' => { 'type' => 'readme' })
|
215
|
+
File.open(singleton_file, 'w')
|
216
|
+
Dir.chdir fixture_folder
|
217
|
+
@projections.load_file
|
218
|
+
end
|
219
|
+
|
220
|
+
subject { @projections.file_for 'readme' }
|
221
|
+
it { is_expected.to eq singleton_file }
|
222
|
+
end
|
199
223
|
end
|
200
224
|
end
|
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.3.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-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|