sanultari-config 0.1.0.RC1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@sanconfig"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.14.2 ()" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "ZenTest", "~> 4.8.1"
10
+ gem "autotest-growl", "~> 0.2.16"
11
+ gem "rspec", "~> 2.11"
12
+ gem "yard", "~> 0.7"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", "~> 1.1"
15
+ gem "jeweler", "~> 1.8.3"
16
+ gem "rcov", ">= 0", :platform => [:ruby_18, :mingw_18]
17
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,40 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ ZenTest (4.8.1)
5
+ autotest-growl (0.2.16)
6
+ diff-lcs (1.1.3)
7
+ git (1.2.5)
8
+ jeweler (1.8.4)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rdoc
13
+ json (1.7.3)
14
+ rake (0.9.2.2)
15
+ rcov (1.0.0)
16
+ rdoc (3.12)
17
+ json (~> 1.4)
18
+ rspec (2.11.0)
19
+ rspec-core (~> 2.11.0)
20
+ rspec-expectations (~> 2.11.0)
21
+ rspec-mocks (~> 2.11.0)
22
+ rspec-core (2.11.0)
23
+ rspec-expectations (2.11.1)
24
+ diff-lcs (~> 1.1.3)
25
+ rspec-mocks (2.11.1)
26
+ yard (0.8.2.1)
27
+
28
+ PLATFORMS
29
+ ruby
30
+ x86-mingw32
31
+
32
+ DEPENDENCIES
33
+ ZenTest (~> 4.8.1)
34
+ autotest-growl (~> 0.2.16)
35
+ bundler (~> 1.1)
36
+ jeweler (~> 1.8.3)
37
+ rcov
38
+ rdoc (~> 3.12)
39
+ rspec (~> 2.11)
40
+ yard (~> 0.7)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Jeong, Jiung
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ = sanconfig
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to sanconfig
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Jeong, Jiung. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "sanultari-config"
18
+ gem.homepage = "https://github.com/sanultari/config"
19
+ gem.license = "AFL"
20
+ gem.summary = %Q{Simple configuration}
21
+ gem.description = %Q{This library provides simple configuration management with object's attributes. sanconfig support yaml as datastore.}
22
+ gem.email = "ethernuiel@sanultari.com"
23
+ gem.authors = ["Jeong, Jiung"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'yard'
42
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0.RC1
@@ -0,0 +1,6 @@
1
+ test: 'a'
2
+ alpha: 12345
3
+ list_test: [1,2,3]
4
+ list:
5
+ - 4
6
+ - 5
data/fixture/tree.yml ADDED
@@ -0,0 +1,4 @@
1
+ a: test
2
+ test:
3
+ a: confirm
4
+ b: cancel
@@ -0,0 +1,3 @@
1
+ module SanUltari; end
2
+
3
+ require 'sanultari/config'
@@ -0,0 +1,71 @@
1
+ require 'sanultari/config/store'
2
+ require 'yaml'
3
+
4
+ module SanUltari
5
+ class Config
6
+ attr_accessor :name, :path
7
+
8
+ def initialize name = nil
9
+ @name = name || nil
10
+ @path = File.expand_path '.'
11
+ @store_class = Class.new SanUltari::Config::Store
12
+ @store = @store_class.new
13
+ end
14
+
15
+ def init! path = nil
16
+ return nil if path == nil
17
+ if @name == nil
18
+ @name = File.basename path, '.yml'
19
+ @path = File.expand_path File.dirname(path), @path
20
+ end
21
+ config_hash = YAML.load_file make_path
22
+ from_hash(config_hash)
23
+ end
24
+
25
+ def save path = nil
26
+ @name = 'config' if @name == nil
27
+ path = make_path if path == nil
28
+
29
+ File.open(make_path(path), 'w') do |f|
30
+ YAML.dump(to_hash, f)
31
+ end
32
+ end
33
+
34
+ def from_hash hash
35
+ raise Exception.new unless hash.instance_of?(Hash)
36
+
37
+ hash.each_pair do |key, value|
38
+ t_value = value
39
+ if value.instance_of? Hash
40
+ t_value = Config.new key
41
+ t_value.from_hash value
42
+ end
43
+
44
+ @store.send("#{key}=".to_sym, t_value)
45
+ end
46
+ end
47
+
48
+ def to_hash
49
+ hash = {}
50
+ @store.keys.each do |key|
51
+ value = @store.send key.to_sym
52
+ value = value.to_hash if value.instance_of? SanUltari::Config
53
+ hash[key] = value
54
+ end
55
+ hash
56
+ end
57
+
58
+ def make_path path = nil
59
+ return File.expand_path "#{@name}.yml", @path if path == nil
60
+ if path.start_with?('/', '\\')
61
+ return path
62
+ else
63
+ return File.expand_path(path, @path)
64
+ end
65
+ end
66
+
67
+ def method_missing(method_name, *args, &block)
68
+ @store.send method_name, *args, &block
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,41 @@
1
+ module SanUltari
2
+ class Config
3
+ class Store
4
+ def [] name
5
+ @values ||= {}
6
+
7
+ @values[name] = SanUltari::Config.new name if @values[name] == nil
8
+ @values[name]
9
+ end
10
+
11
+ def []= name, value
12
+ @values ||= {}
13
+
14
+ @values[name] = value
15
+ end
16
+
17
+ def keys
18
+ return [] if @values == nil
19
+ @values.keys
20
+ end
21
+
22
+ def method_missing(method_name, *args, &block)
23
+ name = method_name.to_s
24
+ name.chomp!('=')
25
+
26
+ self.class.instance_eval do
27
+ define_method(name.to_sym) do |&blk|
28
+ blk.call self[name] if blk != nil
29
+ self[name]
30
+ end if not public_methods.include? name.to_sym
31
+
32
+ define_method("#{name}=".to_sym) do |value|
33
+ self[name] = value
34
+ end
35
+ end
36
+
37
+ send method_name, *args, &block
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "SanUltari::Config::Store" do
4
+ before :each do
5
+ @fixture = SanUltari::Config::Store.new
6
+ end
7
+
8
+ it "should initialze" do
9
+ SanUltari::Config::Store.new
10
+ end
11
+
12
+ it "should set plain value" do
13
+ expected = 'test'
14
+ @fixture.a = expected
15
+ @fixture.a.should be_equal expected
16
+ end
17
+
18
+ it "should set tree value" do
19
+ expected = 'test'
20
+ @fixture.a.b = expected
21
+ @fixture.a.should_not be_nil
22
+ @fixture.a.b.should be_equal expected
23
+ end
24
+
25
+ it "should set tree value with block" do
26
+ expected = 'test'
27
+ @fixture.a do |conf|
28
+ conf.b = expected
29
+ conf.c = 3
30
+ end
31
+ @fixture.a.b.should be_equal expected
32
+ @fixture.a.c.should be_equal 3
33
+ end
34
+ end
@@ -0,0 +1,74 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'tempfile'
3
+
4
+ describe "SanUltari::Config" do
5
+ before :all do
6
+ @origin = Dir.getwd
7
+ Dir.chdir File.expand_path('../fixture', File.dirname(__FILE__))
8
+ end
9
+
10
+ before :each do
11
+ @fixture = SanUltari::Config.new
12
+ end
13
+
14
+ it "should not have properties" do
15
+ expected = 'test'
16
+ @fixture.a = expected
17
+ @fixture.a.should be_equal expected
18
+ @fixture.class.instance_methods.should_not include :a
19
+ end
20
+
21
+ it "should create object without yaml file" do
22
+ @fixture.init!
23
+ @fixture.name.should be_nil
24
+ @fixture.path.should eql File.expand_path('.')
25
+ end
26
+
27
+ it "should create object with yaml file" do
28
+ @fixture.init! 'config.yml'
29
+ @fixture.test.should eql 'a'
30
+ @fixture.alpha.should eql 12345
31
+ @fixture.list_test.length.should eql 3
32
+ @fixture.list.length.should eql 2
33
+ @fixture.name.should eql 'config'
34
+ @fixture.path.should eql File.expand_path('.')
35
+ end
36
+
37
+ it "should create tree object with yaml file" do
38
+ @fixture.init! 'tree.yml'
39
+ @fixture.a.should eql 'test'
40
+ @fixture.test.a.should eql 'confirm'
41
+ end
42
+
43
+ it "should dump to yaml file" do
44
+ test_file = 'tree.yml'
45
+ @fixture.init! test_file
46
+
47
+ tmp_file = nil
48
+ Tempfile.open(['dump', '.yml']) do |f|
49
+ tmp_file = f
50
+ @fixture.save tmp_file.path
51
+ end
52
+
53
+ File.open(test_file, 'r') do |o|
54
+ File.open(tmp_file.path, 'r') do |f|
55
+ dump = cleanup f.read
56
+ origin = cleanup o.read
57
+ dump.should eql origin
58
+ end
59
+ end
60
+
61
+ tmp_file.unlink
62
+ end
63
+
64
+ after :all do
65
+ Dir.chdir @origin
66
+ end
67
+
68
+ private
69
+ def cleanup string
70
+ string.gsub! /^$(\r|\n|\r\n)/, ''
71
+ string.gsub! /^---$(\r|\n|\r\n)/, ''
72
+ string.each_line.sort.join
73
+ end
74
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'sanultari-config'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sanultari-config
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0.RC1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Jeong, Jiung
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: ZenTest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 4.8.1
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 4.8.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: autotest-growl
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 0.2.16
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.2.16
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.11'
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '0.7'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.7'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rdoc
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '3.12'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '3.12'
94
+ - !ruby/object:Gem::Dependency
95
+ name: bundler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.1'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.1'
110
+ - !ruby/object:Gem::Dependency
111
+ name: jeweler
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.8.3
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.8.3
126
+ - !ruby/object:Gem::Dependency
127
+ name: rcov
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: This library provides simple configuration management with object's attributes.
143
+ sanconfig support yaml as datastore.
144
+ email: ethernuiel@sanultari.com
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files:
148
+ - LICENSE.txt
149
+ - README.md
150
+ files:
151
+ - .document
152
+ - .rspec
153
+ - .rvmrc
154
+ - Gemfile
155
+ - Gemfile.lock
156
+ - LICENSE.txt
157
+ - README.md
158
+ - Rakefile
159
+ - VERSION
160
+ - fixture/config.yml
161
+ - fixture/tree.yml
162
+ - lib/sanultari-config.rb
163
+ - lib/sanultari/config.rb
164
+ - lib/sanultari/config/store.rb
165
+ - spec/config/store_spec.rb
166
+ - spec/config_spec.rb
167
+ - spec/spec_helper.rb
168
+ homepage: https://github.com/sanultari/config
169
+ licenses:
170
+ - AFL
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ none: false
177
+ requirements:
178
+ - - ! '>='
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ segments:
182
+ - 0
183
+ hash: 805368188006248101
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>'
188
+ - !ruby/object:Gem::Version
189
+ version: 1.3.1
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 1.8.24
193
+ signing_key:
194
+ specification_version: 3
195
+ summary: Simple configuration
196
+ test_files: []