deb_control 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8756498877b70f0be2440e409f3bbd1412f92750
4
+ data.tar.gz: b9616abf04b84e749ee2de4d984c2eab3e60721d
5
+ SHA512:
6
+ metadata.gz: e7dd18e61c91721633bbaadda341a2744cd5aba3aa8e218934bf200a148d0ad68de0830a83f560fac66191c4506710dcb4e09e5ae5a6c0d36892021b346e72ea
7
+ data.tar.gz: 803f2373ebfe00a10cfde4e6735775a95b76e29559a4243d2ad3da00f05a840f6601a45afcf535a745ff8715629a1acf0534385cb59e882d86a0d8ad36e14d25
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .idea
4
+ *.iml
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development do
4
+ gem 'coveralls', require: false
5
+ end
6
+
7
+ # Specify your gem's dependencies in deb_control.gemspec
8
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Malte Swart
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.
@@ -0,0 +1,48 @@
1
+ # DebControl
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/deb_control.png)](http://badge.fury.io/rb/deb_control)
4
+ [![Build Status](https://travis-ci.org/mswart/deb_control.png?branch=master)](https://travis-ci.org/mswart/deb_control)
5
+ [![Coverage Status](https://coveralls.io/repos/mswart/deb_control/badge.png?branch=master)](https://coveralls.io/r/mswart/deb_control)
6
+ [![Code Climate](https://codeclimate.com/github/mswart/deb_control.png)](https://codeclimate.com/github/mswart/deb_control)
7
+
8
+ DebControl contains helper classes to read Debian control files. Write support is planed.
9
+
10
+ **This gem is under development. Every 0.x release might break backwards compatibility.**
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ gem 'deb_control', '~> 0.0.1'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install deb_control
25
+
26
+
27
+ ## Usage
28
+
29
+ The Class DebControl::ControlFileBase implements a generic parser for control files:
30
+
31
+ ```ruby
32
+ control = DebControl::ControlFileBase.read 'debian/control'
33
+ # receive the array from paragraphs:
34
+ control.paragraphs.size
35
+ # receive fields of paragraph:
36
+ control.paragraphs.first['Source']
37
+ ```
38
+
39
+ Each paragraph is a Hash containing its fields and values.
40
+
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ 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 'deb_control/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'deb_control'
8
+ spec.version = DebControl::VERSION
9
+ spec.authors = ['Malte Swart']
10
+ spec.email = %w(mswart@devtation.de)
11
+ spec.description = 'Helpers to read debian control files'
12
+ spec.summary = File.read('README.md')
13
+ spec.homepage = 'https://github.com/mswart/deb_control'
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 = %w(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,5 @@
1
+ require 'deb_control/version'
2
+ require 'deb_control/control_file_base'
3
+
4
+ module DebControl
5
+ end
@@ -0,0 +1,76 @@
1
+ module DebControl
2
+ # Generic parser class for control files. It is design to be used as parent classes for specific
3
+ # files like the debian source control file.
4
+ #
5
+ # @api public
6
+ class ControlFileBase
7
+ # @api public
8
+ # @param [String] filecontent A string with all data that should be parsed
9
+ # @return [Array<Hash<String, String>>] The parsed data: a array of paragraphs. Each paragraph
10
+ # is a Hash contain its field value pairs.
11
+ def self.parse(filecontent)
12
+ parsed = []
13
+ current_paragraph = []
14
+ filecontent.split("\n").each do |line|
15
+ if line.strip == ''
16
+ parsed << parse_paragraph(current_paragraph)
17
+ current_paragraph = []
18
+ else
19
+ current_paragraph << line
20
+ end
21
+ end
22
+
23
+ if current_paragraph.size > 0
24
+ parsed << parse_paragraph(current_paragraph)
25
+ end
26
+ parsed
27
+ end
28
+
29
+
30
+ # @api private
31
+ # @param [Array<String>] lines all lines of the paragraph
32
+ # @return [Hash<String, String>] parsed key value pairs
33
+ #
34
+ def self.parse_paragraph(lines)
35
+ fields = {}
36
+ field = nil
37
+ value = nil
38
+ lines.each do |line|
39
+ if line.include? ':' # no value
40
+ unless field.nil?
41
+ fields[field] = value
42
+ end
43
+ field, value = line.split ':', 2
44
+ value.strip!
45
+ elsif line =~ /^\s/
46
+ value += "\n" + line.strip
47
+ else
48
+ # error
49
+ end
50
+ end
51
+ unless field.nil?
52
+ fields[field] = value
53
+ end
54
+ fields
55
+ end
56
+
57
+ # Create a new ControlFileBase instances with the contain of the given file name.
58
+ #
59
+ # @api public
60
+ # @param [String] filename A relative or absolute file name to the file that should be parsed.
61
+ # @return [ControlFileBase] A new object instance contain the parsed data. Use the paragraphs
62
+ # accessor to use them.
63
+ # @example
64
+ # control = ControlFileBase.read 'debian/control'
65
+ # puts control.paragraphs.first['Source']
66
+ def self.read(filename)
67
+ new parse File.read filename
68
+ end
69
+
70
+ def initialize(paragraphs)
71
+ @paragraphs = paragraphs
72
+ end
73
+
74
+ attr_reader :paragraphs
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module DebControl
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,99 @@
1
+ require 'spec_helper'
2
+
3
+ describe DebControl::ControlFileBase do
4
+ subject { DebControl::ControlFileBase }
5
+ describe '#parse' do
6
+ let(:single) do
7
+ <<-EOF
8
+ Field1: b
9
+ Field2: c
10
+ EOF
11
+ end
12
+ let(:multiple) do
13
+ <<-EOF
14
+ Field1: c
15
+ Field3: b
16
+
17
+ Field6: 9
18
+ Field7: b
19
+ EOF
20
+ end
21
+ let(:multiple_with_space) do
22
+ <<-EOF
23
+ Field1: c
24
+ Field3: b
25
+ EOF + ' ' + <<-EOF
26
+ Field6: 9
27
+ Field7: b
28
+ EOF
29
+ end
30
+
31
+ context 'paragraph splitting' do
32
+ it 'parse paragraph' do
33
+ expect(subject).to receive(:parse_paragraph).with(['Field1: b', 'Field2: c']).ordered
34
+ expect(subject.parse(single).size).to eq 1
35
+ end
36
+
37
+ it 'parse multiple paragraphs separately' do
38
+ expect(subject).to receive(:parse_paragraph).with(['Field1: c', 'Field3: b']).ordered
39
+ expect(subject).to receive(:parse_paragraph).with(['Field6: 9', 'Field7: b']).ordered
40
+ expect(subject.parse(multiple).size).to eq 2
41
+ end
42
+
43
+ it 'parse multiple paragraphs separated by line with spaces' do
44
+ expect(subject).to receive(:parse_paragraph).with(['Field1: c', 'Field3: b']).ordered
45
+ expect(subject).to receive(:parse_paragraph).with(['Field6: 9', 'Field7: b']).ordered
46
+ expect(subject.parse(multiple).size).to eq 2
47
+ end
48
+ end
49
+
50
+ context 'high level' do
51
+ it 'parse paragraphs and fields' do
52
+ parsed = subject.parse multiple
53
+ expect(parsed.size).to eq 2
54
+ expect(parsed[0]).to eq({'Field1' => 'c', 'Field3' => 'b'})
55
+ expect(parsed[1]).to eq({'Field6' => '9', 'Field7' => 'b'})
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#parse_paragraph' do
61
+ it 'single value without space' do
62
+ expect(subject.parse_paragraph(['Field:value'])).to eq({ 'Field' => 'value' })
63
+ end
64
+
65
+ it 'single value' do
66
+ expect(subject.parse_paragraph(['Field: value'])).to eq({ 'Field' => 'value' })
67
+ end
68
+
69
+ it 'single value with trailing space' do
70
+ expect(subject.parse_paragraph(['Field: value '])).to eq({ 'Field' => 'value' })
71
+ end
72
+
73
+ it 'value with colon' do
74
+ expect(subject.parse_paragraph(['Field: v:alue'])).to eq({ 'Field' => 'v:alue' })
75
+ end
76
+
77
+ it 'two values' do
78
+ values = subject.parse_paragraph(['Field: v:alue', 'Key: data'])
79
+ expect(values).to eq({ 'Field' => 'v:alue', 'Key' => 'data' })
80
+ expect(values.keys).to eq ['Field', 'Key']
81
+ end
82
+
83
+ it 'multi-line values' do
84
+ values = subject.parse_paragraph(['Field: first-line', ' second-line'])
85
+ expect(values).to eq({ 'Field' => "first-line\nsecond-line"})
86
+ end
87
+ end
88
+
89
+ describe '#read' do
90
+ let(:filename) { File.expand_path '../../fixtures/simple_control_file.txt', __FILE__ }
91
+
92
+ it 'should parse the file' do
93
+ parsed = subject.read filename
94
+ expect(parsed).to be_instance_of subject
95
+ expect(parsed.paragraphs.size).to eq 2
96
+ expect(parsed.paragraphs.first['Field1']).to eq 'c'
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,5 @@
1
+ Field1: c
2
+ Field3: b
3
+
4
+ Field6: 9
5
+ Field7: b
@@ -0,0 +1,29 @@
1
+ require 'coveralls'
2
+ Coveralls.wear! do
3
+ add_filter 'spec'
4
+ end
5
+
6
+ require 'deb_control'
7
+
8
+ Dir[File.expand_path('spec/support/**/*.rb')].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+ # ## Mock Framework
12
+ #
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ #
15
+ # config.mock_with :mocha
16
+ # config.mock_with :flexmock
17
+ # config.mock_with :rr
18
+
19
+ # Run specs in random order to surface order dependencies. If you find an
20
+ # order dependency and want to debug it, you can fix the order by providing
21
+ # the seed, which is printed after each run.
22
+ # --seed 1234
23
+ config.order = 'random'
24
+
25
+ config.expect_with :rspec do |c|
26
+ # Only allow expect syntax
27
+ c.syntax = :expect
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deb_control
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Malte Swart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-30 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: Helpers to read debian control files
56
+ email:
57
+ - mswart@devtation.de
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - deb_control.gemspec
69
+ - lib/deb_control.rb
70
+ - lib/deb_control/control_file_base.rb
71
+ - lib/deb_control/version.rb
72
+ - spec/deb_control/control_file_base_spec.rb
73
+ - spec/fixtures/simple_control_file.txt
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/mswart/deb_control
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: '# DebControl [![Gem Version](https://badge.fury.io/rb/deb_control.png)](http://badge.fury.io/rb/deb_control)
99
+ [![Build Status](https://travis-ci.org/mswart/deb_control.png?branch=master)](https://travis-ci.org/mswart/deb_control)
100
+ [![Coverage Status](https://coveralls.io/repos/mswart/deb_control/badge.png?branch=master)](https://coveralls.io/r/mswart/deb_control)
101
+ [![Code Climate](https://codeclimate.com/github/mswart/deb_control.png)](https://codeclimate.com/github/mswart/deb_control) DebControl
102
+ contains helper classes to read Debian control files. Write support is planed. **This
103
+ gem is under development. Every 0.x release might break backwards compatibility.** ##
104
+ Installation Add this line to your application''s Gemfile: gem ''deb_control'',
105
+ ''~> 0.0.1'' And then execute: $ bundle Or install it yourself as: $ gem install
106
+ deb_control ## Usage The Class DebControl::ControlFileBase implements a generic
107
+ parser for control files: ```ruby control = DebControl::ControlFileBase.read ''debian/control''
108
+ # receive the array from paragraphs: control.paragraphs.size # receive fields of
109
+ paragraph: control.paragraphs.first[''Source''] ``` Each paragraph is a Hash containing
110
+ its fields and values. ## Contributing 1. Fork it 2. Create your feature branch
111
+ (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am ''Add
112
+ some feature''`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create
113
+ new Pull Request'
114
+ test_files:
115
+ - spec/deb_control/control_file_base_spec.rb
116
+ - spec/fixtures/simple_control_file.txt
117
+ - spec/spec_helper.rb