hashie_mash_knockoff 0.4.3

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: c52ce2cd105760778e02d3a3ae122ca59fb3dea2
4
+ data.tar.gz: 6f1a1a23ddf89b9a17eabb19d2dab4c288490f3b
5
+ SHA512:
6
+ metadata.gz: 205e799451cb552514515d9c780b968763618620fbb3c03c2ad9c6399c1bd64fade97d16b38bba179c1808cbde901a2959a779062937dea15912964bca7adb3e
7
+ data.tar.gz: 44d4dec6dfc612c226938375e203a80d59761f6257f0382dcbff6cc99cf55af3ec9bb1f038ab666efd226235cc9ccf1c3bd48979cb1f458b26f71816e8f618c8
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ *.DS_Store
2
+ *.gem
3
+ /.bundle/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hashie_mash_knockoff.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Michael Pope
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # HashieMashKnockoff
2
+
3
+ - A [Hashie::Mash](https://github.com/intridea/hashie#mash) knockoff
4
+ - This is a prototype
5
+ - Built and tested with Ruby 2.2.3
6
+
7
+ ## Setup
8
+
9
+ Add it to your Gemfile or...
10
+
11
+ ```
12
+ gem install hashie_mash_knockoff
13
+ ```
14
+
15
+ ## Test
16
+
17
+ ```
18
+ bundle exec rspec
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ require 'hashie_mash_knockoff'
25
+
26
+ # access hash keys with method calls
27
+ hash = { a: 'b', c: { d: 'e' }, f: {} }
28
+ hashie_mash_knockoff = HashieMashKnockoff.new(hash)
29
+ hashie_mash_knockoff.a # returns 'b'
30
+ hashie_mash_knockoff.a = '' # raises NoMethodError
31
+ hashie_mash_knockoff[:a] # returns 'b'
32
+ hashie_mash_knockoff[:a] = '' # raises NoMethodError
33
+ hashie_mash_knockoff.c # returns instance of HashIsh w/ hash of { d: 'e' }
34
+ hashie_mash_knockoff.c.class # returns HashIsh
35
+ hashie_mash_knockoff[:c] # returns { d: 'e' }
36
+ hashie_mash_knockoff[:c].class # returns Hash
37
+ hashie_mash_knockoff.c.d # returns 'e'
38
+ hashie_mash_knockoff.f # returns {}
39
+ hashie_mash_knockoff.f.class # returns Hash
40
+ hashie_mash_knockoff[:f] # returns {}
41
+ hashie_mash_knockoff[:f].class # returns Hash
42
+
43
+ # set default values
44
+ hash = { a: nil, b: { c: false }, d: { e: '>_<' } }
45
+ defaults = { a: 123, b: { c: true }, d: { e: 'ಠ_ಠ' } }
46
+ hashie_mash_knockoff = HashieMashKnockoff.new(hash, defaults)
47
+ hashie_mash_knockoff.a # returns 123, overrides falsey nil
48
+ hashie_mash_knockoff.b.c # returns true, overrides falsey false
49
+ hashie_mash_knockoff.d.e # returns 'lol', not overriden due to 'lol' being truthy
50
+ ```
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hashie_mash_knockoff"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hashie_mash_knockoff/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'hashie_mash_knockoff'
8
+ spec.version = HashieMashKnockoff::VERSION
9
+ spec.authors = ['Michael Pope']
10
+ spec.email = ['mpope.cr@gmail.com']
11
+
12
+ spec.summary = %q{A Hashie::Mash knockoff}
13
+ spec.description = spec.summary
14
+ spec.homepage = 'https://github.com/amorphid/hashie_mash_knockoff'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.10'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rspec', '~> 3.3'
25
+ spec.add_runtime_dependency 'json', '~> 1.8'
26
+ spec.add_runtime_dependency 'srm', '~> 0.1'
27
+ end
28
+
@@ -0,0 +1,34 @@
1
+ require 'json'
2
+ require 'srm'
3
+ require 'hashie_mash_knockoff/version'
4
+ require 'hashie_mash_knockoff/add_default_values'
5
+ require 'hashie_mash_knockoff/add_instance_methods'
6
+
7
+ class HashieMashKnockoff
8
+ def initialize(kwargs = {}, defaults = {})
9
+ @hash = AddDefaultValues.new.add(kwargs, defaults)
10
+ decorate_self(self, @hash)
11
+ end
12
+
13
+ def [](key)
14
+ @hash[key]
15
+ end
16
+
17
+ def to_hash
18
+ @hash
19
+ end
20
+
21
+ def to_json
22
+ to_hash.to_json
23
+ end
24
+
25
+ alias :to_h :to_hash
26
+
27
+ private
28
+
29
+ def decorate_self(hashie_mash_knockoff, kwargs)
30
+ hashie_mash_knockoff.tap do |hashie_mash_knockoff|
31
+ AddInstanceMethods.new.add(hashie_mash_knockoff, kwargs)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ class HashieMashKnockoff
2
+ class AddDefaultValues
3
+ def add(kwargs, defaults)
4
+ hash = kwargs.dup
5
+
6
+ hash.tap do |hash|
7
+ add_defaults(hash, defaults)
8
+ end
9
+ end
10
+
11
+ def add_defaults(hash, defaults)
12
+ defaults.each do |key, value|
13
+ if Srm.is_a_hash?(value)
14
+ arg_hash = hash[key] || {}
15
+ hash[key] = AddDefaultValues.new.add(arg_hash, value)
16
+ else
17
+ hash[key] ||= value
18
+ end
19
+ end
20
+ end
21
+
22
+ def truthy?(hash, key)
23
+ !!hash[key]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ class HashieMashKnockoff
2
+ class AddInstanceMethods
3
+ def add(hashie_mash_knockoff, kwargs)
4
+ kwargs.each do |key, value|
5
+ define_method(hashie_mash_knockoff, key, value)
6
+ end
7
+ end
8
+
9
+ def define_method(hashie_mash_knockoff, name, value)
10
+ return_value = method_value(value)
11
+
12
+ hashie_mash_knockoff.send(:define_singleton_method, name) do
13
+ return_value
14
+ end
15
+ end
16
+
17
+ def hashie_mash_knockoff(hash)
18
+ HashieMashKnockoff.new(hash)
19
+ end
20
+
21
+ def has_keys?(value)
22
+ value.keys.size > 0
23
+ end
24
+
25
+ def should_be_a_hashie_mash_knockoff?(value)
26
+ Srm.is_a_hash?(value) && has_keys?(value)
27
+ end
28
+
29
+ def method_value(value)
30
+ should_be_a_hashie_mash_knockoff?(value) ? hashie_mash_knockoff(value) : value
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ class HashieMashKnockoff
2
+ VERSION = '0.4.3'
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hashie_mash_knockoff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.3
5
+ platform: ruby
6
+ authors:
7
+ - Michael Pope
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-20 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: srm
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
83
+ description: A Hashie::Mash knockoff
84
+ email:
85
+ - mpope.cr@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - hashie_mash_knockoff.gemspec
101
+ - lib/hashie_mash_knockoff.rb
102
+ - lib/hashie_mash_knockoff/add_default_values.rb
103
+ - lib/hashie_mash_knockoff/add_instance_methods.rb
104
+ - lib/hashie_mash_knockoff/version.rb
105
+ homepage: https://github.com/amorphid/hashie_mash_knockoff
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.4.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A Hashie::Mash knockoff
129
+ test_files: []
130
+ has_rdoc: