hard_boiled 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +22 -5
- data/lib/hard_boiled.rb +1 -1
- data/lib/hard_boiled/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
## HardBoiled
|
2
2
|
|
3
|
-
simply define mapping from
|
3
|
+
simply define a mapping from your model to a simple hash. For those who worked with [thoughtbot](http://thoughtbot.com)'s [factory girl](http://github.com/thoughtbot/factory_girl) the DSL should be familiar.
|
4
4
|
|
5
5
|
### Installation
|
6
6
|
|
7
|
-
gem install
|
7
|
+
gem install hard_boiled
|
8
8
|
|
9
9
|
### Usage
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
require '
|
12
|
+
require 'hard_boiled'
|
13
13
|
|
14
14
|
egg = OpenStruct.new({
|
15
15
|
:boil_time => 7,
|
@@ -21,14 +21,31 @@ HardBoiled::Presenter.define egg do
|
|
21
21
|
time :from => :boil_time
|
22
22
|
colour
|
23
23
|
temperature :format => "%d ℃"
|
24
|
-
end
|
24
|
+
end
|
25
|
+
# => { :time => 7, :temperature => "99 ℃", :colour => "beige" }
|
26
|
+
|
27
|
+
# Or with traits
|
28
|
+
|
29
|
+
HardBoiled::Presenter.define(egg, :only => [:instructions]) do
|
30
|
+
with_trait(:instructions) do
|
31
|
+
time :from => :boil_time
|
32
|
+
temperature :format => "%d ℃"
|
33
|
+
end
|
34
|
+
|
35
|
+
with_trait(:presentation) do
|
36
|
+
colour
|
37
|
+
end
|
38
|
+
|
39
|
+
omnipresent_slogan "proudly produced on organic farms"
|
40
|
+
end
|
41
|
+
# => { :time => 7, :temperature => "99 ℃", :omnipresent_slogan => "proudly produced on organic farms" }
|
25
42
|
```
|
26
43
|
|
27
44
|
for more examples see the tests in the `spec` directory.
|
28
45
|
|
29
46
|
### Similar Projects
|
30
47
|
|
31
|
-
If _hard
|
48
|
+
If _hard\_boiled_ isn't your cup of tea, go and check out other ways to map models
|
32
49
|
to hashes (for data serialization):
|
33
50
|
|
34
51
|
* [Representative](https://github.com/mdub/representative)
|
data/lib/hard_boiled.rb
CHANGED
data/lib/hard_boiled/version.rb
CHANGED