yack 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +40 -0
- data/lib/yack.rb +48 -0
- metadata +49 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Florian Motlik
|
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,40 @@
|
|
1
|
+
Yack
|
2
|
+
===
|
3
|
+
|
4
|
+
Yack is a library to create simple callbacks for loading your Yaml files. It is especially useful when loading config files. Instead of pulling the values out of the config file you simply add callbacks and when the attributes exist in the file a code block is run.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
------------
|
8
|
+
|
9
|
+
gem install yack
|
10
|
+
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
Consider you have the following YAML File
|
14
|
+
|
15
|
+
---
|
16
|
+
:parent:
|
17
|
+
:child: "TestString"
|
18
|
+
|
19
|
+
Simply create a new callback object
|
20
|
+
|
21
|
+
yack = Yack::Callback.new
|
22
|
+
|
23
|
+
then simply add some callbacks
|
24
|
+
|
25
|
+
yack.parent.child do |value|
|
26
|
+
puts value
|
27
|
+
end
|
28
|
+
|
29
|
+
and start the processing
|
30
|
+
|
31
|
+
yack.process_yaml(YAML_STRING)
|
32
|
+
|
33
|
+
Your Code block will be called with the value of the attribute which in the last example would be "TestString".
|
34
|
+
|
35
|
+
License
|
36
|
+
-------
|
37
|
+
|
38
|
+
Copyright (c) 2012 Florian Motlik.
|
39
|
+
|
40
|
+
Released under the MIT license. See `LICENSE` for details.
|
data/lib/yack.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Yack
|
4
|
+
class Callback
|
5
|
+
def initialize
|
6
|
+
@groups = {}
|
7
|
+
end
|
8
|
+
|
9
|
+
def process_yaml yaml
|
10
|
+
yaml = YAML::load(yaml)
|
11
|
+
yaml.each{|key, value|
|
12
|
+
_call_back yaml, @groups
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing m, *args, &block
|
17
|
+
block_given? ? @groups[m] = block : Handler.new(m, @groups)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def _call_back key, value
|
22
|
+
return if key.nil? or value.nil?
|
23
|
+
case(key)
|
24
|
+
when Hash
|
25
|
+
_call_back key[key.keys.first], value[key.keys.first]
|
26
|
+
else
|
27
|
+
value.call(key)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Handler
|
33
|
+
def initialize method, groups
|
34
|
+
groups[method] ||= {}
|
35
|
+
@groups = groups[method]
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_missing m, *args, &block
|
39
|
+
if block_given?
|
40
|
+
@groups[m] = block
|
41
|
+
else
|
42
|
+
@groups[m] ||= {}
|
43
|
+
@groups = @groups[m]
|
44
|
+
return self
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Florian Motlik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-17 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Churn through Yaml file via callbacks. Define rules for specific parameters,
|
15
|
+
load the yaml file and get callbacks if the routes match
|
16
|
+
email: flo@railsonfire.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- lib/yack.rb
|
24
|
+
homepage: https://github.com/flomotlik/yack
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.10
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Churn through Yaml file via callbacks. Define rules for specific parameters,
|
48
|
+
load the yaml file and get callbacks if the routes match
|
49
|
+
test_files: []
|