tfg_support 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3488356b08dd4c3e94aee911d21cc0ab2e6afd1e
4
+ data.tar.gz: 8babc6483365556e2874efc1c41ad0027a08b2e2
5
+ SHA512:
6
+ metadata.gz: 0437d369672ad913f6df5736e19a4fda0762593c03b82dbeac43a1ffbf4c659010d1bb8d3a79a031dfb8a52118a05d37990c6e77b88664b5b757857a18d48c99
7
+ data.tar.gz: af997c1f80e8d49ee5d9b9b936dbf960c65a00648b2a207e7d916d722bdf43609df71e821f8dff11c1a633aeb1287b1cdd9099577e8e871079d0b26724caa60f
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 tfg_support.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Courtney de Lautour
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,46 @@
1
+ # TfgSupport
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ gem 'tfg_support', git: "git@github.com:Amerdrix/TFG-support.git"
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ ## Usage
14
+
15
+ Provides some useful extentions to ruby classes.
16
+
17
+ ### [Hash] (http://ruby-doc.org/core-2.0/Hash.html)
18
+
19
+ #### #deep
20
+
21
+ Allows access to hashes nested with in other hashes.
22
+
23
+ Replace
24
+
25
+ value = some_hash[:foo][:bar][:baz] if some_hash[:foo] && some_hash[:foo][:bar]
26
+
27
+ with
28
+
29
+ value = hash.deep[:foo, :bar, :baz]
30
+
31
+ also works for setting, creating a new hash one isn't present
32
+
33
+ hash.deep[:foo, :bar, :baz] = :frob
34
+ hash.deep[:foo, :missing_key, :baz] = :frob
35
+
36
+ hash
37
+ => {:foo=>{:bar=>{:baz=>:frob}, :missing_key=>{:baz=>:frob}}}
38
+
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
1
+ require "tfg_support/version"
2
+
3
+ module TfgSupport
4
+ autoload :DeepHashAccessor, "tfg_support/deep_hash_accessor"
5
+ end
6
+
7
+ class Hash
8
+ def deep()
9
+ TfgSupport::DeepHashAccessor.new(self)
10
+ end
11
+ end
@@ -0,0 +1,35 @@
1
+ module TfgSupport
2
+ class DeepHashAccessor
3
+
4
+ def initialize(hash)
5
+ @hash = hash
6
+ end
7
+
8
+ def [](*keys)
9
+ target = @hash
10
+
11
+ keys.each do |key|
12
+ return nil unless target.respond_to?(:[])
13
+ target = target[key]
14
+ end
15
+ target
16
+ end
17
+
18
+ def []=(*keys)
19
+ value = keys.pop()
20
+ set_key = keys.pop()
21
+
22
+ target = @hash
23
+ keys.each do |key|
24
+ hash = target[key]
25
+ if hash.nil?
26
+ hash = {}
27
+ target[key] = hash
28
+ end
29
+ target = hash
30
+ end
31
+
32
+ target[set_key] = value
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module TfgSupport
2
+ VERSION = "0.0.1"
3
+ end
data/spec/hash_spec.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hash do
4
+
5
+ subject(:hash) do
6
+ {
7
+ shallow_key: :single_value,
8
+ deep_key:
9
+ {
10
+ nested_key: :nested_value
11
+ }
12
+ }
13
+ end
14
+
15
+ describe "#deep[]" do
16
+ describe "with single argument" do
17
+
18
+ subject(:index) { hash.deep[:shallow_key] }
19
+
20
+ it "returns the value of the key" do
21
+ should eq :single_value
22
+ end
23
+ end
24
+
25
+ describe "with multiple arguments" do
26
+
27
+ subject(:index) { hash.deep[:deep_key, :nested_key] }
28
+
29
+ it "returns the value of the key for the nested hash" do
30
+ should eq :nested_value
31
+ end
32
+ end
33
+
34
+ describe "when a key is not present" do
35
+
36
+ subject(:index) { hash.deep[:deep_key, :missing_key, :nested_key] }
37
+
38
+ it "returns nil" do
39
+ should be nil
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#deep[]=" do
45
+ before :each do
46
+ deep_set
47
+ end
48
+
49
+ describe "with single argument" do
50
+ subject(:deep_set) { hash.deep[:shallow_key]= :new_value }
51
+
52
+ it "sets the key of the original hash" do
53
+ hash[:shallow_key].should eq :new_value
54
+ end
55
+ end
56
+
57
+ describe "with multiple arguments" do
58
+
59
+ subject(:deep_set) { hash.deep[:deep_key, :nested_key]= :new_value }
60
+
61
+ it "sets the key of the nested hash" do
62
+ hash[:deep_key][:nested_key].should eq :new_value
63
+ end
64
+ end
65
+
66
+ describe "when a key is not present" do
67
+
68
+ subject(:deep_set) { hash.deep[:deep_key, :missing_key, :nested_key]= :new_value }
69
+
70
+ it "creates a new hash for the missing key" do
71
+ hash[:deep_key][:missing_key][:nested_key].should eq :new_value
72
+ end
73
+ end
74
+ end
75
+ end
76
+
@@ -0,0 +1 @@
1
+ require "tfg_support"
@@ -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 'tfg_support/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tfg_support"
8
+ spec.version = TfgSupport::VERSION
9
+ spec.authors = ["Courtney de Lautour"]
10
+ spec.email = ["clautour@thefrontiergroup.com.au"]
11
+ spec.description = %q{A collection of helper methods / extensions for Ruby}
12
+ spec.summary = %q{A collection of helper methods / extensions for Ruby}
13
+ spec.homepage = "https://github.com/Amerdrix/TFG-support"
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,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tfg_support
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Courtney de Lautour
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-23 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: A collection of helper methods / extensions for Ruby
56
+ email:
57
+ - clautour@thefrontiergroup.com.au
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/tfg_support.rb
68
+ - lib/tfg_support/deep_hash_accessor.rb
69
+ - lib/tfg_support/version.rb
70
+ - spec/hash_spec.rb
71
+ - spec/spec_helper.rb
72
+ - tfg_support.gemspec
73
+ homepage: https://github.com/Amerdrix/TFG-support
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: A collection of helper methods / extensions for Ruby
97
+ test_files:
98
+ - spec/hash_spec.rb
99
+ - spec/spec_helper.rb