Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updated readme to document the Lash

  • Loading branch information...
commit 502c1f45548aed1712a511162ce6da0393473a56 1 parent 4d583a8
authored July 02, 2011

Showing 1 changed file with 39 additions and 12 deletions. Show diff stats Hide diff stats

  1. 51  README.rdoc
51  README.rdoc
Source Rendered
@@ -4,7 +4,7 @@ Hashie is a growing collection of tools that extend Hashes and make
4 4
 them more useful.
5 5
 
6 6
 == Installation
7  
-    
  7
+
8 8
 Hashie is available as a RubyGem:
9 9
 
10 10
     gem install hashie
@@ -13,11 +13,11 @@ Hashie is available as a RubyGem:
13 13
 
14 14
 Mash is an extended Hash that gives simple pseudo-object functionality
15 15
 that can be built from hashes and easily extended. It is designed to
16  
-be used in RESTful API libraries to provide easy object-like access 
  16
+be used in RESTful API libraries to provide easy object-like access
17 17
 to JSON and XML parsed hashes.
18 18
 
19 19
 === Example:
20  
-  
  20
+
21 21
     mash = Hashie::Mash.new
22 22
     mash.name? # => false
23 23
     mash.name # => nil
@@ -25,16 +25,16 @@ to JSON and XML parsed hashes.
25 25
     mash.name # => "My Mash"
26 26
     mash.name? # => true
27 27
     mash.inspect # => <Hashie::Mash name="My Mash">
28  
-  
  28
+
29 29
     mash = Mash.new
30 30
     # use bang methods for multi-level assignment
31 31
     mash.author!.name = "Michael Bleigh"
32 32
     mash.author # => <Hashie::Mash name="Michael Bleigh">
33 33
 
34  
-<b>Note:</b> The <tt>?</tt> method will return false if a key has been set 
  34
+<b>Note:</b> The <tt>?</tt> method will return false if a key has been set
35 35
 to false or nil. In order to check if a key has been set at all, use the
36 36
 <tt>mash.key?('some_key')</tt> method instead.
37  
-  
  37
+
38 38
 == Dash
39 39
 
40 40
 Dash is an extended Hash that has a discrete set of defined properties
@@ -56,11 +56,11 @@ can set defaults for each property.
56 56
     p.email        # => 'abc@def.com'
57 57
     p[:awesome]    # => NoMethodError
58 58
     p[:occupation] # => 'Rubyist'
59  
-    
  59
+
60 60
     p = Person.new(:name => "Bob")
61 61
     p.name       # => 'Bob'
62 62
     p.occupation # => 'Rubyist'
63  
-    
  63
+
64 64
 == Trash
65 65
 
66 66
 A Trash is a Dash that allows you to translate keys on initialization.
@@ -69,12 +69,12 @@ It is used like so:
69 69
     class Person < Hashie::Trash
70 70
       property :first_name, :from => :firstName
71 71
     end
72  
-    
  72
+
73 73
 This will automatically translate the <tt>firstName</tt> key to <tt>first_name</tt>
74 74
 when it is initialized using a hash such as through:
75  
-  
  75
+
76 76
     Person.new(:firstName => 'Bob')
77  
-    
  77
+
78 78
 == Clash
79 79
 
80 80
 Clash is a Chainable Lazy Hash that allows you to easily construct
@@ -102,8 +102,35 @@ provide.
102 102
     c.where(:abc => 'def').where(:hgi => 123)
103 103
     c # => {:where => {:abc => 'def', :hgi => 123}}
104 104
 
  105
+== Lash
  106
+
  107
+Lash is an extended Dash that allows properties to be set
  108
+as required. These required properties will cause new Lash
  109
+instances to "lash out" by raising an error when passed a
  110
+nil value.
  111
+
  112
+=== Example:
  113
+
  114
+    class Person < Hashie::Dash
  115
+      property :name, :required => true
  116
+      property :email
  117
+      property :occupation, :default => 'Rubyist'
  118
+    end
  119
+
  120
+    p = Person.new # => ArgumentError: The property 'name' is required for this Lash.
  121
+
  122
+    p = Person.new(:name => 'Bob')
  123
+    p.name # => 'Bob'
  124
+    p.email = 'abc@def.com'
  125
+    p.occupation   # => 'Rubyist'
  126
+    p.email        # => 'abc@def.com'
  127
+    p[:awesome]    # => NoMethodError
  128
+    p[:occupation] # => 'Rubyist'
  129
+
  130
+    p.name = nil # => ArgumentError: The property 'name' is required for this Lash.
  131
+
105 132
 == Note on Patches/Pull Requests
106  
- 
  133
+
107 134
 * Fork the project.
108 135
 * Make your feature addition or bug fix.
109 136
 * Add tests for it. This is important so I don't break it in a future version unintentionally.

0 notes on commit 502c1f4

Please sign in to comment.
Something went wrong with that request. Please try again.