shash 0.0.1 → 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.
- data/README.md +39 -0
- data/lib/shash.rb +2 -3
- data/lib/version.rb +1 -1
- data/test/test_shash.rb +2 -2
- metadata +2 -2
- data/README +0 -35
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
Shash
|
2
|
+
=====
|
3
|
+
Shash provides a quick way to handle configuration file, settings or other form of key/value store. It's based
|
4
|
+
on a single hash, but lets you set/read keys like attributes. Shash stands for StructHash or, for intimates,
|
5
|
+
SuperHash.
|
6
|
+
|
7
|
+
Installation
|
8
|
+
------------
|
9
|
+
gem install shash
|
10
|
+
|
11
|
+
Test
|
12
|
+
----
|
13
|
+
rspec test/test_shash.rb
|
14
|
+
|
15
|
+
Usage
|
16
|
+
-----
|
17
|
+
Here is the simpliest scenario
|
18
|
+
|
19
|
+
Settings = Shash.new({"name"=>"Shash!", "application"=>{"version"=>1}})
|
20
|
+
Settings.name #=> "Shash!"
|
21
|
+
Settings.application #=> {"version"=>1}
|
22
|
+
Settings.application.version #=> 1
|
23
|
+
|
24
|
+
From a hash, it could not be simplier
|
25
|
+
|
26
|
+
Settings = {"name"=>"Shash!"}.to_shash
|
27
|
+
Settings.name #=> "Shash!"
|
28
|
+
|
29
|
+
You can of course set values directly from a Shash object
|
30
|
+
|
31
|
+
Settings = Shash.new
|
32
|
+
Settings.has_key?("name") #=> false
|
33
|
+
Settings.name = "Shash!"
|
34
|
+
Settings.has_key?("name") #=> true
|
35
|
+
Settings.name #=> "Shash!"
|
36
|
+
|
37
|
+
From a YAML file, or any other key/value kind of file
|
38
|
+
|
39
|
+
Settings = YAML.load_file( "path/to/your/file.yml" ).to_shash
|
data/lib/shash.rb
CHANGED
@@ -22,11 +22,10 @@ class Shash
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def has_key?(key)
|
26
26
|
@hash.has_key?(key.to_s)
|
27
27
|
end
|
28
|
-
alias_method :
|
29
|
-
alias_method :key?, :respond_to?
|
28
|
+
alias_method :key?, :has_key?
|
30
29
|
|
31
30
|
def == other
|
32
31
|
@hash == other.hash
|
data/lib/version.rb
CHANGED
data/test/test_shash.rb
CHANGED
@@ -26,8 +26,8 @@ describe Shash do
|
|
26
26
|
|
27
27
|
it "#respond_to? should check for key existence correctly" do
|
28
28
|
h = {"a"=>1, "b"=>{"c"=>2}}.to_shash
|
29
|
-
h.
|
29
|
+
h.has_key?("z").should == false
|
30
30
|
h.has_key?("b").should == true
|
31
|
-
h.b.
|
31
|
+
h.b.has_key?("c").should == true
|
32
32
|
end
|
33
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,7 +19,7 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- LICENSE
|
22
|
-
- README
|
22
|
+
- README.md
|
23
23
|
- lib/shash.rb
|
24
24
|
- lib/version.rb
|
25
25
|
- shash.gemspec
|
data/README
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
Shash
|
2
|
-
=====
|
3
|
-
Shash provides quick way to handle configuration file, settings or other form of key/value store. It's based
|
4
|
-
on a single hash, but lets you set/read keys like attributes. Shash stands for StructHash or, for intimates,
|
5
|
-
SuperHash.
|
6
|
-
|
7
|
-
Installation
|
8
|
-
------------
|
9
|
-
gem install shash
|
10
|
-
|
11
|
-
Test
|
12
|
-
----
|
13
|
-
rspec test/test_shash.rb
|
14
|
-
|
15
|
-
Usage
|
16
|
-
-----
|
17
|
-
Here his the simpliest scenario
|
18
|
-
Settings = Shash.new({"name"=>"Shash!", "application"=>{"version"=>1}})
|
19
|
-
Settings.name #=> "Shash!"
|
20
|
-
Settings.application #=> {"version"=>1}
|
21
|
-
Settings.application.version #=> 1
|
22
|
-
|
23
|
-
From a hash, it could not be simplier
|
24
|
-
Settings = {"name"=>"Shash!"}.to_shash
|
25
|
-
Settings.name #=> "Shash!"
|
26
|
-
|
27
|
-
You can of course set values directly from a Shash object
|
28
|
-
Settings = Shash.new
|
29
|
-
Settings.respond_to?("name") #=> false
|
30
|
-
Settings.name = "Shash!"
|
31
|
-
Settings.respond_to?("name") #=> true
|
32
|
-
Settings.name #=> "Shash!"
|
33
|
-
|
34
|
-
From a YAML file, or any other key/value kind of file
|
35
|
-
Settings = YAML.load_file( "path/to/your/file.yml" ).to_shash
|