parse-conf 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f02d7265ae01b6764aa024132cddae71a46ac172
4
+ data.tar.gz: 9c65f619c53bcfa2f2574f00c515e00687cc47b1
5
+ SHA512:
6
+ metadata.gz: c5288e10706fb317639d7a143bd2d3ae71d5397c607f38d1eacb5164073c6866e1dcaa78aae18beefc14edd8311c59cbe05c9b23bb6d50f87da59b563da4d360
7
+ data.tar.gz: 8b94744adc7031861a234c763c106061e8495fd3ce165ef6d2c4075956b925810c1c52902ea2acd86b1c248a6f3936ebf2f0e75b655aa02df9d4b7070d800275
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ config/database.yml
2
+ config/*.sphinx.conf
3
+ config/s3_credentials.yml
4
+ *~
5
+ *.cache
6
+ *.log
7
+ *.pid
8
+ tmp/**/*
9
+ .DS_Store
10
+ db/cstore/**
11
+ db/sphinx/**
12
+ doc/api
13
+ doc/app
14
+ doc/plugins
15
+ doc/*.dot
16
+ coverage/*
17
+ db/*.sqlite3
18
+ *.tmproj
19
+ *.sw?
20
+ .idea
21
+ public/assets/**/*
22
+
23
+ *~
24
+ \#*\#
25
+ /.emacs.desktop
26
+ /.emacs.desktop.lock
27
+ *.elc
28
+ auto-save-list
29
+ tramp
30
+ .\#*
31
+
32
+ # Org-mode
33
+ .org-id-locations
34
+ *_archive
35
+
36
+ # flymake-mode
37
+ *_flymake.*
38
+
39
+ # eshell files
40
+ /eshell/history
41
+ /eshell/lastdir
42
+
43
+ # elpa packages
44
+ /elpa/
45
+
46
+ # reftex files
47
+ *.rel
48
+
49
+ # AUCTeX auto folder
50
+ /auto/
data/.projectile ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in parse-conf.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ parse-conf (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.0)
10
+ ffi (1.9.3-java)
11
+ method_source (0.8.2)
12
+ minitest (5.3.4)
13
+ pry (0.9.12.6)
14
+ coderay (~> 1.0)
15
+ method_source (~> 0.8)
16
+ slop (~> 3.4)
17
+ pry (0.9.12.6-java)
18
+ coderay (~> 1.0)
19
+ method_source (~> 0.8)
20
+ slop (~> 3.4)
21
+ spoon (~> 0.0)
22
+ rake (10.3.2)
23
+ slop (3.5.0)
24
+ spoon (0.0.4)
25
+ ffi
26
+
27
+ PLATFORMS
28
+ java
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ bundler (~> 1.5)
33
+ minitest
34
+ parse-conf!
35
+ pry
36
+ rake
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 maringan
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Parse::Conf
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'parse-conf'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install parse-conf
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/parse-conf/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = "test/*_test.rb"
7
+ end
@@ -0,0 +1,53 @@
1
+ require "pry"
2
+
3
+ module Parse
4
+ module Conf
5
+ class GitosisStyle
6
+ attr_reader :config_raw, :data, :empty_group_name
7
+
8
+ Helper = Parse::Conf::ParserHelper
9
+
10
+ def initialize(config_raw, separator = " ")
11
+ @config_raw = config_raw
12
+ @data = {}
13
+
14
+ @empty_group_name = 'without_group'
15
+ @separator = separator
16
+ @data[empty_group_name] = []
17
+ end
18
+
19
+ def result
20
+ parse unless @parsed
21
+ @data
22
+ end
23
+
24
+ def self.run(config_raw, separator = " ")
25
+ obj = new(config_raw, separator)
26
+ obj.result
27
+ end
28
+
29
+ private
30
+ def parse
31
+ @parsed = true
32
+
33
+ group_name = nil
34
+ config_raw.lines.each do |line|
35
+ next if line == "\n" || line =~ /^\#.*/
36
+
37
+ if line =~ /\[.*\]/i
38
+ group_name = Helper.trim_and_remove_ugly_symbol(line)
39
+ data[group_name] = []
40
+ else
41
+ item = line.split("=").map{ |it| Helper.trim_and_remove_ugly_symbol(it) }
42
+ key, value = item[0], item[1].split(@separator)
43
+
44
+ insert_etntry = {key => value}
45
+ insert_key = group_name ? group_name : empty_group_name
46
+
47
+ data[insert_key].push(insert_etntry)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,26 @@
1
+ module Parse
2
+ module Conf
3
+ class ParserHelper
4
+ attr_reader :string
5
+
6
+ def initialize(string)
7
+ @string = string
8
+ end
9
+
10
+ def self.trim_and_remove_ugly_symbol(string)
11
+ obj = new(string)
12
+ obj.trim!
13
+ obj.remove_ugly_symbol!
14
+ obj.string
15
+ end
16
+
17
+ def trim!
18
+ string.strip!
19
+ end
20
+
21
+ def remove_ugly_symbol!
22
+ string.gsub!(/(\[|\])/, '')
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Parse
2
+ module Conf
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/parse/conf.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "parse/conf/version"
2
+ require "parse/conf/parser_helper"
3
+ require "parse/conf/gitosis_style"
4
+
5
+
6
+ module Parse
7
+ module Conf
8
+ end
9
+ end
@@ -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 'parse/conf'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "parse-conf"
8
+ spec.version = Parse::Conf::VERSION
9
+ spec.authors = ["maringan"]
10
+ spec.email = ["kamil.kucharski88+1@gmail.com"]
11
+ spec.summary = %q{Parse standard unix config}
12
+ spec.description = %q{Parse standard unix config}
13
+ spec.homepage = "http://github.com/"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "minitest"
23
+ spec.add_development_dependency "pry"
24
+ end
@@ -0,0 +1,64 @@
1
+ # this config file tries to show a bit of everything, most real life
2
+ # configurations really only need a "group" section with "members" and
3
+ # "writable"
4
+
5
+ [gitosis]
6
+ ## To override the default ~/repositories path
7
+ # repositories = repositories
8
+
9
+ ## Allow gitweb to show all known repositories. If you want gitweb,
10
+ ## you need either this or a [repo foo] section for each repository
11
+ ## you want visible in gitweb.
12
+ gitweb = no
13
+
14
+ ## Allow git-daemon to publish all known repositories. As with gitweb,
15
+ ## this can be done globally or per-repository.
16
+ daemon = no
17
+
18
+ ## Logging level, one of DEBUG, INFO, WARNING, ERROR, CRITICAL
19
+ loglevel = DEBUG
20
+
21
+ [group quux]
22
+ members = jdoe wsmith @anothergroup
23
+ writable = foo bar baz/thud
24
+ readonly = xyzzy
25
+
26
+ ## You can use groups just to avoid listing users multiple times. Note
27
+ ## no writable= or readonly= lines.
28
+ [group anothergroup]
29
+ members = alice bill
30
+
31
+ ## You can play fancy tricks by making some repositories appear with
32
+ ## different names in different contexts. Not really supported
33
+ ## everywhere (e.g. gitweb) and can be confusing -- experts only.
34
+ map writable visiblename1 = actualname1
35
+ map readonly visiblename2 = actualname2
36
+
37
+ [repo foo]
38
+ ## Allow gitweb to show this repository.
39
+ gitweb = yes
40
+
41
+ ## Oneline description of the project, mostly for gitweb.
42
+ description = blah blah
43
+
44
+ ## Owner of this repository. Used in gitweb list of projects.
45
+ owner = John Doe
46
+
47
+ ## Allow git-daemon to publish this repository.
48
+ daemon = yes
49
+
50
+ [gitweb]
51
+ ## Where to make gitweb link to as it's "home location".
52
+ ## NOT YET IMPLEMENTED.
53
+ # homelink = http://example.com/
54
+
55
+ ## Set a mirror for all repository
56
+ ## (all repositories with a post-receive hook
57
+ ## running "gitosis-run-hook update-mirrors")
58
+ [mirror github]
59
+ repos = @all
60
+ uri = git@github.com:res0nat0r/%s.git
61
+
62
+ ## Add a mirror for the bar repository
63
+ [repo bar]
64
+ mirrors = /var/trac/bar/repository
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+
4
+ class GitosisStyleTest < MiniTest::Unit::TestCase
5
+ def setup
6
+ @expected_result = {"without_group"=>[], "gitosis"=>[{"gitweb"=>["no"]}, {"daemon"=>["no"]}, {"loglevel"=>["DEBUG"]}], "group quux"=>[{"members"=>["jdoe", "wsmith", "@anothergroup"]}, {"writable"=>["foo", "bar", "baz/thud"]}, {"readonly"=>["xyzzy"]}], "group anothergroup"=>[{"members"=>["alice", "bill"]}, {"map writable visiblename1"=>["actualname1"]}, {"map readonly visiblename2"=>["actualname2"]}], "repo foo"=>[{"gitweb"=>["yes"]}, {"description"=>["blah", "blah"]}, {"owner"=>["John", "Doe"]}, {"daemon"=>["yes"]}], "gitweb"=>[], "mirror github"=>[{"repos"=>["@all"]}, {"uri"=>["git@github.com:res0nat0r/%s.git"]}], "repo bar"=>[{"mirrors"=>["/var/trac/bar/repository"]}]}
7
+
8
+ @config_raw = File.open('test/config_example/gitosis.conf').read
9
+ @parser = Parse::Conf::GitosisStyle.new(@config_raw)
10
+ end
11
+
12
+ def test_instance_of_class
13
+ assert_instance_of Parse::Conf::GitosisStyle, @parser
14
+ end
15
+
16
+ def test_return_hash
17
+ assert_kind_of Hash, @parser.result
18
+ end
19
+
20
+ def test_result
21
+ assert_equal @expected_result, @parser.result
22
+ end
23
+
24
+ def test_run
25
+ assert_equal @expected_result, Parse::Conf::GitosisStyle.run(@config_raw)
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class ParserHelperTest < MiniTest::Unit::TestCase
4
+ def setup
5
+ @text = " [group gitosis]\n "
6
+ @parser_helper = Parse::Conf::ParserHelper
7
+ end
8
+
9
+ def test_trim!
10
+ obj = @parser_helper.new(@text)
11
+ obj.trim!
12
+
13
+ assert_equal "[group gitosis]", obj.string
14
+ end
15
+
16
+ def test_remove_ugly_symbol!
17
+ obj = @parser_helper.new(@text)
18
+ obj.remove_ugly_symbol!
19
+
20
+ assert_equal " group gitosis\n ", obj.string
21
+ end
22
+
23
+ def test_trim_and_remove_ugly_symbol!
24
+ assert_equal 'group gitosis', @parser_helper.trim_and_remove_ugly_symbol(@text)
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ require 'minitest'
2
+ require 'minitest/unit'
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parse-conf
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - maringan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-19 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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: minitest
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
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Parse standard unix config
70
+ email:
71
+ - kamil.kucharski88+1@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".projectile"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - lib/parse/conf.rb
84
+ - lib/parse/conf/gitosis_style.rb
85
+ - lib/parse/conf/parser_helper.rb
86
+ - lib/parse/conf/version.rb
87
+ - parse-conf.gemspec
88
+ - test/config_example/gitosis.conf
89
+ - test/gitosis_style_test.rb
90
+ - test/parse_helper_test.rb
91
+ - test/test_helper.rb
92
+ homepage: http://github.com/
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.2.1
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: Parse standard unix config
116
+ test_files:
117
+ - test/config_example/gitosis.conf
118
+ - test/gitosis_style_test.rb
119
+ - test/parse_helper_test.rb
120
+ - test/test_helper.rb