options-hash 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "hashie", ">= 1.0.0"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "bundler", "~> 1.0.0"
10
+ gem "jeweler", "~> 1.5.2"
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ hashie (1.0.0)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.9.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.0.0)
17
+ hashie (>= 1.0.0)
18
+ jeweler (~> 1.5.2)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
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.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ Options Hash
2
+ ============
3
+
4
+ **options-hash** serves as an syntactic sugar for creating hashes with
5
+ options which can have defined default values and are accessible by
6
+ object-like style. Utilizes [Mash][1].
7
+
8
+ Example:
9
+
10
+ require "options-hash"
11
+
12
+ user_opts = {:a => :b}
13
+ options = OptionsHash::get(user_opts)[:a => 1, :c => 3]
14
+
15
+ p options
16
+ # will print out <#Hashie::Mash a=:b c=3>
17
+
18
+ p options.c
19
+ # will print out 3
20
+
21
+
22
+ Contributing
23
+ ------------
24
+
25
+ 1. Fork it.
26
+ 2. Create a branch (`git checkout -b 20101220-my-change`).
27
+ 3. Commit your changes (`git commit -am "Added something"`).
28
+ 4. Push to the branch (`git push origin 20101220-my-change`).
29
+ 5. Create an [Issue][2] with a link to your branch.
30
+ 6. Enjoy a refreshing Diet Coke and wait.
31
+
32
+ Copyright
33
+ ---------
34
+
35
+ Copyright &copy; 2011 [Martin Kozák][3]. See `LICENSE.txt` for
36
+ further details.
37
+
38
+ [1]: http://github.com/intridea/hashie
39
+ [2]: http://github.com/martinkozak/options-hash/issues
40
+ [3]: http://www.martinkozak.net/
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+
14
+ require 'rake'
15
+ require 'jeweler'
16
+
17
+ Jeweler::Tasks.new do |gem|
18
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
19
+
20
+ gem.name = "options-hash"
21
+ gem.homepage = "https://github.com/martinkozak/options-hash"
22
+ gem.license = "MIT"
23
+ gem.summary = "Syntactic sugar for creating hashes with options which can have defined default values and are accessible by object-like style."
24
+ gem.email = "martinkozak@martinkozak.net"
25
+ gem.authors = ["Martin Kozák"]
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,65 @@
1
+ # encoding: utf-8
2
+ # (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
3
+
4
+ require "hashie/mash"
5
+
6
+ ##
7
+ # Options hash which allows defiying the default values and access to
8
+ # items as to properties.
9
+ #
10
+ # @see https://github.com/intridea/hashie
11
+ #
12
+
13
+ class OptionsHash
14
+
15
+ ##
16
+ # Holds assigned options.
17
+ #
18
+
19
+ @options
20
+
21
+ ##
22
+ # Assigns the options data.
23
+ #
24
+ # @param [Hash] options options data
25
+ # @return [OptionsHash] itself for service purpose
26
+ #
27
+
28
+ def self.get(options = {})
29
+ self::new(options)
30
+ end
31
+
32
+ ##
33
+ # Constructor.
34
+ # @param [Hash] options options data
35
+ #
36
+
37
+ def initialize(options = {})
38
+ @options = options
39
+ end
40
+
41
+ ##
42
+ # Assigns the default values.
43
+ #
44
+ # @param [Hash] defaults defaults data
45
+ # @return [Hashie::Mash] object-like accessible pseudo-hash
46
+ #
47
+
48
+ def [](defaults = {})
49
+ Hashie::Mash::new(defaults.merge(@options))
50
+ end
51
+
52
+ end
53
+
54
+ =begin
55
+ opts = {
56
+ :a => :b
57
+ }
58
+
59
+ x = OptionsHash::get(opts)[
60
+ :a => 1,
61
+ :c => 3
62
+ ]
63
+
64
+ p x
65
+ =end
@@ -0,0 +1,53 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{options-hash}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Martin Kozák}]
12
+ s.date = %q{2011-05-29}
13
+ s.email = %q{martinkozak@martinkozak.net}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.txt",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "README.md",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/options-hash.rb",
27
+ "options-hash.gemspec"
28
+ ]
29
+ s.homepage = %q{https://github.com/martinkozak/options-hash}
30
+ s.licenses = [%q{MIT}]
31
+ s.require_paths = [%q{lib}]
32
+ s.rubygems_version = %q{1.8.4}
33
+ s.summary = %q{Syntactic sugar for creating hashes with options which can have defined default values and are accessible by object-like style.}
34
+
35
+ if s.respond_to? :specification_version then
36
+ s.specification_version = 3
37
+
38
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
+ s.add_runtime_dependency(%q<hashie>, [">= 1.0.0"])
40
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
41
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
42
+ else
43
+ s.add_dependency(%q<hashie>, [">= 1.0.0"])
44
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
45
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
46
+ end
47
+ else
48
+ s.add_dependency(%q<hashie>, [">= 1.0.0"])
49
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
51
+ end
52
+ end
53
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: options-hash
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - "Martin Koz\xC3\xA1k"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-29 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hashie
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: bundler
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: jeweler
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.5.2
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ description:
49
+ email: martinkozak@martinkozak.net
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ extra_rdoc_files:
55
+ - LICENSE.txt
56
+ - README.md
57
+ files:
58
+ - .document
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - LICENSE.txt
62
+ - README.md
63
+ - Rakefile
64
+ - VERSION
65
+ - lib/options-hash.rb
66
+ - options-hash.gemspec
67
+ homepage: https://github.com/martinkozak/options-hash
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 1863587562541823663
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ requirements: []
91
+
92
+ rubyforge_project:
93
+ rubygems_version: 1.8.4
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Syntactic sugar for creating hashes with options which can have defined default values and are accessible by object-like style.
97
+ test_files: []
98
+