confire 0.0.3 → 0.1.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/Rakefile +6 -0
- data/lib/confire/main.rb +66 -0
- data/lib/confire/parser.rb +54 -0
- data/lib/confire/processor.rb +36 -0
- data/lib/confire/project_creator.rb +26 -24
- data/lib/confire/templates/Gemfile +1 -0
- data/lib/confire/templates/config.yml +3 -1
- data/lib/confire/templates/custom_processor.rb +41 -0
- data/lib/confire/templates/driver.rb +7 -0
- data/lib/confire/templates/run.sh +1 -1
- data/lib/confire/templates/spec/custom_processor_spec.rb +29 -0
- data/lib/confire.rb +1 -1
- data/{lib/confire/templates/spec → spec}/processor_spec.rb +3 -3
- metadata +9 -5
- data/lib/confire/templates/main.rb +0 -44
- data/lib/confire/templates/parser.rb +0 -51
- data/lib/confire/templates/processor.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9950b1c6dfbf61bca27c372715a55215d305efe
|
4
|
+
data.tar.gz: 1061bfb24a79a379f87d7574dc6d7bbe40030d90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fd5efc88879058d0d3de821b90f20bd4a68b0ef5dfdf44329da00b2e4d2fca9e1b9767ed3d2327f4874b04362aa022071635af8d52ee0b41e77b6da414d589e
|
7
|
+
data.tar.gz: a7f7a6bdc253e4ae3d2da37b74b8df65a9a37ea233d1513e09043b6991875ad9c3973fcb5bfd5dd0a1d43b3db923c6e6132a3b3efc915207383ca1a57efcd5f9
|
data/Rakefile
ADDED
data/lib/confire/main.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'log4r'
|
3
|
+
require 'confire/parser'
|
4
|
+
require 'confire/processor'
|
5
|
+
include Log4r
|
6
|
+
|
7
|
+
class Confire
|
8
|
+
class Main
|
9
|
+
def initialize(options = {})
|
10
|
+
# setup configs
|
11
|
+
#config = YAML::load_file(File.join(__dir__, 'config.yml'))
|
12
|
+
config = YAML::load_file('config.yml')
|
13
|
+
filename = config['filename']
|
14
|
+
lines_per_test_case = config['lines_per_test_case']
|
15
|
+
|
16
|
+
# setup logger
|
17
|
+
log_name = options[:log_name] || 'application'
|
18
|
+
logger = Logger.new log_name
|
19
|
+
log_level = 0
|
20
|
+
case config['log_level'].to_sym
|
21
|
+
when :debug
|
22
|
+
log_level = Log4r::DEBUG
|
23
|
+
when :info
|
24
|
+
log_level = Log4r::INFO
|
25
|
+
when :warn
|
26
|
+
log_level = Log4r::WARN
|
27
|
+
when :error
|
28
|
+
log_level = Log4r::ERROR
|
29
|
+
when :fatal
|
30
|
+
log_level = Log4r::FATAL
|
31
|
+
else
|
32
|
+
log_level = 0
|
33
|
+
end if config['log_level']
|
34
|
+
logger.level = log_level
|
35
|
+
logger.outputters = Outputter.stdout
|
36
|
+
@logger = logger
|
37
|
+
|
38
|
+
# setup parser
|
39
|
+
@parser = Parser.new(
|
40
|
+
filename: filename,
|
41
|
+
lines_per_test_case: lines_per_test_case,
|
42
|
+
logger: logger
|
43
|
+
)
|
44
|
+
|
45
|
+
# setup processor that will do all the work
|
46
|
+
@processor = Processor.new(
|
47
|
+
logger: logger,
|
48
|
+
custom_processor: options[:custom_processor]
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
def run
|
53
|
+
block_processor = ->(line_buffer, test_number) do
|
54
|
+
processed_block = @processor.process_block line_buffer, test_number
|
55
|
+
puts "Case ##{test_number}: #{processed_block}"
|
56
|
+
end
|
57
|
+
|
58
|
+
line_processor = ->(line) do
|
59
|
+
@processor.process_line line
|
60
|
+
end
|
61
|
+
|
62
|
+
@parser.parse block_processor, line_processor
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Confire
|
2
|
+
# Parses the google test case
|
3
|
+
class Parser
|
4
|
+
attr_accessor :filename, :lines_per_test_case
|
5
|
+
|
6
|
+
# Remember to set:
|
7
|
+
# filename to read (will blow a ArgumentError if not set)
|
8
|
+
# lines_per_test_case
|
9
|
+
def initialize(options = {})
|
10
|
+
@filename = options[:filename]
|
11
|
+
@lines_per_test_case = options[:lines_per_test_case] || 1
|
12
|
+
@logger = options[:logger]
|
13
|
+
end
|
14
|
+
|
15
|
+
# This will read a given test case and pass that into the test_case_processor.
|
16
|
+
# A test case is defined as the number of lines_per_test_case
|
17
|
+
# Can optionally pass in a line_processor that will process a line before adding it to the buffer.
|
18
|
+
# Will stop reading after we hit the number of test cases defined in the file
|
19
|
+
# Assumption: Number of test cases is defined in the first line
|
20
|
+
def parse(test_case_processor, line_processor = nil)
|
21
|
+
(raise ArgumentError.new('Missing input filename to parse')) unless @filename
|
22
|
+
line_counter = -1
|
23
|
+
test_cases_read = 0
|
24
|
+
|
25
|
+
test_cases = 0
|
26
|
+
line_buffer = []
|
27
|
+
|
28
|
+
IO.foreach(@filename) do |line|
|
29
|
+
line.strip!
|
30
|
+
# read number of cases
|
31
|
+
if line_counter == -1
|
32
|
+
test_cases = line.to_i
|
33
|
+
# if unable to parse or we get 0, blow up
|
34
|
+
raise ArgumentError.new('Missing number of test cases on first line') if test_cases == 0
|
35
|
+
line_counter = 0
|
36
|
+
# process the test case
|
37
|
+
elsif line_counter == (lines_per_test_case - 1)
|
38
|
+
line = line_processor.call(line) if line_processor
|
39
|
+
line_buffer << line
|
40
|
+
test_cases_read += 1
|
41
|
+
test_case_processor.call(line_buffer, test_cases_read)
|
42
|
+
line_buffer = []
|
43
|
+
line_counter = 0
|
44
|
+
return if test_cases_read == test_cases
|
45
|
+
# keep reading
|
46
|
+
else
|
47
|
+
line = line_processor.call(line) if line_processor
|
48
|
+
line_buffer << line
|
49
|
+
line_counter += 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class Confire
|
2
|
+
# This is where the main bits are processed
|
3
|
+
# We can process lines and blocks here
|
4
|
+
class Processor
|
5
|
+
attr_accessor :logger, :custom_processor
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@logger = options[:logger]
|
9
|
+
@custom_processor = options[:custom_processor]
|
10
|
+
@custom_processor.logger = @logger if @custom_processor
|
11
|
+
end
|
12
|
+
|
13
|
+
# Will process a test case.
|
14
|
+
# Just return whatever we want to print out as results.
|
15
|
+
# line_buffer: an array of inputs. each line read is an element in the array
|
16
|
+
# test_number: the current test case number we are working on. probably won't need this value
|
17
|
+
def process_block(line_buffer, test_number)
|
18
|
+
if (@custom_processor && @custom_processor.class.method_defined?(:process_testcase))
|
19
|
+
@custom_processor.process_testcase line_buffer
|
20
|
+
else
|
21
|
+
line_buffer
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Process the line
|
26
|
+
# Each of these lines get stored as an element in the line_buffer array
|
27
|
+
# line: the line the process
|
28
|
+
def process_line(line)
|
29
|
+
if (@custom_processor && @custom_processor.class.method_defined?(:process_line))
|
30
|
+
@custom_processor.process_line line
|
31
|
+
else
|
32
|
+
line.split ' '
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,29 +1,31 @@
|
|
1
|
-
class
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
class Confire
|
2
|
+
class ProjectCreator
|
3
|
+
def create(project_name)
|
4
|
+
# make dir with that project_name
|
5
|
+
Dir.mkdir project_name
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
FileUtils.cp(filename_with_path('lib/confire/templates/input_sample.txt'), project_name)
|
16
|
-
#copy_and_rename project_name, 'lib/confire/templates/config_sample.yml', 'config_sample.yml', 'config.yml'
|
17
|
-
#copy_and_rename project_name, 'lib/confire/templates/processor.rb', 'config_sample.yml', 'config.yml'
|
18
|
-
end
|
7
|
+
# copy files in
|
8
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/config.yml'), project_name)
|
9
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/Gemfile'), project_name)
|
10
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/Rakefile'), project_name)
|
11
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/driver.rb'), project_name)
|
12
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/custom_processor.rb'), project_name)
|
13
|
+
FileUtils.cp_r(filename_with_path('lib/confire/templates/spec'), project_name)
|
14
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/run.sh'), project_name)
|
15
|
+
FileUtils.cp(filename_with_path('lib/confire/templates/input_sample.txt'), project_name)
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
#copy_and_rename project_name, 'lib/confire/templates/config_sample.yml', 'config_sample.yml', 'config.yml'
|
18
|
+
#copy_and_rename project_name, 'lib/confire/templates/processor.rb', 'config_sample.yml', 'config.yml'
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
def filename_with_path(filename)
|
23
|
+
File.join(Confire.root, filename)
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
def copy_and_rename(project_name, source, oldname, newname)
|
27
|
+
FileUtils.cp(source, project_name)
|
28
|
+
FileUtils.mv(File.join(project_name, oldname), File.join(project_name, newname))
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'pry'
|
2
|
+
class CustomProcessor
|
3
|
+
# Logger setup in config.yml
|
4
|
+
attr_accessor :logger
|
5
|
+
|
6
|
+
# Gets passed in a buffer (array) of lines.
|
7
|
+
# Given an input with two lines
|
8
|
+
# -------
|
9
|
+
# 5 5 23
|
10
|
+
# 3 1 1
|
11
|
+
# 1 2 3
|
12
|
+
# 4 5 6
|
13
|
+
# -------
|
14
|
+
#
|
15
|
+
# For example:
|
16
|
+
# If each test case was 2 lines long the first invocation would have the input:
|
17
|
+
# ['5 5 23', '3 1 1']
|
18
|
+
# and the second would be:
|
19
|
+
# ['1 2 3', '4 5 6']
|
20
|
+
#
|
21
|
+
# For another example:
|
22
|
+
# This method takes buffers up what is returned from process_line.
|
23
|
+
# So if process_line creates an array by using line.split ' ', you will get an array of arrays.
|
24
|
+
# First invocation:
|
25
|
+
# [["5", "5", "23"], ["3", "1", "1"]]
|
26
|
+
# Second invocation:
|
27
|
+
# [["1", "2", "3"], ["4", "5", "6"]]
|
28
|
+
def process_testcase(line_buffer)
|
29
|
+
line_buffer
|
30
|
+
end
|
31
|
+
|
32
|
+
# Processing that can be done per each line. Whatever this returns gets stored as a line in the
|
33
|
+
# array of arrays described in the process_testcase method.
|
34
|
+
# For example:
|
35
|
+
# method input: '5 5 23'
|
36
|
+
# method implementation: line.split ' '
|
37
|
+
# method output: ["5", "5", "23"]
|
38
|
+
def process_line(line)
|
39
|
+
line.split ' '
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require_relative '../custom_processor'
|
3
|
+
|
4
|
+
describe CustomProcessor do
|
5
|
+
before do
|
6
|
+
@processor = CustomProcessor.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "when asked to process a test case" do
|
10
|
+
it "must process it" do
|
11
|
+
line_buffer = [["5", "5", "23"], ["3", "1", "1"]]
|
12
|
+
expected = [["5", "5", "23"], ["3", "1", "1"]]
|
13
|
+
|
14
|
+
actual = @processor.process_testcase line_buffer
|
15
|
+
actual.must_equal expected
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "when asked to process a line" do
|
20
|
+
it "must process it" do
|
21
|
+
line = "5 5 23"
|
22
|
+
expected = ["5", "5", "23"]
|
23
|
+
|
24
|
+
actual = @processor.process_line line
|
25
|
+
actual.must_equal expected
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
data/lib/confire.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require "minitest/autorun"
|
2
|
-
|
2
|
+
require 'confire/processor'
|
3
3
|
|
4
|
-
describe Processor do
|
4
|
+
describe Confire::Processor do
|
5
5
|
before do
|
6
|
-
@processor = Processor.new
|
6
|
+
@processor = Confire::Processor.new
|
7
7
|
end
|
8
8
|
|
9
9
|
describe "when asked to process a test case" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: confire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Keam
|
@@ -17,18 +17,22 @@ executables:
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- Rakefile
|
20
21
|
- bin/confire
|
21
22
|
- lib/confire.rb
|
23
|
+
- lib/confire/main.rb
|
24
|
+
- lib/confire/parser.rb
|
25
|
+
- lib/confire/processor.rb
|
22
26
|
- lib/confire/project_creator.rb
|
23
27
|
- lib/confire/templates/Gemfile
|
24
28
|
- lib/confire/templates/Rakefile
|
25
29
|
- lib/confire/templates/config.yml
|
30
|
+
- lib/confire/templates/custom_processor.rb
|
31
|
+
- lib/confire/templates/driver.rb
|
26
32
|
- lib/confire/templates/input_sample.txt
|
27
|
-
- lib/confire/templates/main.rb
|
28
|
-
- lib/confire/templates/parser.rb
|
29
|
-
- lib/confire/templates/processor.rb
|
30
33
|
- lib/confire/templates/run.sh
|
31
|
-
- lib/confire/templates/spec/
|
34
|
+
- lib/confire/templates/spec/custom_processor_spec.rb
|
35
|
+
- spec/processor_spec.rb
|
32
36
|
homepage: https://github.com/jkeam/confire
|
33
37
|
licenses:
|
34
38
|
- MIT
|
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'log4r'
|
3
|
-
require_relative 'parser'
|
4
|
-
require_relative 'processor'
|
5
|
-
include Log4r
|
6
|
-
|
7
|
-
class Main
|
8
|
-
def initialize
|
9
|
-
# setup configs
|
10
|
-
config = YAML::load_file(File.join(__dir__, 'config.yml'))
|
11
|
-
filename = config['filename']
|
12
|
-
lines_per_test_case = config['lines_per_test_case']
|
13
|
-
|
14
|
-
# setup parser
|
15
|
-
@parser = Parser.new(
|
16
|
-
filename: filename,
|
17
|
-
lines_per_test_case: lines_per_test_case
|
18
|
-
)
|
19
|
-
|
20
|
-
# setup logger
|
21
|
-
logger = Logger.new 'application_logger'
|
22
|
-
logger.outputters = Outputter.stdout
|
23
|
-
logger.level = config['log_level']
|
24
|
-
@logger = logger
|
25
|
-
|
26
|
-
# setup processor that will do all the work
|
27
|
-
@processor = Processor.new
|
28
|
-
end
|
29
|
-
|
30
|
-
def run
|
31
|
-
block_processor = ->(line_buffer, test_number) do
|
32
|
-
processed_block = @processor.process_block line_buffer, test_number
|
33
|
-
puts "#{test_number}: #{processed_block}"
|
34
|
-
end
|
35
|
-
|
36
|
-
line_processor = ->(line) do
|
37
|
-
@processor.process_line line
|
38
|
-
end
|
39
|
-
|
40
|
-
@parser.parse block_processor, line_processor
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
Main.new.run
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# Parses the google test case
|
2
|
-
class Parser
|
3
|
-
attr_accessor :filename, :lines_per_test_case
|
4
|
-
|
5
|
-
# Remember to set:
|
6
|
-
# filename to read (will blow a ArgumentError if not set)
|
7
|
-
# lines_per_test_case
|
8
|
-
def initialize(options = {})
|
9
|
-
@filename = options[:filename]
|
10
|
-
@lines_per_test_case = options[:lines_per_test_case] || 1
|
11
|
-
end
|
12
|
-
|
13
|
-
# This will read a given test case and pass that into the test_case_processor.
|
14
|
-
# A test case is defined as the number of lines_per_test_case
|
15
|
-
# Can optionally pass in a line_processor that will process a line before adding it to the buffer.
|
16
|
-
# Will stop reading after we hit the number of test cases defined in the file
|
17
|
-
# Assumption: Number of test cases is defined in the first line
|
18
|
-
def parse(test_case_processor, line_processor = nil)
|
19
|
-
(raise ArgumentError.new('Missing input filename to parse')) unless @filename
|
20
|
-
line_counter = -1
|
21
|
-
test_cases_read = 0
|
22
|
-
|
23
|
-
test_cases = 0
|
24
|
-
line_buffer = []
|
25
|
-
|
26
|
-
IO.foreach(@filename) do |line|
|
27
|
-
line.strip!
|
28
|
-
# read number of cases
|
29
|
-
if line_counter == -1
|
30
|
-
test_cases = line.to_i
|
31
|
-
# if unable to parse or we get 0, blow up
|
32
|
-
raise ArgumentError.new('Missing number of test cases on first line') if test_cases == 0
|
33
|
-
line_counter = 0
|
34
|
-
# process the test case
|
35
|
-
elsif line_counter == (lines_per_test_case - 1)
|
36
|
-
line = line_processor.call(line) if line_processor
|
37
|
-
line_buffer << line
|
38
|
-
test_cases_read += 1
|
39
|
-
test_case_processor.call(line_buffer, test_cases_read)
|
40
|
-
line_buffer = []
|
41
|
-
line_counter = 0
|
42
|
-
return if test_cases_read == test_cases
|
43
|
-
# keep reading
|
44
|
-
else
|
45
|
-
line = line_processor.call(line) if line_processor
|
46
|
-
line_buffer << line
|
47
|
-
line_counter += 1
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
# This is where the main bits are processed
|
2
|
-
# We can process lines and blocks here
|
3
|
-
class Processor
|
4
|
-
# Will process a test case. simply return whatever we want to print out as results
|
5
|
-
def process_block(line_buffer, test_number)
|
6
|
-
line_buffer
|
7
|
-
end
|
8
|
-
|
9
|
-
# Process the line to be stored in the line_buffer
|
10
|
-
def process_line(line)
|
11
|
-
line.split ' '
|
12
|
-
end
|
13
|
-
end
|