hard-boiled 0.0.3 → 0.1.0

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.
@@ -34,7 +34,23 @@ module HardBoiled
34
34
  private
35
35
  def method_missing id, *args, &block
36
36
  options = args.extract_options!
37
- value = options[:nil] ? nil : (args.shift || (options[:parent] ? parent_subject : subject).__send__(options[:from] || id))
37
+ params = options[:params]
38
+ value =
39
+ if options[:nil]
40
+ nil
41
+ else
42
+ if static = args.shift
43
+ static
44
+ else
45
+ object = options[:parent] ? parent_subject : subject
46
+ method_name = options[:from] || id
47
+ if params
48
+ object.__send__ method_name, *params
49
+ else
50
+ object.__send__ method_name
51
+ end
52
+ end
53
+ end
38
54
  @hash[id] =
39
55
  if block_given?
40
56
  if value.kind_of? Array
@@ -1,5 +1,5 @@
1
1
  module Hard
2
2
  module Boiled
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -14,6 +14,24 @@ class Filterable < HardBoiled::Presenter
14
14
  include MyFilters
15
15
  end
16
16
 
17
+ class Calculator
18
+ def add a, b
19
+ a + b
20
+ end
21
+
22
+ def zero
23
+ 0
24
+ end
25
+
26
+ def negative
27
+ -100
28
+ end
29
+
30
+ def tax val = 0.0
31
+ ((val + 1) * 2700).to_i
32
+ end
33
+ end
34
+
17
35
  describe HardBoiled::Presenter do
18
36
  let(:egg) {
19
37
  OpenStruct.new({:temperature => 25, :boil_time => 7, :colour => "white"})
@@ -38,6 +56,36 @@ describe HardBoiled::Presenter do
38
56
  }
39
57
  end
40
58
 
59
+ context :paramified do
60
+ it "should pass params to member function" do
61
+ definition = described_class.define(Calculator.new) do
62
+ negative
63
+ zero
64
+ add :params => [5, 2]
65
+ end
66
+
67
+ definition.should == {
68
+ :negative => -100,
69
+ :zero => 0,
70
+ :add => 7
71
+ }
72
+ end
73
+
74
+ it "should pass param to member function" do
75
+ definition = described_class.define(Calculator.new) do
76
+ null :from => :zero
77
+ tax
78
+ sales :from => :tax, :params => 0.19
79
+ end
80
+
81
+ definition.should == {
82
+ :null => 0,
83
+ :tax => 2700,
84
+ :sales => 3213
85
+ }
86
+ end
87
+ end
88
+
41
89
  context :nested do
42
90
  let(:egg_box) {
43
91
  OpenStruct.new({
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hard-boiled
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
7
+ - 1
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ version: 0.1.0
11
10
  platform: ruby
12
11
  authors:
13
12
  - Lennart Melzer
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-11-23 00:00:00 +01:00
17
+ date: 2012-03-21 00:00:00 +01:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
@@ -50,27 +49,23 @@ rdoc_options: []
50
49
  require_paths:
51
50
  - lib
52
51
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
52
  requirements:
55
53
  - - ">="
56
54
  - !ruby/object:Gem::Version
57
- hash: 3
58
55
  segments:
59
56
  - 0
60
57
  version: "0"
61
58
  required_rubygems_version: !ruby/object:Gem::Requirement
62
- none: false
63
59
  requirements:
64
60
  - - ">="
65
61
  - !ruby/object:Gem::Version
66
- hash: 3
67
62
  segments:
68
63
  - 0
69
64
  version: "0"
70
65
  requirements: []
71
66
 
72
67
  rubyforge_project: hard-boiled
73
- rubygems_version: 1.4.2
68
+ rubygems_version: 1.3.6
74
69
  signing_key:
75
70
  specification_version: 3
76
71
  summary: Get your models boiled down to plain hashes!