maccman-mash 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c98e069e8c59a6c4db899ad748893540fa48d444
4
+ data.tar.gz: 8c947f552edd4f6a88ff56b164b163e73b62ba4a
5
+ SHA512:
6
+ metadata.gz: 896ffc355db4dc35bedd3e67f0a1bd18f435ba4ea21908d2046594e46506670095792bb351e8d762af38847a8d322603c54bf12dd8a8a989a522cb20add37a21
7
+ data.tar.gz: fe608963adecf253317f712e59b758af2d246594e8ad63969078064701277cc51d480edae14c4ad2fc75bd7c29eaf8bdbe187e4fa145af24b9b9a24577214457
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mash.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Intridea, Inc., Alex MacCaw, and Contributors
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.
@@ -0,0 +1,29 @@
1
+ # Mash
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mash'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mash
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/mash/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
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,184 @@
1
+ class Mash < Hash
2
+ autoload :Camel, 'mash/camel'
3
+
4
+ def self.from_json(json)
5
+ self.new(JSON.parse(json))
6
+ end
7
+
8
+ def self.new(value = nil, *args)
9
+ if value.respond_to?(:each) &&
10
+ !value.respond_to?(:each_pair)
11
+ value.map {|v| super(v) }
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ alias_method :to_s, :inspect
18
+
19
+ def initialize(source_hash = nil, default = nil, &blk)
20
+ deep_update(source_hash.to_hash) if source_hash
21
+ default ? super(default) : super(&blk)
22
+ end
23
+
24
+ class << self; alias [] new; end
25
+
26
+ def id #:nodoc:
27
+ self['id']
28
+ end
29
+
30
+ def type #:nodoc:
31
+ self['type']
32
+ end
33
+
34
+ alias_method :regular_reader, :[]
35
+ alias_method :regular_writer, :[]=
36
+
37
+ # Retrieves an attribute set in the Mash. Will convert
38
+ # any key passed in to a string before retrieving.
39
+ def custom_reader(key)
40
+ value = regular_reader(convert_key(key))
41
+ yield value if block_given?
42
+ value
43
+ end
44
+
45
+ # Sets an attribute in the Mash. Key will be converted to
46
+ # a string before it is set, and Hashes will be converted
47
+ # into Mashes for nesting purposes.
48
+ def custom_writer(key,value) #:nodoc:
49
+ regular_writer(convert_key(key), convert_value(value))
50
+ end
51
+
52
+ alias_method :[], :custom_reader
53
+ alias_method :[]=, :custom_writer
54
+
55
+ # This is the bang method reader, it will return a new Mash
56
+ # if there isn't a value already assigned to the key requested.
57
+ def initializing_reader(key)
58
+ ck = convert_key(key)
59
+ regular_writer(ck, self.class.new) unless key?(ck)
60
+ regular_reader(ck)
61
+ end
62
+
63
+ # This is the under bang method reader, it will return a temporary new Mash
64
+ # if there isn't a value already assigned to the key requested.
65
+ def underbang_reader(key)
66
+ ck = convert_key(key)
67
+ if key?(ck)
68
+ regular_reader(ck)
69
+ else
70
+ self.class.new
71
+ end
72
+ end
73
+
74
+ def fetch(key, *args)
75
+ super(convert_key(key), *args)
76
+ end
77
+
78
+ def delete(key)
79
+ super(convert_key(key))
80
+ end
81
+
82
+ alias_method :regular_dup, :dup
83
+ # Duplicates the current mash as a new mash.
84
+ def dup
85
+ self.class.new(self, self.default)
86
+ end
87
+
88
+ def key?(key)
89
+ super(convert_key(key))
90
+ end
91
+ alias_method :has_key?, :key?
92
+ alias_method :include?, :key?
93
+ alias_method :member?, :key?
94
+
95
+ # Performs a deep_update on a duplicate of the
96
+ # current mash.
97
+ def deep_merge(other_hash, &blk)
98
+ dup.deep_update(other_hash, &blk)
99
+ end
100
+ alias_method :merge, :deep_merge
101
+
102
+ # Recursively merges this mash with the passed
103
+ # in hash, merging each hash in the hierarchy.
104
+ def deep_update(other_hash, &blk)
105
+ other_hash.each_pair do |k,v|
106
+ key = convert_key(k)
107
+ if regular_reader(key).is_a?(Mash) and v.is_a?(::Hash)
108
+ custom_reader(key).deep_update(v, &blk)
109
+ else
110
+ value = convert_value(v, true)
111
+ value = blk.call(key, self[k], value) if blk
112
+ custom_writer(key, value)
113
+ end
114
+ end
115
+ self
116
+ end
117
+ alias_method :deep_merge!, :deep_update
118
+ alias_method :update, :deep_update
119
+ alias_method :merge!, :update
120
+
121
+ # Performs a shallow_update on a duplicate of the current mash
122
+ def shallow_merge(other_hash)
123
+ dup.shallow_update(other_hash)
124
+ end
125
+
126
+ # Merges (non-recursively) the hash from the argument,
127
+ # changing the receiving hash
128
+ def shallow_update(other_hash)
129
+ other_hash.each_pair do |k,v|
130
+ regular_writer(convert_key(k), convert_value(v, true))
131
+ end
132
+ self
133
+ end
134
+
135
+ def replace(other_hash)
136
+ (keys - other_hash.keys).each { |key| delete(key) }
137
+ other_hash.each { |key, value| self[key] = value }
138
+ self
139
+ end
140
+
141
+ # Will return true if the Mash has had a key
142
+ # set in addition to normal respond_to? functionality.
143
+ def respond_to?(method_name, include_private=false)
144
+ return true if key?(method_name) || method_name.to_s.slice(/[=?!_]\Z/)
145
+ super
146
+ end
147
+
148
+ def method_missing(method_name, *args, &blk)
149
+ return self.[](method_name, &blk) if key?(method_name)
150
+ match = method_name.to_s.match(/(.*?)([?=!_]?)$/)
151
+ case match[2]
152
+ when "="
153
+ self[match[1]] = args.first
154
+ when "?"
155
+ !!self[match[1]]
156
+ when "!"
157
+ initializing_reader(match[1])
158
+ when "_"
159
+ underbang_reader(match[1])
160
+ else
161
+ default(method_name, *args, &blk)
162
+ end
163
+ end
164
+
165
+ protected
166
+
167
+ def convert_key(key) #:nodoc:
168
+ key.to_s
169
+ end
170
+
171
+ def convert_value(val, duping=false) #:nodoc:
172
+ case val
173
+ when self.class
174
+ val.dup
175
+ when ::Hash
176
+ val = val.dup if duping
177
+ Mash.new(val)
178
+ when ::Array
179
+ val.map {|e| convert_value(e) }
180
+ else
181
+ val
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,7 @@
1
+ class Mash::Camel < Mash
2
+ protected
3
+
4
+ def convert_key(key)
5
+ key.to_s.underscore
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "maccman-mash"
7
+ spec.version = '0.0.2'
8
+ spec.authors = ["Alex MacCaw"]
9
+ spec.email = ["alex@clearbit.com"]
10
+ spec.summary = %q{A fork of a Mash library.}
11
+ spec.license = "MIT"
12
+
13
+ spec.files = `git ls-files -z`.split("\x0")
14
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.6"
19
+ spec.add_development_dependency "rake"
20
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maccman-mash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alex MacCaw
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-24 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ description:
42
+ email:
43
+ - alex@clearbit.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/mash.rb
54
+ - lib/mash/camel.rb
55
+ - mash.gemspec
56
+ homepage:
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.2.2
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: A fork of a Mash library.
80
+ test_files: []
81
+ has_rdoc: