bldr 1.0.0 → 1.0.1

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/HISTORY.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 1.0.1
2
+ * #32 Improved `object` syntax
3
+
4
+ ## 1.0.0
5
+ * Full Rails 3 support
6
+ * #31 BREAKING: Properly handle nil objects
7
+
1
8
  ## 0.7.0 (2013-02-24)
2
9
  * Full support for instance variables
3
10
  * Breaking change: Node#attribute block syntax no longer inherits
@@ -109,6 +109,11 @@ module Bldr
109
109
  # object :hobbies => hobbies
110
110
  # end
111
111
  #
112
+ # @example Setting current object
113
+ # object @person do
114
+ # attributes :id, :name
115
+ # end # => {'id' => 1, 'name' => 'john doe'}
116
+ #
112
117
  # @param [Hash, Nil] hash a key/value pair indicating the output key name
113
118
  # and the object to serialize.
114
119
  # @param [Proc] block the code block to evaluate
@@ -119,15 +124,22 @@ module Bldr
119
124
  if keyed_object?(base)
120
125
  key = base.keys.first
121
126
  value = base.values.first
122
- else
123
- key = base
124
- value = nil
125
- end
126
127
 
127
- # handle nil objects
128
- if value.nil? && keyed_object?(base)
129
- merge_result!(key, nil)
130
- return self
128
+ # handle nil objects
129
+ if value.nil?
130
+ merge_result!(key, nil)
131
+ return self
132
+ end
133
+ else
134
+ # e.g. set the keyspace for an object
135
+ if base.is_a?(Symbol) || base.is_a?(String)
136
+ key = base
137
+ value = nil
138
+ else
139
+ # e.g. set current object
140
+ value = base
141
+ key = nil
142
+ end
131
143
  end
132
144
 
133
145
  node = Node.new(value, opts.merge(:parent => self), &block)
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Bldr
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'setting the current object in an object block' do
4
+ it 'sets the object' do
5
+ klass = Struct.new(:name)
6
+ person = klass.new('alex')
7
+ Bldr::Node.new(nil, locals: {person: person}) do
8
+ object person do
9
+ attributes(:name)
10
+ end
11
+ end.result.should == {name: 'alex'}
12
+ end
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bldr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-01 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -147,6 +147,7 @@ files:
147
147
  - spec/functional/handlers_spec.rb
148
148
  - spec/functional/helpers_spec.rb
149
149
  - spec/functional/params_spec.rb
150
+ - spec/functional/set_current_object_spec.rb
150
151
  - spec/functional/tilt_template_spec.rb
151
152
  - spec/integration/rails_32_spec.rb
152
153
  - spec/integration/sinatra_spec.rb
@@ -195,6 +196,7 @@ test_files:
195
196
  - spec/functional/handlers_spec.rb
196
197
  - spec/functional/helpers_spec.rb
197
198
  - spec/functional/params_spec.rb
199
+ - spec/functional/set_current_object_spec.rb
198
200
  - spec/functional/tilt_template_spec.rb
199
201
  - spec/integration/rails_32_spec.rb
200
202
  - spec/integration/sinatra_spec.rb