IniSearch 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: 3974ecc9f4b8a97ba245e39db1b192355f648c2b
4
+ data.tar.gz: 054f3d5abac34a4cb5285c3b729f646da2633db0
5
+ SHA512:
6
+ metadata.gz: 1a3f7472c5d3ffc3412e98e538e487b5c447cc2176173691b4da0fd83e91fc2b5e983be73bb94f6af38854441843cd0ba4c48fdfefb09da62e0d3c5b99b2bcbd
7
+ data.tar.gz: 01bb2532426ac2128fccceb948f47aaa920ec56213cfa1a7d1d0bd5baf53a518cf1e52c529024d57d5003ceabf8bb927a90cc8b911421879c5c9b9152159a19b
data/.gitignore ADDED
@@ -0,0 +1,35 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
35
+ foo.*
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+
3
+ before_install: "gem install bones"
4
+ install: "rake gem:install_dependencies"
5
+
6
+ script: "rake"
7
+
8
+ rvm:
9
+ - 1.9.3
10
+ - 2.0.0
11
+ - 2.1.1
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "rake"
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,19 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ IniSearch (0.0.1)
5
+ inifile
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ inifile (3.0.0)
11
+ rake (10.1.0)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ IniSearch!
18
+ bundler (~> 1.0)
19
+ rake
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 shadowbq
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ ini_search
2
+ ==========
3
+
4
+ This is a native Ruby package for searching INI files to find enabled keys.
5
+
6
+ Description
7
+ -----------
8
+
9
+ Usage of `ini-search` binary.
10
+
11
+ Search ini configs
12
+ Usage: ~/ini-search [options]
13
+ -s [section regex string], default: .*
14
+ --section Section name as a regular expression to match
15
+ -k, --key [searchkey] default: key
16
+ Stanza key
17
+ -x, --check-for-existance default: false
18
+ Report existance of key in Stanza
19
+ -f, --file [configfilename] Individual ini file
20
+ -v, --verbose Verbose output
21
+ -z, --max-verbose Max Verbose output
22
+ -h, --help Display this screen
23
+
24
+ ### Example Use
25
+
26
+ $ ini-search -f ~/.rvm/gems/ruby-2.1.2/gems/IniSearch-0.0.1/test/data/good.ini -k one
27
+ section_one:one
28
+
29
+
30
+ ### Example File Format Matches
31
+
32
+ A typical INI file might look like this:
33
+
34
+ [section1]
35
+ ; some comment on section1
36
+ var1 = false
37
+ var2 = true
38
+ varA = Foobar
39
+ var3 = multiline values \
40
+ are also possible
41
+
42
+ [section2]
43
+ # another comment
44
+ var10 = baz
45
+ var20 = 1
46
+
47
+ We would be looking for section1:var2, section2:var20 as *Enabled* settings
48
+
49
+
50
+ ### Identifying Enabled Variables
51
+
52
+ * 1 --> Enabled
53
+ * "" --> Disabled
54
+ * "42" --> Set
55
+ * "1" --> Enabled
56
+ * "3.14159" --> Set
57
+ * "true" --> Enabled
58
+ * true --> Enabled
59
+ * "false" --> Disabled
60
+ * "normal string" --> Set
61
+
62
+ Install
63
+ -------
64
+
65
+ gem install IniSearch
66
+
67
+ Testing
68
+ -------
69
+
70
+ To run the tests:
71
+
72
+ $ rake
73
+
74
+ License
75
+ -------
76
+
77
+ MIT License
78
+ Copyright (c) 2006 - 2014
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'rake/testtask'
2
+ require "bundler/gem_tasks"
3
+
4
+ task :default => [:test]
5
+
6
+ Rake::TestTask.new do |test|
7
+ test.libs << "test"
8
+ test.test_files = Dir[ "test/test_*.rb" ]
9
+ test.verbose = true
10
+ end
data/bin/ini-search ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems' unless defined?(Gem)
3
+ begin
4
+ require 'bundler'
5
+ Bundler.setup(:default)
6
+ rescue ::Exception => e
7
+ end
8
+
9
+ require 'ini_search'
10
+
11
+ # Executable with absolute path to lib for hacking and development
12
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'ini_search', 'cli')
13
+
14
+ IniSearch::CLI.invoke
@@ -0,0 +1,38 @@
1
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
2
+ require File.expand_path('../lib/ini_search/version', __FILE__)
3
+ name = "IniSearch"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = name
7
+ s.version = IniSearch::VERSION
8
+
9
+ s.authors = ["shadowbq"]
10
+ s.date = %q{2014-08-01}
11
+ s.description = %q{A simple ini search gem}
12
+ s.email = %q{shadowbq@gmail.com}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.homepage = "http://github.com/shadowbq/#{name}"
16
+
17
+
18
+ s.summary = s.description
19
+ s.license = 'MIT'
20
+ s.platform = Gem::Platform::RUBY
21
+ s.executables = ["ini-search"]
22
+
23
+ s.required_rubygems_version = ">= 1.8.1"
24
+
25
+ s.add_development_dependency 'bundler', '~> 1.0'
26
+
27
+ s.add_runtime_dependency 'inifile'
28
+
29
+ if s.respond_to? :specification_version then
30
+ s.specification_version = 3
31
+
32
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
33
+ else
34
+ end
35
+ else
36
+ end
37
+ end
38
+
@@ -0,0 +1,78 @@
1
+ module IniSearch
2
+ class CLI
3
+
4
+ def self.invoke
5
+ self.new
6
+ end
7
+
8
+ def initialize
9
+ @options = {}
10
+ @options[:verbose] = 0
11
+ @options[:key] = 'key'
12
+ @options[:sect_regexp] = Regexp.new('.*')
13
+ @options[:find_existance] = false
14
+
15
+ optparse = OptionParser.new do |opts|
16
+ opts.banner = "Search ini configs"
17
+ opts.separator "Usage: #$0 [options]"
18
+
19
+ opts.on( '-s', '--section [section regex string]', "default: #{@options[:sect_regexp].source}", 'Section name as a regular expression to match') do |section|
20
+ @options[:sect_regexp] = Regexp.new(section)
21
+ end
22
+
23
+ opts.on( '-k', '--key [searchkey]', "default: #{@options[:key]}", 'Stanza key') do |key|
24
+ @options[:key] = key
25
+ end
26
+
27
+ opts.on( '-x', '--check-for-existance ', "default: #{@options[:find_existance]}", 'Report existance of key in Stanza') do
28
+ @options[:find_existance] = true
29
+ end
30
+
31
+ opts.on( '-f', '--file [configfilename]', 'Individual ini file') do |conf|
32
+ @options[:file] = conf
33
+ end
34
+
35
+ opts.on('-v', '--verbose', 'Verbose output') do
36
+ @options[:verbose] = 1
37
+ end
38
+
39
+ opts.on('-z', '--max-verbose', 'Max Verbose output') do
40
+ @options[:verbose] = 2
41
+ end
42
+
43
+ opts.on_tail( '-h', '--help', 'Display this screen' ) do
44
+ puts opts
45
+ exit
46
+ end
47
+
48
+ end
49
+
50
+ #Verify the options
51
+ begin
52
+ raise unless ARGV.size > 0
53
+ optparse.parse!
54
+ exclusive_options = [:verbose, :scandir]
55
+
56
+ if (exclusive_options.collect{|item| item if @options.include? item}.compact).length > 1
57
+ puts "Error: Mutually Exclusive options were selected"
58
+ puts optparse
59
+ exit
60
+ end
61
+
62
+ #If options fail display help
63
+ rescue
64
+ puts optparse
65
+ exit
66
+ end
67
+
68
+ begin
69
+ Searcher.new(obj_inifile: IniFile.new(:filename => @options[:file]), key: @options[:key], sect_regexp: @options[:sect_regexp], find_existance: @options[:find_existance], verbosity: @options[:verbose])
70
+ rescue
71
+ $stderr.puts "Could not read #{@options[:file]}"
72
+ exit 1
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,7 @@
1
+ module IniSearch
2
+ module Helper
3
+ def verbose(msg, level=0)
4
+ puts msg if level > 0
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,59 @@
1
+ module IniSearch
2
+ class Searcher
3
+ include Helper
4
+
5
+ def initialize(arg={})
6
+ @inifile = arg[:obj_inifile] || (raise MissingIniFile)
7
+ @verbosity = arg[:verbosity] || 0
8
+ @key = arg[:key] || (raise MissingSearchKey)
9
+ @find_existance = arg[:find_existance] || false
10
+ @section_regex = arg[:sect_regexp] || Regexp.new('.*')
11
+ do_search
12
+ end
13
+
14
+ private
15
+
16
+ #obj_inifile, key, find_existance
17
+ def do_search
18
+ @inifile.each_section do |section|
19
+ if @inifile[section].has_key?(@key) && section.match(@section_regex)
20
+ verbose("Found '#{section}:#{@key}' Exists: ", @verbosity) if @find_existance
21
+ puts "#{section}" if @find_existance
22
+ if key_enabled?(section) && !(key_falsy?(section))
23
+ verbose("Found '#{section}:#{@key}' Enabled: #{@inifile[section][@key]} ", @verbosity)
24
+ puts "#{section}:#{@key}"
25
+ elsif key_falsy?(section)
26
+ verbose("Found '#{section}:#{@key}' Disabled: #{@inifile[section][@key]} ", @verbosity)
27
+ else
28
+ verbose("Found '#{section}:#{@key}' Set: #{@inifile[section][@key]} ", @verbosity)
29
+ end
30
+ end
31
+ end #enum
32
+ end #def
33
+
34
+ def key_enabled?(section)
35
+ begin
36
+ if @inifile[section][@key].to_s == "1" || @inifile[section][@key].to_s.downcase == "true" || @inifile[section][@key] == true
37
+ return true
38
+ else
39
+ return false
40
+ end
41
+ rescue
42
+ raise FailureIniDataSet
43
+ end
44
+ end
45
+
46
+ def key_falsy?(section)
47
+ begin
48
+ if @inifile[section][@key].to_s == "0" || @inifile[section][@key] == "" || @inifile[section][@key].to_s.downcase == "false"
49
+ return true
50
+ else
51
+ return false
52
+ end
53
+ rescue
54
+ raise FailureIniDataSet
55
+ end
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module IniSearch
2
+ VERSION = '0.0.1'
3
+ end
data/lib/ini_search.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'inifile'
2
+ require 'optparse'
3
+ require 'rubygems' unless defined?(Gem)
4
+
5
+ module IniSearch
6
+ class MissingIniFile < StandardError; end
7
+ class MissingSearchKey < StandardError; end
8
+ class FailureIniDataSet < StandardError; end
9
+
10
+ $:.unshift(File.dirname(__FILE__))
11
+ %w( helper cli searcher ).each do |lib|
12
+ begin
13
+ require "ini_search/#{lib}"
14
+ rescue LoadError
15
+ require File.expand_path(File.join(File.dirname(__FILE__), 'ini_search', lib))
16
+ end
17
+ end
18
+
19
+ end
20
+
21
+
22
+
@@ -0,0 +1,18 @@
1
+ [section_one]
2
+ one = 1
3
+ two = 2
4
+
5
+ [section_two]
6
+ three = -3
7
+ multi = multiline \
8
+ support
9
+
10
+ ; comments should be ignored
11
+ [section three]
12
+ four =true
13
+ five=false # comments can go here
14
+ six =6.0 ; and here, too
15
+
16
+ [section_four]
17
+ [section_five]
18
+ seven and eight= 7 & 8
@@ -0,0 +1,65 @@
1
+ # encoding: UTF-8
2
+
3
+ libpath = File.expand_path '../../lib', __FILE__
4
+ require File.join(libpath, 'ini_search')
5
+ require 'fileutils'
6
+ require 'test/unit'
7
+
8
+
9
+ class TestIniSearch < Test::Unit::TestCase
10
+
11
+ def setup
12
+ @ini_file = IniFile.new(:filename => 'test/data/good.ini')
13
+ FileUtils.cp "test/data/good.ini", "test/data/tmp.ini"
14
+ end
15
+
16
+ def teardown
17
+ FileUtils.rm_rf "test/data/tmp.ini"
18
+ end
19
+
20
+ def test_class_load
21
+ ini_file = IniFile.load 'test/data/good.ini'
22
+ assert_instance_of IniFile, ini_file
23
+ end
24
+
25
+ def test_has_section_eh
26
+ assert_equal true, @ini_file.has_section?('section_one')
27
+ assert_equal false, @ini_file.has_section?('section_ten')
28
+ end
29
+
30
+ def test_read
31
+ @ini_file.read
32
+ assert_equal 1, @ini_file['section_one']['one']
33
+ assert_equal 2, @ini_file['section_one']['two']
34
+ end
35
+
36
+ def test_match_section_regex_1
37
+ out, err = capture_io do
38
+ IniSearch::Searcher.new(obj_inifile: @ini_file, key: 'one', find_existance: true)
39
+ end
40
+ assert_match "section_one\nsection_one:one", out
41
+ end
42
+
43
+
44
+ def test_match_section_regex_2
45
+ out, err = capture_io do
46
+ IniSearch::Searcher.new(obj_inifile: @ini_file, key: 'four', sect_regexp: Regexp.new('secti.*'))
47
+ end
48
+ assert_match "section three:four", out
49
+ end
50
+
51
+ def test_match_section_regex_3
52
+ out, err = capture_io do
53
+ IniSearch::Searcher.new(obj_inifile: @ini_file, key: 'three', sect_regexp: Regexp.new('section_.*'))
54
+ end
55
+ assert_match "", out
56
+ end
57
+
58
+ def test_match_section_regex_4
59
+ out, err = capture_io do
60
+ IniSearch::Searcher.new(obj_inifile: @ini_file, key: 'five', sect_regexp: Regexp.new('section_.*'))
61
+ end
62
+ assert_match "", out
63
+ end
64
+
65
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: IniSearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - shadowbq
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-01 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.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: inifile
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A simple ini search gem
42
+ email: shadowbq@gmail.com
43
+ executables:
44
+ - ini-search
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - bin/ini-search
56
+ - ini_search.gemspec
57
+ - lib/ini_search.rb
58
+ - lib/ini_search/cli.rb
59
+ - lib/ini_search/helper.rb
60
+ - lib/ini_search/searcher.rb
61
+ - lib/ini_search/version.rb
62
+ - test/data/good.ini
63
+ - test/test_ini_search.rb
64
+ homepage: http://github.com/shadowbq/IniSearch
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 1.8.1
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.2.2
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: A simple ini search gem
88
+ test_files: []