hasugar 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: 401caf9feaff120a8308f12385e18eec9722f70f
4
+ data.tar.gz: 7b202a4adccec51ebf784b9a6bf6aff78131b108
5
+ SHA512:
6
+ metadata.gz: 93f4b1faba690e4ebb3232ab2a34674737a2804d8067bc15ed416ca51dad445ee10de89bd0597981a559913e11ea8fa85501b1f12dca5941fab8607b2e2e8188
7
+ data.tar.gz: d1b96142cec141b56f7715c8992e16635c064e40c26ddfef78068f45ac98f015d2267fb2883aa757af1ea49c5683db67060a7879c4e06fb5ffc203e8eaac5e75
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hasugar.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Martin Fernandez
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,29 @@
1
+ # Hasugar
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hasugar'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hasugar
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/hasugar/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/hasugar.gemspec ADDED
@@ -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 'hasugar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hasugar"
8
+ spec.version = Hasugar::VERSION
9
+ spec.authors = ["Martin Fernandez"]
10
+ spec.email = ["me@bilby91.com"]
11
+ spec.summary = %q{ Sugar for ruby hash class. }
12
+ spec.description = %q{ Sugar for ruby hash class. }
13
+ spec.homepage = "https://github.com/bilby91/hasugar"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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 "rspec", "~> 3.2"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake", "~> 10"
24
+ end
data/lib/hasugar.rb ADDED
@@ -0,0 +1,73 @@
1
+ require_relative 'hasugar/version'
2
+
3
+ module Hasugar
4
+
5
+ def transform(transformations)
6
+ _dup = dup
7
+
8
+ transformations.each do |k, v|
9
+ if v.class == Hash
10
+ _dup[k] = _dup[k].transform(v)
11
+ else
12
+ _dup[v] = _dup.delete(k) if _dup[k]
13
+ end
14
+ end
15
+
16
+ _dup
17
+ end
18
+
19
+ def keep_keys!(*keys)
20
+ keys_to_delete = self.keys - keys.flatten
21
+
22
+ delete_keys!(keys_to_delete)
23
+ end
24
+
25
+ def keep_keys(*keys)
26
+ keys_to_delete = self.keys - keys.flatten
27
+
28
+ delete_keys(keys_to_delete)
29
+ end
30
+
31
+ def delete_keys!(*keys)
32
+ keys.flatten.each do |k|
33
+ delete(k)
34
+ end
35
+
36
+ self
37
+ end
38
+
39
+ def delete_keys(*keys)
40
+ _dup = dup
41
+
42
+ keys.flatten.each do |k|
43
+ _dup.delete(k)
44
+ end
45
+
46
+ _dup
47
+ end
48
+
49
+ def require_keys(*keys)
50
+ all_keys = keys.all? { |k|
51
+ if k.class == Symbol
52
+ self.key? k
53
+ elsif k.class == Hash
54
+ k.keys.all? { |i_k|
55
+ self[i_k].require_keys(k[i_k])
56
+ }
57
+ elsif k.class == Array
58
+ require_keys(*k)
59
+ else
60
+ false
61
+ end
62
+ }
63
+
64
+ all_keys
65
+ end
66
+
67
+ end
68
+
69
+ class Hash
70
+
71
+ include Hasugar
72
+
73
+ end
@@ -0,0 +1,3 @@
1
+ module Hasugar
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hasugar do
4
+
5
+ let(:hash) { { name: 'Jhon', phone: '1234' } }
6
+
7
+ describe '.transform' do
8
+
9
+ context 'when using symbols' do
10
+
11
+ subject { hash.transform(name: :x_name) }
12
+
13
+ it { should include(:x_name) }
14
+ it { should_not include(:name) }
15
+
16
+ end
17
+
18
+ context 'when nesting hashes' do
19
+
20
+ let(:hash) {
21
+ {
22
+ person: {
23
+ name: 'Jhon', phone: '1234'
24
+ }
25
+ }
26
+ }
27
+
28
+ subject { hash.transform(person: { name: :x_name })[:person] }
29
+
30
+ it { should include(:x_name) }
31
+ it { should_not include(:name) }
32
+ end
33
+
34
+ end
35
+
36
+ describe '.keep_keys' do
37
+
38
+ subject { hash.keep_keys(:name) }
39
+
40
+ it { should_not include(:phone) }
41
+
42
+ end
43
+
44
+ describe '.keep_keys' do
45
+
46
+ subject { hash }
47
+ before { hash.keep_keys!(:name) }
48
+
49
+ it { should_not include(:phone) }
50
+
51
+ end
52
+
53
+ describe '.delete_keys' do
54
+
55
+ subject { hash.delete_keys(:name) }
56
+
57
+ it { should_not include(:name) }
58
+
59
+ end
60
+
61
+ describe '.delete_keys!' do
62
+
63
+ subject { hash }
64
+ before { hash.delete_keys!(:name) }
65
+
66
+ it { should_not include(:name) }
67
+
68
+ end
69
+
70
+
71
+ describe '.require_keys' do
72
+
73
+ context 'when all keys are present' do
74
+
75
+ subject { hash.require_keys(:name, :phone) }
76
+
77
+ it { should be_truthy }
78
+
79
+ end
80
+
81
+ context 'when a key is missing' do
82
+
83
+ subject { hash.require_keys(:x_name, :phone) }
84
+
85
+ it { should be_falsey }
86
+
87
+ end
88
+ end
89
+
90
+ end
91
+
@@ -0,0 +1,75 @@
1
+ require_relative '../lib/hasugar'
2
+
3
+ RSpec.configure do |config|
4
+ # rspec-expectations config goes here. You can use an alternate
5
+ # assertion/expectation library such as wrong or the stdlib/minitest
6
+ # assertions if you prefer.
7
+ config.expect_with :rspec do |expectations|
8
+ # This option will default to `true` in RSpec 4. It makes the `description`
9
+ # and `failure_message` of custom matchers include text for helper methods
10
+ # defined using `chain`, e.g.:
11
+ # be_bigger_than(2).and_smaller_than(4).description
12
+ # # => "be bigger than 2 and smaller than 4"
13
+ # ...rather than:
14
+ # # => "be bigger than 2"
15
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
16
+ end
17
+
18
+ # rspec-mocks config goes here. You can use an alternate test double
19
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
20
+ config.mock_with :rspec do |mocks|
21
+ # Prevents you from mocking or stubbing a method that does not exist on
22
+ # a real object. This is generally recommended, and will default to
23
+ # `true` in RSpec 4.
24
+ mocks.verify_partial_doubles = true
25
+ end
26
+
27
+ # The settings below are suggested to provide a good initial experience
28
+ # with RSpec, but feel free to customize to your heart's content.
29
+ =begin
30
+ # These two settings work together to allow you to limit a spec run
31
+ # to individual examples or groups you care about by tagging them with
32
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
33
+ # get run.
34
+ config.filter_run :focus
35
+ config.run_all_when_everything_filtered = true
36
+
37
+ # Limits the available syntax to the non-monkey patched syntax that is
38
+ # recommended. For more details, see:
39
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
40
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
41
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
42
+ config.disable_monkey_patching!
43
+
44
+ # This setting enables warnings. It's recommended, but in some cases may
45
+ # be too noisy due to issues in dependencies.
46
+ config.warnings = true
47
+
48
+ # Many RSpec users commonly either run the entire suite or an individual
49
+ # file, and it's useful to allow more verbose output when running an
50
+ # individual spec file.
51
+ if config.files_to_run.one?
52
+ # Use the documentation formatter for detailed output,
53
+ # unless a formatter has already been configured
54
+ # (e.g. via a command-line flag).
55
+ config.default_formatter = 'doc'
56
+ end
57
+
58
+ # Print the 10 slowest examples and example groups at the
59
+ # end of the spec run, to help surface which specs are running
60
+ # particularly slow.
61
+ config.profile_examples = 10
62
+
63
+ # Run specs in random order to surface order dependencies. If you find an
64
+ # order dependency and want to debug it, you can fix the order by providing
65
+ # the seed, which is printed after each run.
66
+ # --seed 1234
67
+ config.order = :random
68
+
69
+ # Seed global randomization in this process using the `--seed` CLI option.
70
+ # Setting this allows you to use `--seed` to deterministically reproduce
71
+ # test failures related to randomization by passing the same `--seed` value
72
+ # as the one that triggered the failure.
73
+ Kernel.srand config.seed
74
+ =end
75
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hasugar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Fernandez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10'
55
+ description: ' Sugar for ruby hash class. '
56
+ email:
57
+ - me@bilby91.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - hasugar.gemspec
69
+ - lib/hasugar.rb
70
+ - lib/hasugar/version.rb
71
+ - spec/hasugar_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: https://github.com/bilby91/hasugar
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.4.5
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Sugar for ruby hash class.
97
+ test_files:
98
+ - spec/hasugar_spec.rb
99
+ - spec/spec_helper.rb
100
+ has_rdoc: