dougp-shatter 0.0.1

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.
Files changed (5) hide show
  1. data/License +21 -0
  2. data/README +23 -0
  3. data/Rakefile +16 -0
  4. data/lib/shatter.rb +16 -0
  5. metadata +57 -0
data/License ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2009 Doug Peterson
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.
21
+
data/README ADDED
@@ -0,0 +1,23 @@
1
+ Shatter modifies method missing in its scope to allow for more convenient access to hash parameters as local variables (actually methods)
2
+
3
+ #old and verbose
4
+
5
+ #expecting :email, :password , and :id
6
+ def my_method(params={})
7
+ raise "No Email" unless params[:email]
8
+ raise "No Password" unles params[:password]
9
+ Record.find(params[:id])
10
+ end
11
+
12
+ #new and awesome
13
+
14
+ require 'shatter'
15
+ include 'Shatter'
16
+ #expecting :email, :password , and :id
17
+ def my_method(params={})
18
+ shatter(params) do
19
+ raise "No Email" unless email
20
+ raise "No Password" unless password
21
+ Record.find(id)
22
+ end
23
+ end
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ spec= Gem::Specification.new do |s|
5
+ s.name="Shatter"
6
+ s.version = "0.0.1"
7
+ s.author = "Doug Peterson"
8
+ s.email = "dougp757"
9
+ s.homepage = "http://github.com/dougp/shatter"
10
+ s.summary = "Allows non verbose access hash members"
11
+ s.files = ["License", "README","lib/shatter.rb", "Rakefile"]
12
+ s.has_rdoc = false
13
+ end
14
+ Rake::GemPackageTask.new(spec) do |pkg|
15
+ pkg.need_tar = true
16
+ end
data/lib/shatter.rb ADDED
@@ -0,0 +1,16 @@
1
+ module Shatter
2
+ def method_missing(method_id, *arguments)
3
+ @my_hash||={}
4
+ if @my_hash.has_key? method_id
5
+ return @my_hash[method_id]
6
+ else
7
+ return super
8
+ end
9
+ end
10
+ def shatter(my_hash)
11
+ @my_hash=my_hash
12
+ val=yield
13
+ @my_hash={}
14
+ val
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dougp-shatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Doug Peterson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: dougp757
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - License
26
+ - README
27
+ - lib/shatter.rb
28
+ - Rakefile
29
+ has_rdoc: false
30
+ homepage: http://github.com/dougp/shatter
31
+ licenses:
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.3.5
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: Allows non verbose access hash members
56
+ test_files: []
57
+