frozen-objects 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +20 -0
- data/README.md +41 -0
- data/Rakefile +37 -0
- data/VERSION +1 -0
- data/lib/frozen-objects.rb +6 -0
- data/lib/frozen-objects/array.rb +22 -0
- data/lib/frozen-objects/hash.rb +27 -0
- data/lib/frozen-objects/string.rb +22 -0
- data/test +58 -0
- metadata +103 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "hash-utils", ">= 0.11.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
|
+
gem "riot", ">= 0.12.1"
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
git (1.2.5)
|
5
|
+
jeweler (1.5.2)
|
6
|
+
bundler (~> 1.0.0)
|
7
|
+
git (>= 1.2.5)
|
8
|
+
rake
|
9
|
+
rake (0.8.7)
|
10
|
+
riot (0.12.1)
|
11
|
+
rr
|
12
|
+
term-ansicolor
|
13
|
+
rr (1.0.2)
|
14
|
+
term-ansicolor (1.0.5)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
ruby
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
bundler (~> 1.0.0)
|
21
|
+
jeweler (~> 1.5.2)
|
22
|
+
riot (>= 0.12.1)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Martin Kozák
|
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,41 @@
|
|
1
|
+
Frozen Objects
|
2
|
+
==============
|
3
|
+
|
4
|
+
**frozen-objects** provides syntax sugar of implicitly frozen objects
|
5
|
+
useful for example in class constants.
|
6
|
+
|
7
|
+
require "frozen-objects"
|
8
|
+
|
9
|
+
class Foo
|
10
|
+
SOME_ARRAY = Frozen::Array[:a, :b] # or any other Array constructing methods
|
11
|
+
SOME_HASH = Frozen::Hash[:a => :b] # or any other Hash constructing methods
|
12
|
+
SOME_STRING = Frozen::String::new("a")
|
13
|
+
end
|
14
|
+
|
15
|
+
Foo::SOME_ARRAY.frozen? # will return true
|
16
|
+
Foo::SOME_HASH.frozen? # will return true
|
17
|
+
Foo::SOME_STRING.frozen? # will return true
|
18
|
+
|
19
|
+
All attempts to modify these objects will fail on `RuntimeError`.
|
20
|
+
Objects are reported as frozen of sure. From other points of view they
|
21
|
+
are "normal" and fully compatible with Ruby implicitly
|
22
|
+
non-frozen objects.
|
23
|
+
|
24
|
+
Contributing
|
25
|
+
------------
|
26
|
+
|
27
|
+
1. Fork it.
|
28
|
+
2. Create a branch (`git checkout -b 20101220-my-change`).
|
29
|
+
3. Commit your changes (`git commit -am "Added something"`).
|
30
|
+
4. Push to the branch (`git push origin 20101220-my-change`).
|
31
|
+
5. Create an [Issue][2] with a link to your branch.
|
32
|
+
6. Enjoy a refreshing Diet Coke and wait.
|
33
|
+
|
34
|
+
Copyright
|
35
|
+
---------
|
36
|
+
|
37
|
+
Copyright © 2011 [Martin Kozák][3]. See `LICENSE.txt` for
|
38
|
+
further details.
|
39
|
+
|
40
|
+
[2]: http://github.com/martinkozak/frozen-objects/issues
|
41
|
+
[3]: http://www.martinkozak.net/
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rake'
|
12
|
+
|
13
|
+
require 'jeweler'
|
14
|
+
Jeweler::Tasks.new do |gem|
|
15
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
+
gem.name = "frozen-objects"
|
17
|
+
gem.homepage = "http://github.com/martinkozak/frozen-objects"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = 'Syntax sugar of implicitly frozen objects useful for example in class constants.'
|
20
|
+
gem.email = "martinkozak@martinkozak.net"
|
21
|
+
gem.authors = ["Martin Kozák"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/rdoctask'
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
32
|
+
|
33
|
+
rdoc.rdoc_dir = 'rdoc'
|
34
|
+
rdoc.title = "hash-utils #{version}"
|
35
|
+
rdoc.rdoc_files.include('README*')
|
36
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
37
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
##
|
5
|
+
# Implicitly frozen objects.
|
6
|
+
#
|
7
|
+
|
8
|
+
module Frozen
|
9
|
+
##
|
10
|
+
# Implicitly frozen array.
|
11
|
+
#
|
12
|
+
# @note All calls are +Array+ compatible.
|
13
|
+
# @see http://www.ruby-doc.org/core/classes/Array.html
|
14
|
+
#
|
15
|
+
|
16
|
+
class Array < ::Array
|
17
|
+
def initialize(*args, &block)
|
18
|
+
super(*args, &block)
|
19
|
+
self.freeze
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
##
|
5
|
+
# Implicitly frozen objects.
|
6
|
+
#
|
7
|
+
|
8
|
+
module Frozen
|
9
|
+
##
|
10
|
+
# Implicitly frozen hash.
|
11
|
+
#
|
12
|
+
# @note All calls are +Hash+ compatible.
|
13
|
+
# @see http://www.ruby-doc.org/core/classes/Hash.html
|
14
|
+
#
|
15
|
+
|
16
|
+
class Hash < ::Hash
|
17
|
+
def self.[](*args)
|
18
|
+
result = super(*args)
|
19
|
+
result.freeze
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(*args, &block)
|
23
|
+
super(*args, &block)
|
24
|
+
self.freeze
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
3
|
+
|
4
|
+
##
|
5
|
+
# Implicitly frozen objects.
|
6
|
+
#
|
7
|
+
|
8
|
+
module Frozen
|
9
|
+
##
|
10
|
+
# Implicitly frozen string.
|
11
|
+
#
|
12
|
+
# @note All calls are +String+ compatible.
|
13
|
+
# @see http://www.ruby-doc.org/core/classes/String.html
|
14
|
+
#
|
15
|
+
|
16
|
+
class String < ::String
|
17
|
+
def initialize(*args, &block)
|
18
|
+
super(*args, &block)
|
19
|
+
self.freeze
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/test
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
# (c) 2011 Martin Kozák (martinkozak@martinkozak.net)
|
4
|
+
|
5
|
+
$:.push("./lib")
|
6
|
+
require "frozen-objects"
|
7
|
+
require "riot"
|
8
|
+
|
9
|
+
context "Array" do
|
10
|
+
setup do
|
11
|
+
Frozen::Array[:a, :b]
|
12
|
+
end
|
13
|
+
|
14
|
+
asserts("non-frozen class object equivalence") do
|
15
|
+
topic == [:a, :b]
|
16
|
+
end
|
17
|
+
asserts("frozen state") do
|
18
|
+
begin
|
19
|
+
topic.replace([:c, :d])
|
20
|
+
rescue RuntimeError => e
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "Hash" do
|
27
|
+
setup do
|
28
|
+
Frozen::Hash[:a => :b]
|
29
|
+
end
|
30
|
+
|
31
|
+
asserts("non-frozen class object equivalence") do
|
32
|
+
topic == {:a => :b}
|
33
|
+
end
|
34
|
+
asserts("frozen state") do
|
35
|
+
begin
|
36
|
+
topic.replace({:c => :d})
|
37
|
+
rescue RuntimeError => e
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "String" do
|
44
|
+
setup do
|
45
|
+
Frozen::String::new("frozen")
|
46
|
+
end
|
47
|
+
|
48
|
+
asserts("non-frozen class object equivalence") do
|
49
|
+
topic == "frozen"
|
50
|
+
end
|
51
|
+
asserts("frozen state") do
|
52
|
+
begin
|
53
|
+
topic.replace("new")
|
54
|
+
rescue RuntimeError => e
|
55
|
+
true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: frozen-objects
|
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-03-01 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.0.0
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: jeweler
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.5.2
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: riot
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.12.1
|
46
|
+
type: :development
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
description:
|
50
|
+
email: martinkozak@martinkozak.net
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
files:
|
59
|
+
- .document
|
60
|
+
- Gemfile
|
61
|
+
- Gemfile.lock
|
62
|
+
- LICENSE.txt
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- VERSION
|
66
|
+
- lib/frozen-objects.rb
|
67
|
+
- lib/frozen-objects/array.rb
|
68
|
+
- lib/frozen-objects/hash.rb
|
69
|
+
- lib/frozen-objects/string.rb
|
70
|
+
- test
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://github.com/martinkozak/frozen-objects
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: -322238794642139436
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: "0"
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.5.3
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: Syntax sugar of implicitly frozen objects useful for example in class constants.
|
102
|
+
test_files: []
|
103
|
+
|