structura 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: 50aa01efafd6ded7076f51fee213210c74a35934
4
+ data.tar.gz: 915291ebec61849a803777117e128ac51b1f9dbf
5
+ SHA512:
6
+ metadata.gz: 8cde176a5675b9cfcf0514b4c4772b7875bcb0aea29f7d5eee37ff8b50f9cda94092c901b64ae5d5558b996d9ea0c1e9de9e4634e2ecbca31f6ff61d12758d69
7
+ data.tar.gz: 829b6fc34f2e8dbb8abe6d2fbbf7510a267625b02a0cc2805912459795160f7d5936ff792227d1808e58d4bc8f468ef8423a6d78f574c02c53cff29f4e29571c
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in structura.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Stephen Yu
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,47 @@
1
+ # Structura
2
+
3
+ Configuration File Reader Gem
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'structura'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install structura
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ require 'structura'
23
+
24
+ Structura::Cfg.instance.load_file 'config.yaml'
25
+
26
+ p Structura::Cfg.instance.read_value('section_one', 'value_one')
27
+ p Structura::Cfg.instance.read_value('section_one', 'value_two')
28
+ ```
29
+
30
+ The Configuration File Format
31
+
32
+ ```
33
+ section_one:
34
+ :value_one: "1.1"
35
+ :value_two: "1.2"
36
+
37
+ section_two:
38
+ :value_one: '2.1'
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run all RSpec tests"
5
+ RSpec::Core::RakeTask.new(:spec)
data/lib/structura.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'yaml'
2
+ require 'singleton'
3
+
4
+ # Internal Requires
5
+ require "structura/version"
6
+ require "structura/cfg"
@@ -0,0 +1,33 @@
1
+ require 'yaml'
2
+ require 'singleton'
3
+
4
+ module Structura
5
+ class Cfg
6
+ include Singleton
7
+
8
+ def read_value section, variable
9
+ raise LoadError, 'Configuration file has not been loaded' if !@cfg
10
+
11
+ is_string section
12
+ is_string variable
13
+
14
+ return false if !@cfg.include? section
15
+ return false if !@cfg[section].include? string_to_symbol(variable)
16
+
17
+ @cfg[section][string_to_symbol(variable)]
18
+ end
19
+
20
+ def load_file file_path
21
+ raw_config = File.read(file_path)
22
+ @cfg = YAML.load(raw_config)
23
+ end
24
+
25
+ def string_to_symbol string
26
+ string.to_s.downcase.gsub(/\s+/, "_").to_sym
27
+ end
28
+
29
+ def is_string target
30
+ raise ArgumentError, "Expected String Parameter: #{target}" if !target.instance_of? String
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Structura
2
+ VERSION = "0.0.1"
3
+ end
data/spec/cfg_spec.rb ADDED
@@ -0,0 +1,38 @@
1
+ require './spec/spec_helper'
2
+
3
+ describe Structura::Cfg.instance do
4
+
5
+ before do
6
+ stub_const "FakeCfgClass", Structura::Cfg.clone
7
+ end
8
+
9
+ it "can`'t use the Cfg without loading a configuration file'" do
10
+ expect {FakeCfgClass.instance.read_value 'aaa', 'bbb'}.to raise_error LoadError
11
+ end
12
+
13
+ it "is_string: exceptions and working" do
14
+ expect {FakeCfgClass.instance.is_string 123}.to raise_error ArgumentError
15
+ expect {FakeCfgClass.instance.is_string '123'}.not_to raise_error
16
+ end
17
+
18
+ it "string_to_symbol: convert string to symbol" do
19
+ expect(FakeCfgClass.instance.string_to_symbol("string")).to eq :string
20
+ end
21
+
22
+ it "Cfg will raise exception when using non string arguments" do
23
+ FakeCfgClass.instance.load_file 'spec/config.yaml'
24
+ expect {FakeCfgClass.instance.read_value(:section, :value)}.to raise_error ArgumentError
25
+ end
26
+
27
+ it "Cfg read expected values, return false for values that don't exist" do
28
+ FakeCfgClass.instance.load_file 'spec/config.yaml'
29
+
30
+ FakeCfgClass.instance.read_value('section_one', 'one').should eq 'one'
31
+ FakeCfgClass.instance.read_value('section_one', 'two').should eq 'two'
32
+ FakeCfgClass.instance.read_value('section_two', 'one').should eq 'one'
33
+
34
+ FakeCfgClass.instance.read_value('section_one', 'fake_value').should be_false
35
+ FakeCfgClass.instance.read_value('fake_section', 'one').should be_false
36
+ end
37
+
38
+ end
data/spec/config.yaml ADDED
@@ -0,0 +1,6 @@
1
+ section_one:
2
+ :one: "one"
3
+ :two: "two"
4
+
5
+ section_two:
6
+ :one: 'one'
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'structura'
data/structura.gemspec ADDED
@@ -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 'structura/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "structura"
8
+ spec.version = Structura::VERSION
9
+ spec.authors = ["Stephen Yu"]
10
+ spec.email = ["s.yu@less3.com"]
11
+ spec.description = ["Reading a Configuration File"]
12
+ spec.summary = ["Straight forward gem for reading a Configuration File"]
13
+ spec.homepage = "https://github.com/stephenyu/Structura"
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 = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: structura
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stephen Yu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-20 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: '["Reading a Configuration File"]'
56
+ email:
57
+ - s.yu@less3.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/structura.rb
68
+ - lib/structura/cfg.rb
69
+ - lib/structura/version.rb
70
+ - spec/cfg_spec.rb
71
+ - spec/config.yaml
72
+ - spec/spec_helper.rb
73
+ - structura.gemspec
74
+ homepage: https://github.com/stephenyu/Structura
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.5
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: '["Straight forward gem for reading a Configuration File"]'
98
+ test_files:
99
+ - spec/cfg_spec.rb
100
+ - spec/config.yaml
101
+ - spec/spec_helper.rb