yagni 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rvmrc +55 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +32 -0
- data/Guardfile +5 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +59 -0
- data/lib/yell/hash.rb +122 -0
- data/lib/yell/version.rb +5 -0
- data/lib/yell.rb +6 -0
- data/rdoc/README_rdoc.html +132 -0
- data/rdoc/Yell/Hash.html +554 -0
- data/rdoc/Yell.html +158 -0
- data/rdoc/created.rid +5 -0
- data/rdoc/index.html +72 -0
- data/rdoc/lib/yell/hash_rb.html +55 -0
- data/rdoc/lib/yell/version_rb.html +55 -0
- data/rdoc/lib/yell_rb.html +52 -0
- data/rdoc/rdoc.css +706 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/yell/hash_spec.rb +83 -0
- metadata +122 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1,55 @@
|
|
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
|
+
environment_id="ruby-1.9.3-p0@yell"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment following line if you want options to be set only for given project.
|
11
|
+
#
|
12
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
13
|
+
|
14
|
+
#
|
15
|
+
# First we attempt to load the desired environment directly from the environment
|
16
|
+
# file. This is very fast and efficient compared to running through the entire
|
17
|
+
# CLI and selector. If you want feedback on which environment was used then
|
18
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
19
|
+
#
|
20
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
21
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
22
|
+
then
|
23
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
24
|
+
|
25
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
26
|
+
then
|
27
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
28
|
+
fi
|
29
|
+
else
|
30
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
31
|
+
if ! rvm --create "$environment_id"
|
32
|
+
then
|
33
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
34
|
+
exit 1
|
35
|
+
fi
|
36
|
+
fi
|
37
|
+
|
38
|
+
#
|
39
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
40
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
41
|
+
# necessary.
|
42
|
+
#
|
43
|
+
# filename=".gems"
|
44
|
+
# if [[ -s "$filename" ]]
|
45
|
+
# then
|
46
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
47
|
+
# fi
|
48
|
+
|
49
|
+
# If you use bundler, this might be useful to you:
|
50
|
+
# if command -v bundle && [[ -s Gemfile ]]
|
51
|
+
# then
|
52
|
+
# bundle install
|
53
|
+
# fi
|
54
|
+
|
55
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.3)
|
5
|
+
git (1.2.5)
|
6
|
+
guard (0.8.4)
|
7
|
+
thor (~> 0.14.6)
|
8
|
+
guard-rspec (0.4.5)
|
9
|
+
guard (>= 0.4.0)
|
10
|
+
jeweler (1.6.4)
|
11
|
+
bundler (~> 1.0)
|
12
|
+
git (>= 1.2.5)
|
13
|
+
rake
|
14
|
+
rake (0.9.2)
|
15
|
+
rspec (2.6.0)
|
16
|
+
rspec-core (~> 2.6.0)
|
17
|
+
rspec-expectations (~> 2.6.0)
|
18
|
+
rspec-mocks (~> 2.6.0)
|
19
|
+
rspec-core (2.6.4)
|
20
|
+
rspec-expectations (2.6.0)
|
21
|
+
diff-lcs (~> 1.1.2)
|
22
|
+
rspec-mocks (2.6.0)
|
23
|
+
thor (0.14.6)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler
|
30
|
+
guard-rspec
|
31
|
+
jeweler
|
32
|
+
rspec
|
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Renato Mascarenhas
|
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.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= yell
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to yell
|
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) 2011 Renato Mascarenhas. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('lib/yell/version')
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'bundler'
|
7
|
+
begin
|
8
|
+
Bundler.setup(:default, :development)
|
9
|
+
rescue Bundler::BundlerError => e
|
10
|
+
$stderr.puts e.message
|
11
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
12
|
+
exit e.status_code
|
13
|
+
end
|
14
|
+
require 'rake'
|
15
|
+
|
16
|
+
require 'jeweler'
|
17
|
+
Jeweler::Tasks.new do |gem|
|
18
|
+
gem.name = "yagni"
|
19
|
+
gem.version = Yell::VERSION
|
20
|
+
|
21
|
+
gem.homepage = "http://github.com/rmascarenhas/yell"
|
22
|
+
gem.license = "MIT"
|
23
|
+
|
24
|
+
gem.summary = %Q{yell is a simple hash library which aims to provide
|
25
|
+
a method-like access}
|
26
|
+
|
27
|
+
gem.description = <<-END
|
28
|
+
yell provides an easy way to access your hash values using its
|
29
|
+
simple, method-like notation. Useful when parsing complex hashes,
|
30
|
+
or loading YAML or JSON files (but not limited to that!) and being
|
31
|
+
able to access your data in an elegant manner
|
32
|
+
END
|
33
|
+
|
34
|
+
gem.email = "renato.mascosta@gmail.com"
|
35
|
+
gem.authors = ["Fabio de Lima Pereira", "Rafael Regis do Prado", "Renato Mascarenhas"]
|
36
|
+
end
|
37
|
+
Jeweler::RubygemsDotOrgTasks.new
|
38
|
+
|
39
|
+
require 'rspec/core'
|
40
|
+
require 'rspec/core/rake_task'
|
41
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
42
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
43
|
+
end
|
44
|
+
|
45
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
46
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
47
|
+
end
|
48
|
+
|
49
|
+
task :default => :spec
|
50
|
+
|
51
|
+
require 'rake/rdoctask'
|
52
|
+
Rake::RDocTask.new do |rdoc|
|
53
|
+
version = Yell::VERSION
|
54
|
+
|
55
|
+
rdoc.rdoc_dir = 'rdoc'
|
56
|
+
rdoc.title = "yell #{version}"
|
57
|
+
rdoc.rdoc_files.include('README*')
|
58
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
59
|
+
end
|
data/lib/yell/hash.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
#lib/yell/hash.rbi
|
2
|
+
|
3
|
+
module Yell
|
4
|
+
|
5
|
+
# Yell::Hash is a class that provides easy access to members,
|
6
|
+
# in a method-like syntax.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
#
|
10
|
+
# h = Yell::Hash.new({ :my => 'hash',
|
11
|
+
# :is => { :just => 'awesome!' }
|
12
|
+
# })
|
13
|
+
#
|
14
|
+
# h.my #=> "hash"
|
15
|
+
# h.is.just #=> "awesome!"
|
16
|
+
#
|
17
|
+
# You can also pass a block with your data, allowing us to give you a
|
18
|
+
# method-like access syntax, as long as you provide us the corresponding
|
19
|
+
# hash. The code passed in initialization will only be called when
|
20
|
+
# you first try to access a key.
|
21
|
+
#
|
22
|
+
# # File: data.json
|
23
|
+
#
|
24
|
+
# {
|
25
|
+
# "my": "json",
|
26
|
+
#
|
27
|
+
# "is": {
|
28
|
+
# "just": "awesome!"
|
29
|
+
# }
|
30
|
+
# }
|
31
|
+
#
|
32
|
+
# # File: test.rb
|
33
|
+
# require 'json'
|
34
|
+
# require 'yell'
|
35
|
+
# y = Yell::Hash.new { JSON.parse File.read('data.json') }
|
36
|
+
# y.my #=> "json"
|
37
|
+
# # You need to call Yell::Hash#reload, otherwise we would have to
|
38
|
+
# # monkey patch Object::Hash, and that would be terrible!
|
39
|
+
# y.reload #=> true
|
40
|
+
# y.is.just #=> "awesome!"
|
41
|
+
class Hash
|
42
|
+
|
43
|
+
# Creates a new Yell::Hash instance. You can pass it an Object::Hash instance
|
44
|
+
# directly, or a code block, which will return our hash. The data will be lazily
|
45
|
+
# initialized, meaning that the block will be only called when you first
|
46
|
+
# try to access a key.
|
47
|
+
def initialize(hash=nil, &block)
|
48
|
+
@data = @context = hash
|
49
|
+
|
50
|
+
setup_context if @context
|
51
|
+
|
52
|
+
@loader = block
|
53
|
+
|
54
|
+
@loaded = !block_given?
|
55
|
+
end
|
56
|
+
|
57
|
+
# Updates respond_to? so that we answer +true+ for key names
|
58
|
+
def respond_to?(name)
|
59
|
+
return true if @data && (@data.key?(name.to_s) || @data.key?(name.to_sym))
|
60
|
+
super
|
61
|
+
end
|
62
|
+
|
63
|
+
# If the method passed is a key from the current context, we return it.
|
64
|
+
# Otherwise, +self+ is returned so that the user can chain keys in
|
65
|
+
# a method-like syntax.
|
66
|
+
def method_missing(meth, *args, &block)
|
67
|
+
load_data unless @loaded
|
68
|
+
|
69
|
+
return change_context_to(meth) && self if nested? @context[meth]
|
70
|
+
|
71
|
+
return change_context_to(meth) if @context[meth]
|
72
|
+
|
73
|
+
super
|
74
|
+
end
|
75
|
+
|
76
|
+
# Calls the passed block on initialization (which should provide us
|
77
|
+
# the data)
|
78
|
+
def load_data
|
79
|
+
@data = @loader.call
|
80
|
+
symbolize_keys! @data
|
81
|
+
@loaded = true
|
82
|
+
|
83
|
+
@context = @data.dup
|
84
|
+
end
|
85
|
+
|
86
|
+
# Converts all the keys of the passed hash to symbols.
|
87
|
+
def symbolize_keys!(hash)
|
88
|
+
hash.keys.each do |key|
|
89
|
+
hash[key.to_sym] = hash.delete(key)
|
90
|
+
end
|
91
|
+
|
92
|
+
hash
|
93
|
+
end
|
94
|
+
|
95
|
+
# reloads the object. In other words, we change the context to
|
96
|
+
# the root of the initial data.
|
97
|
+
def reload
|
98
|
+
@context = @data
|
99
|
+
true
|
100
|
+
end
|
101
|
+
|
102
|
+
# Checks wheter the given object is another hash (as in Object::Hash)
|
103
|
+
def nested?(obj)
|
104
|
+
obj && obj.kind_of?(Object::Hash)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Updates the current context and symbolize its keys.
|
108
|
+
def change_context_to(key)
|
109
|
+
@context = @context[key]
|
110
|
+
symbolize_keys!(@context) if nested? @context
|
111
|
+
|
112
|
+
@context
|
113
|
+
end
|
114
|
+
|
115
|
+
# Symbolizes our data and make a copy of it as the current context
|
116
|
+
def setup_context
|
117
|
+
symbolize_keys! @data
|
118
|
+
@context = @data.dup
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
data/lib/yell/version.rb
ADDED
data/lib/yell.rb
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
6
|
+
<head>
|
7
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
8
|
+
|
9
|
+
<title>File: README.rdoc [yell 1.0]</title>
|
10
|
+
|
11
|
+
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet" />
|
12
|
+
|
13
|
+
<script src="./js/jquery.js" type="text/javascript"
|
14
|
+
charset="utf-8"></script>
|
15
|
+
<script src="./js/thickbox-compressed.js" type="text/javascript"
|
16
|
+
charset="utf-8"></script>
|
17
|
+
<script src="./js/quicksearch.js" type="text/javascript"
|
18
|
+
charset="utf-8"></script>
|
19
|
+
<script src="./js/darkfish.js" type="text/javascript"
|
20
|
+
charset="utf-8"></script>
|
21
|
+
</head>
|
22
|
+
|
23
|
+
<body class="file">
|
24
|
+
<div id="metadata">
|
25
|
+
<div id="home-metadata">
|
26
|
+
<div id="home-section" class="section">
|
27
|
+
<h3 class="section-header">
|
28
|
+
<a href="./index.html">Home</a>
|
29
|
+
<a href="./index.html#classes">Classes</a>
|
30
|
+
<a href="./index.html#methods">Methods</a>
|
31
|
+
</h3>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="project-metadata">
|
36
|
+
|
37
|
+
|
38
|
+
<div id="fileindex-section" class="section project-section">
|
39
|
+
<h3 class="section-header">Files</h3>
|
40
|
+
<ul>
|
41
|
+
|
42
|
+
<li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
|
47
|
+
|
48
|
+
<div id="classindex-section" class="section project-section">
|
49
|
+
<h3 class="section-header">Class Index
|
50
|
+
<span class="search-toggle"><img src="./images/find.png"
|
51
|
+
height="16" width="16" alt="[+]"
|
52
|
+
title="show/hide quicksearch" /></span></h3>
|
53
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
54
|
+
<fieldset>
|
55
|
+
<legend>Quicksearch</legend>
|
56
|
+
<input type="text" name="quicksearch" value=""
|
57
|
+
class="quicksearch-field" />
|
58
|
+
</fieldset>
|
59
|
+
</form>
|
60
|
+
|
61
|
+
<ul class="link-list">
|
62
|
+
|
63
|
+
<li><a href="./Yell/Hash.html">Yell::Hash</a></li>
|
64
|
+
|
65
|
+
</ul>
|
66
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
67
|
+
</div>
|
68
|
+
|
69
|
+
|
70
|
+
</div>
|
71
|
+
</div>
|
72
|
+
|
73
|
+
<div id="documentation">
|
74
|
+
<h1>yell</h1>
|
75
|
+
<p>
|
76
|
+
Description goes here.
|
77
|
+
</p>
|
78
|
+
<h2>Contributing to yell</h2>
|
79
|
+
<pre>
|
80
|
+
|
81
|
+
</pre>
|
82
|
+
<ul>
|
83
|
+
<li><p>
|
84
|
+
Check out the latest master to make sure the feature hasn’t been
|
85
|
+
implemented or the bug hasn’t been fixed yet
|
86
|
+
</p>
|
87
|
+
</li>
|
88
|
+
<li><p>
|
89
|
+
Check out the issue tracker to make sure someone already hasn’t
|
90
|
+
requested it and/or contributed it
|
91
|
+
</p>
|
92
|
+
</li>
|
93
|
+
<li><p>
|
94
|
+
Fork the project
|
95
|
+
</p>
|
96
|
+
</li>
|
97
|
+
<li><p>
|
98
|
+
Start a feature/bugfix branch
|
99
|
+
</p>
|
100
|
+
</li>
|
101
|
+
<li><p>
|
102
|
+
Commit and push until you are happy with your contribution
|
103
|
+
</p>
|
104
|
+
</li>
|
105
|
+
<li><p>
|
106
|
+
Make sure to add tests for it. This is important so I don’t break it
|
107
|
+
in a future version unintentionally.
|
108
|
+
</p>
|
109
|
+
</li>
|
110
|
+
<li><p>
|
111
|
+
Please try not to mess with the Rakefile, version, or history. If you want
|
112
|
+
to have your own version, or is otherwise necessary, that is fine, but
|
113
|
+
please isolate to its own commit so I can cherry-pick around it.
|
114
|
+
</p>
|
115
|
+
</li>
|
116
|
+
</ul>
|
117
|
+
<h2>Copyright</h2>
|
118
|
+
<p>
|
119
|
+
Copyright © 2011 Renato Mascarenhas. See LICENSE.txt for further
|
120
|
+
details.
|
121
|
+
</p>
|
122
|
+
|
123
|
+
</div>
|
124
|
+
|
125
|
+
<div id="validator-badges">
|
126
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
127
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
128
|
+
Rdoc Generator</a> 1.1.6</small>.</p>
|
129
|
+
</div>
|
130
|
+
</body>
|
131
|
+
</html>
|
132
|
+
|