richmond 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/README.md +30 -0
- data/lib/richmond.rb +33 -14
- data/lib/richmond/rtfm.rb +7 -7
- data/lib/richmond/scan_settings.rb +41 -0
- data/lib/richmond/version.rb +1 -1
- data/spec/lib/rtfm_spec.rb +8 -2
- data/spec/lib/scan_settings_spec.rb +71 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c38d13d4efc091f68338f2c9cee24b21c4e51d2
|
4
|
+
data.tar.gz: 7c03fc180e6e9957a2bb3296b64854b1fdbf57d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92408bd96cc30f5abcbddbdb2e495e3c70cd311ae3d1b15cd54d409c9267c96e4d8aff9adae483ebd2556206a30e7189d5596d5db9d150932a17883fa9898ca7
|
7
|
+
data.tar.gz: bf732a45e67845e1ceae3fbb0fb5101ecf0efbd2b2dafdcddb6ac1263e628282b87681b47a0fb9908182bae1d4cad5f2ca9511a7d6e751b6cdec80e92b84ec42
|
data/README.md
CHANGED
@@ -57,6 +57,36 @@ Successive blocks targeting the same output file can be written as follows:
|
|
57
57
|
|
58
58
|
Richmond will take any text in the block and insert it into the specified output file.
|
59
59
|
|
60
|
+
# Configuration
|
61
|
+
|
62
|
+
Richmond will look for a file called .richmond in the root directory you are running against.
|
63
|
+
If it finds the .richmond file, it will load it.
|
64
|
+
|
65
|
+
You can use the select or reject methods to change which files Richmond will include or exlude
|
66
|
+
in it's processing.
|
67
|
+
|
68
|
+
# Richmond doesn't like binary files
|
69
|
+
Richmond.reject do |file|
|
70
|
+
file.match /images/
|
71
|
+
end
|
72
|
+
|
73
|
+
# I only want to parse .rb files
|
74
|
+
Richmond.select do |file|
|
75
|
+
file.match /\.rb$/
|
76
|
+
end
|
77
|
+
|
78
|
+
# Release Notes
|
79
|
+
|
80
|
+
## 0.3.0
|
81
|
+
|
82
|
+
* Richmond was failing on binary files. Richmond can now be configured to ignore
|
83
|
+
or target specific files or directories via a .richmond file found in the root
|
84
|
+
of the directory being processed.
|
85
|
+
|
86
|
+
## 0.2.0
|
87
|
+
|
88
|
+
Initial public beta release
|
89
|
+
|
60
90
|
## Contributing
|
61
91
|
|
62
92
|
1. Fork it ( https://github.com/crmckenzie/richmond/fork )
|
data/lib/richmond.rb
CHANGED
@@ -1,29 +1,48 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
|
1
|
+
dir = File.dirname(File.expand_path(__FILE__))
|
2
|
+
search = "#{dir}/**/*.rb"
|
3
|
+
Dir.glob(search).each {|file| require file }
|
4
|
+
|
5
5
|
require 'find'
|
6
6
|
|
7
7
|
module Richmond
|
8
8
|
|
9
|
-
@@
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
@@default_select_blocks = [
|
10
|
+
]
|
11
|
+
|
12
|
+
@@default_reject_blocks = [
|
13
|
+
lambda {|f| File.directory? f},
|
14
|
+
lambda {|f| f.split('/').include? '.git' }
|
15
|
+
]
|
16
|
+
|
17
|
+
@@select_blocks = @@default_select_blocks
|
18
|
+
@@reject_blocks = @@default_reject_blocks
|
19
|
+
|
20
|
+
def self.reset_filters
|
21
|
+
@@select_blocks = @@default_select_blocks
|
22
|
+
@@reject_blocks = @@default_reject_blocks
|
14
23
|
end
|
15
24
|
|
16
|
-
def self.
|
17
|
-
@@
|
25
|
+
def self.select_filters
|
26
|
+
@@select_blocks
|
18
27
|
end
|
19
28
|
|
20
|
-
def self.
|
21
|
-
@@
|
29
|
+
def self.reject_filters
|
30
|
+
@@reject_blocks
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.select(&block)
|
34
|
+
@@select_blocks.push block
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.reject(&block)
|
38
|
+
@@reject_blocks.push block
|
22
39
|
end
|
23
40
|
|
24
41
|
def self.generate(dir)
|
25
42
|
rtfm = RTFM.new
|
26
|
-
|
43
|
+
settings = Richmond::ScanSettings.new dir
|
44
|
+
|
45
|
+
scan = rtfm.scan settings
|
27
46
|
rtfm.emit scan.output
|
28
47
|
end
|
29
48
|
|
data/lib/richmond/rtfm.rb
CHANGED
@@ -26,9 +26,9 @@ module Richmond
|
|
26
26
|
File.expand_path smatch
|
27
27
|
end
|
28
28
|
|
29
|
-
def scan(
|
29
|
+
def scan(scan_settings)
|
30
30
|
logger.info "beginning scan"
|
31
|
-
result = scan_files
|
31
|
+
result = scan_files scan_settings.files
|
32
32
|
logger.info "scan finished"
|
33
33
|
result
|
34
34
|
end
|
@@ -43,14 +43,14 @@ module Richmond
|
|
43
43
|
|
44
44
|
lines = File.readlines file
|
45
45
|
lines.each_with_index do |line, i|
|
46
|
-
line.encode!('UTF-8', 'UTF-8', :invalid => :replace)
|
47
|
-
|
46
|
+
#line.encode!('UTF-8', 'UTF-8', :invalid => :replace)
|
47
|
+
begin
|
48
48
|
end_recording! line if end_recording? line
|
49
49
|
record! line if recording?
|
50
50
|
begin_recording! line if begin_recording? line
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
rescue Exception => error
|
52
|
+
logger.debug "error recording line: #{file}: line: #{i}: #{line} => #{error}"
|
53
|
+
end
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Richmond
|
2
|
+
class ScanSettings
|
3
|
+
attr_reader :dir
|
4
|
+
|
5
|
+
def initialize(dir)
|
6
|
+
@dir = File.expand_path dir
|
7
|
+
richmond_file = File.join(@dir, '.richmond')
|
8
|
+
|
9
|
+
Kernel.load richmond_file if File.exists? richmond_file
|
10
|
+
end
|
11
|
+
|
12
|
+
def file_selectors=(value)
|
13
|
+
@file_selectors = value
|
14
|
+
end
|
15
|
+
|
16
|
+
def file_selectors
|
17
|
+
@file_selectors
|
18
|
+
end
|
19
|
+
|
20
|
+
def file_rejectors=(value)
|
21
|
+
@file_rejectors = value
|
22
|
+
end
|
23
|
+
|
24
|
+
def file_rejectors
|
25
|
+
@file_rejectors
|
26
|
+
end
|
27
|
+
|
28
|
+
def files
|
29
|
+
|
30
|
+
files = Find.find(dir).to_a
|
31
|
+
Richmond.select_filters.each do |block|
|
32
|
+
files.select!(&block)
|
33
|
+
end
|
34
|
+
Richmond.reject_filters.each do |block|
|
35
|
+
files.reject!(&block)
|
36
|
+
end
|
37
|
+
files
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
data/lib/richmond/version.rb
CHANGED
data/spec/lib/rtfm_spec.rb
CHANGED
@@ -45,7 +45,10 @@ describe Richmond::RTFM do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
describe '.rtfm' do
|
48
|
-
let!(:result) {
|
48
|
+
let!(:result) {
|
49
|
+
settings = Richmond::ScanSettings.new dir
|
50
|
+
return subject.scan settings
|
51
|
+
}
|
49
52
|
|
50
53
|
describe 'simple comment block' do
|
51
54
|
|
@@ -130,7 +133,10 @@ this:
|
|
130
133
|
end
|
131
134
|
|
132
135
|
describe '.emit' do
|
133
|
-
let!(:input_result) {
|
136
|
+
let!(:input_result) {
|
137
|
+
settings = Richmond::ScanSettings.new dir
|
138
|
+
return subject.scan settings
|
139
|
+
}
|
134
140
|
|
135
141
|
before(:each) do
|
136
142
|
input_result.output.each_pair do |file, lines|
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
describe Richmond::ScanSettings do
|
3
|
+
|
4
|
+
describe '.new' do
|
5
|
+
it 'expands dir to full path' do
|
6
|
+
settings = Richmond::ScanSettings.new '.'
|
7
|
+
expect(settings.dir).to eq File.expand_path '.'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Richmond.select filter' do
|
12
|
+
before(:each) do
|
13
|
+
Richmond.reset_filters
|
14
|
+
end
|
15
|
+
after(:each) do
|
16
|
+
Richmond.reset_filters
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'will grab filters from global context' do
|
20
|
+
Richmond.select { |file|
|
21
|
+
file.match(/scan_settings_spec/)
|
22
|
+
}
|
23
|
+
|
24
|
+
settings = Richmond::ScanSettings.new '.'
|
25
|
+
|
26
|
+
expect(settings.files.size).to eq 1
|
27
|
+
puts settings.files
|
28
|
+
expect(settings.files).to include File.expand_path(__FILE__)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe 'Richmond.reject filter' do
|
33
|
+
before(:each) do
|
34
|
+
Richmond.reset_filters
|
35
|
+
end
|
36
|
+
after(:each) do
|
37
|
+
Richmond.reset_filters
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'will grab filters from global context' do
|
41
|
+
Richmond.reject { |file|
|
42
|
+
file.match(/scan_settings_spec/)
|
43
|
+
}
|
44
|
+
|
45
|
+
settings = Richmond::ScanSettings.new '.'
|
46
|
+
expect(settings.files).to_not include File.expand_path(__FILE__)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe 'when a .richmond file is present' do
|
51
|
+
before(:each) do
|
52
|
+
Richmond.reset_filters
|
53
|
+
end
|
54
|
+
after(:each) do
|
55
|
+
Richmond.reset_filters
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'loads the richmond file' do
|
59
|
+
file = File.expand_path File.join('.', '.richmond')
|
60
|
+
expect(File).to receive(:exists?).with(file)
|
61
|
+
.and_return(true)
|
62
|
+
|
63
|
+
expect(Kernel).to receive(:load).with(file)
|
64
|
+
.and_return true
|
65
|
+
|
66
|
+
Richmond::ScanSettings.new '.'
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: richmond
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crmckenzie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,9 +99,11 @@ files:
|
|
99
99
|
- lib/richmond/logging.rb
|
100
100
|
- lib/richmond/rtfm.rb
|
101
101
|
- lib/richmond/scan_result.rb
|
102
|
+
- lib/richmond/scan_settings.rb
|
102
103
|
- lib/richmond/version.rb
|
103
104
|
- richmond.gemspec
|
104
105
|
- spec/lib/rtfm_spec.rb
|
106
|
+
- spec/lib/scan_settings_spec.rb
|
105
107
|
- spec/spec_helper.rb
|
106
108
|
- tasks/rspec.rake
|
107
109
|
homepage: ''
|
@@ -130,4 +132,5 @@ specification_version: 4
|
|
130
132
|
summary: scrap files for content and emit an aggregate file
|
131
133
|
test_files:
|
132
134
|
- spec/lib/rtfm_spec.rb
|
135
|
+
- spec/lib/scan_settings_spec.rb
|
133
136
|
- spec/spec_helper.rb
|