gm_hash_wrapper 0.1.0

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: 5a2420ee9f3dde81fb5676fd559d5c9ff0f46d43
4
+ data.tar.gz: ccd0adc02a696aa153bad871ebd8dfcc5c7b9833
5
+ SHA512:
6
+ metadata.gz: 0685f9b42a8bd72854d857652fbcd6a42d3867439614a8e5da99b4c51e3608fc63fdfeaf6c8311955e8f2e191fee7a0b02fdc5801052f1226d6aa8767281e409
7
+ data.tar.gz: f258108e9b5ac1e7bd6a3e1f1043dd903eac9152b68aa10d82a14dcb182c139418af6e179a45d5864c2d3db233cd93451efdb74f2a62e719ae58927fe4a35382
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gm_hash_wrapper.gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ramil Sitdikov
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,41 @@
1
+ # GmHashWrapper
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gm_hash_wrapper`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gm_hash_wrapper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gm_hash_wrapper
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gm_hash_wrapper. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gm_hash_wrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gm_hash_wrapper"
8
+ spec.version = GmHashWrapper::VERSION
9
+ spec.authors = ["Ramil Sitdikov"]
10
+ spec.email = ["sitdikov.ramil@gmail.com"]
11
+ spec.summary = %q{Hash Wrapper}
12
+ spec.description = %q{Hash Wrapper}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_runtime_dependency 'activesupport'
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.10"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,56 @@
1
+ require 'active_support/core_ext/hash/indifferent_access'
2
+ module GmHashWrapper
3
+ class HashWrapper
4
+ attr_reader :body
5
+
6
+ def initialize(body)
7
+ @body = ActiveSupport::HashWithIndifferentAccess.new(body)
8
+ end
9
+
10
+ def set_data(key, value)
11
+ @body[key.to_s] = value
12
+ end
13
+ def to_h
14
+ @body
15
+ end
16
+
17
+ def as_json(options = {})
18
+ @body
19
+ end
20
+
21
+ def nil?
22
+ @body.keys.empty?
23
+ end
24
+
25
+ def present?
26
+ @body.keys.any?
27
+ end
28
+
29
+ def each(&block)
30
+ body.each &block
31
+ end
32
+
33
+ def method_missing meth, *args, &block
34
+ if @body.has_key?(meth)
35
+ if @body[meth].kind_of?(Hash)
36
+ return HashWrapper.new(@body[meth])
37
+ elsif @body[meth].kind_of?(Array)
38
+ return @body[meth].map do |x|
39
+ if x.kind_of?(Hash)
40
+ HashWrapper.new(x)
41
+ else
42
+ x
43
+ end
44
+ end
45
+ else
46
+ return @body[meth]
47
+ end
48
+ end
49
+ nil
50
+ end
51
+
52
+ def respond_to_missing?(meth, include_private = false)
53
+ @body.has_key?(meth) || super
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,28 @@
1
+ module GmHashWrapper
2
+ class StrictHashWrapper < HashWrapper
3
+ def key?(key)
4
+ @body.has_key?(key)
5
+ end
6
+
7
+ def method_missing meth, *args, &block
8
+ if @body.has_key?(meth)
9
+ if @body[meth].kind_of?(Hash)
10
+ return StrictHashWrapper.new(@body[meth])
11
+ elsif @body[meth].kind_of?(Array)
12
+ return @body[meth].map do |x|
13
+ if x.kind_of?(Hash)
14
+ StrictHashWrapper.new(x)
15
+ else
16
+ x
17
+ end
18
+ end
19
+ else
20
+ return @body[meth]
21
+ end
22
+ else
23
+ raise("undefined method '#{meth}' for #{body}")
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module GmHashWrapper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'gm_hash_wrapper/version'
2
+ require 'gm_hash_wrapper/hash_wrapper'
3
+ require 'gm_hash_wrapper/strict_hash_wrapper'
4
+
5
+ module GmHashWrapper
6
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gm_hash_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ramil Sitdikov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Hash Wrapper
56
+ email:
57
+ - sitdikov.ramil@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - gm_hash_wrapper.gemspec
68
+ - lib/gm_hash_wrapper.rb
69
+ - lib/gm_hash_wrapper/hash_wrapper.rb
70
+ - lib/gm_hash_wrapper/strict_hash_wrapper.rb
71
+ - lib/gm_hash_wrapper/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.4.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Hash Wrapper
96
+ test_files: []