configgler 0.1.2

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in configgy.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ Configgy
2
+ =======
3
+
4
+ This is a spin off of some abandoned code which may or may not be useful.
5
+
6
+ Provides an idiomatic way of accessing config elements from yaml files.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/TODO.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ == To make this (more) useful:
2
+
3
+ * Find a way to return the actual value for the last call in a method chain
4
+
5
+ * Find a compromise solution for getting config elements that share a method name with something in the class hierarchy
6
+
7
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "configgler/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "configgler"
7
+ s.version = Configgler::VERSION
8
+ s.authors = ["max sharples"]
9
+ s.email = ["maxsharples@gmail.com"]
10
+ s.homepage = "https://github.com/msharp/configgler"
11
+ s.summary = %q{Idiomatic access to yaml configuration files}
12
+ s.description = %q{Get data from your config files in different ways}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_development_dependency "rspec"
20
+ end
data/lib/configgler.rb ADDED
@@ -0,0 +1,20 @@
1
+ """
2
+ nicer api to get data from the yaml configuration files
3
+
4
+ usage example =>
5
+ c = Configgler.load('config.yml','./')
6
+ puts c.smtp.host
7
+ OR
8
+ puts c.get(:smtp,:host)
9
+ TODO : handle existing object methods (type,id,class)
10
+ """
11
+ module Configgler
12
+
13
+ require "configgler/version"
14
+ require "configgler/config"
15
+
16
+ def self.load(file,*args)
17
+ Configgler::Config.new(file,args)
18
+ end
19
+
20
+ end
@@ -0,0 +1,52 @@
1
+ require 'yaml'
2
+
3
+ module Configgler
4
+
5
+ class Config
6
+
7
+ attr_accessor :config
8
+
9
+ def initialize(file,*args)
10
+ @config = YAML.load(File.new(File.join(args.flatten.join('/'),file)))
11
+ end
12
+
13
+ def method_missing(name,*args)
14
+ el = ConfigElement.new(@config,name.to_s)
15
+ el.is_a?(Hash) ? el : el.value
16
+ end
17
+
18
+ def get_by_array(args=[])
19
+ c = @config[args.shift.to_s]
20
+ until args.length == 0
21
+ c = c[args.shift.to_s]
22
+ end
23
+ c
24
+ end
25
+
26
+ def get(*args)
27
+ get_by_array(args)
28
+ end
29
+
30
+ class ConfigElement
31
+
32
+ attr_accessor :element
33
+
34
+ def initialize(config,element)
35
+ @element = config[element.to_s]
36
+ self
37
+ end
38
+
39
+ def method_missing(name)
40
+ el = ConfigElement.new(@element,name.to_s)
41
+ el.is_a?(Hash) ? el : el.value
42
+ end
43
+
44
+ def value
45
+ @element
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,3 @@
1
+ module Configgler
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift '../lib/'
2
+ require 'configgler'
3
+
4
+ describe Configgler do
5
+
6
+ describe '#load' do
7
+ it 'should load a yaml file' do
8
+ c = Configgler.load('configgler_spec.yml', File.dirname(__FILE__), 'yaml')
9
+ c.first.should == 1
10
+ end
11
+ end
12
+
13
+ end
14
+
15
+
@@ -0,0 +1,15 @@
1
+ first: 1
2
+ second:
3
+ - 1
4
+ - 2
5
+ - 3
6
+ third:
7
+ hash:
8
+ h1: foo
9
+ h2: bar
10
+ h3:
11
+ - 1
12
+ - 2
13
+ - 3
14
+ - 4
15
+ fourth: nil
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: configgler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - max sharples
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-19 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: Get data from your config files in different ways
35
+ email:
36
+ - maxsharples@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - README.md
47
+ - Rakefile
48
+ - TODO.rdoc
49
+ - configgler.gemspec
50
+ - lib/configgler.rb
51
+ - lib/configgler/config.rb
52
+ - lib/configgler/version.rb
53
+ - spec/configgler_spec.rb
54
+ - spec/yaml/configgler_spec.yml
55
+ homepage: https://github.com/msharp/configgler
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.10
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Idiomatic access to yaml configuration files
88
+ test_files: []
89
+