hard-boiled 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.
@@ -44,11 +44,19 @@ module HardBoiled
44
44
  self.class.define(value, self.subject, &block)
45
45
  end
46
46
  else
47
- __format_value __apply_filters(value, options), options
47
+ __set_defaults __format_value(__apply_filters(value, options), options), options
48
48
  end
49
49
  self
50
50
  end
51
-
51
+
52
+ def __set_defaults value, options
53
+ if value.nil? and default = options[:default]
54
+ default
55
+ else
56
+ value
57
+ end
58
+ end
59
+
52
60
  def __apply_filters value, options
53
61
  if filters = options[:filters]
54
62
  filters.inject(value) { |result, filter|
@@ -1,5 +1,5 @@
1
1
  module Hard
2
2
  module Boiled
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -19,6 +19,11 @@ describe HardBoiled::Presenter do
19
19
  OpenStruct.new({:temperature => 25, :boil_time => 7, :colour => "white"})
20
20
  }
21
21
 
22
+ let(:conventional_egg) {
23
+ OpenStruct.new({:temperature => 25, :boil_time => 5,
24
+ :colour => "brownish", :organic => false})
25
+ }
26
+
22
27
  it "should produce correct hash" do
23
28
  definition = described_class.define egg do
24
29
  colour
@@ -94,4 +99,33 @@ describe HardBoiled::Presenter do
94
99
  end
95
100
 
96
101
  end
102
+
103
+ context :defaults do
104
+ def with_defaults obj
105
+ Filterable.define obj do
106
+ colour :filters => [:upcase]
107
+ time :from => :boil_time
108
+ consumer "Lennart"
109
+ organic :default => true
110
+ end
111
+ end
112
+
113
+ it "should fallback to defaults" do
114
+ with_defaults(egg).should == {
115
+ :colour => "WHITE",
116
+ :time => 7,
117
+ :consumer => "Lennart",
118
+ :organic => true
119
+ }
120
+ end
121
+
122
+ it "should still use defined values" do
123
+ with_defaults(conventional_egg).should == {
124
+ :colour => "BROWNISH",
125
+ :time => 5,
126
+ :consumer => "Lennart",
127
+ :organic => false
128
+ }
129
+ end
130
+ end
97
131
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hard-boiled
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lennart Melzer