conglomerate 0.14.0 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e7f86dfe40e6fc92f0c38175855edca70ef07ae
4
- data.tar.gz: 91f29ea288d44987d94e0538c88a6ad20e84767f
3
+ metadata.gz: c2c95c7a91ce4333ee2a9301b1b284767a3e6ed8
4
+ data.tar.gz: 8abe345a90637675d59b04694983788786a48a04
5
5
  SHA512:
6
- metadata.gz: ed8a22876ae473586c0c47f69c84b945b9537adbb93ca037d3b1ccaf9fafbd74d84efb9642afc9fdb2a888b0b8082365c72a55da7d70bac0327da609421f99c0
7
- data.tar.gz: c92c82fe723c88ff6ba1d17d3e07525efd2f847e9b1f34eb17de17f3b53bfd04a9f8f365854877e4881b7beb2812242d29f6a76d71d1a1e313c7865a947092ba
6
+ metadata.gz: 248bfbc02447751ca4340211f07a6dcc7853ca73100b4fa5b92331563173496188eda3f39a023cbbf8499e4692f46467ef7dae98b17982c0002d3bc65b02267a
7
+ data.tar.gz: 61bca009ebf37f1a5fb42aacf03790dfce70b31948bba07f9697a6e9ca6c27ef46567cb3e7826f2851d6f72d8ce1d4dde20ce401a0f0d1560d4ee96c7ddf4dbf
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec", "~> 3.0.0.beta1"
24
+
25
+ spec.required_ruby_version = '>= 1.9.3'
24
26
  end
@@ -12,10 +12,8 @@ require_relative "conglomerate/command"
12
12
  require_relative "conglomerate/collection"
13
13
  require_relative "conglomerate/tree_deserializer"
14
14
  require_relative "conglomerate/root"
15
-
16
15
  require_relative "conglomerate/mixin_ivar_helper"
17
16
  require_relative "conglomerate/builder_call"
18
-
19
17
  require_relative "conglomerate/builder_serializer"
20
18
  require_relative "conglomerate/particle_builder"
21
19
  require_relative "conglomerate/link_builder"
@@ -2,13 +2,16 @@ module Conglomerate
2
2
  class BuilderCall
3
3
  attr_accessor :name, :opts, :block, :builder, :array, :iterates
4
4
 
5
- def initialize(name: nil, opts: {}, block:, builder:, array:, iterates:)
6
- self.name = name
7
- self.opts = opts
8
- self.block = block
9
- self.builder = builder
10
- self.array = array
11
- self.iterates = iterates
5
+ def initialize(options = {})
6
+ self.name = options.fetch(:name, nil)
7
+ self.opts = options.fetch(:opts, {})
8
+ self.block = options.fetch(:block)
9
+ self.builder = options.fetch(:builder)
10
+ self.array = options.fetch(:array)
11
+ self.iterates = options.fetch(:iterates)
12
+
13
+ rescue KeyError => e
14
+ raise ArgumentError, e.message.gsub("key not found", "missing argument")
12
15
  end
13
16
 
14
17
  def run(context, objects, attrs, attr_name)
@@ -4,10 +4,10 @@ module Conglomerate
4
4
 
5
5
  mi_ivar_accessor :objects, :context, :_builder_name
6
6
 
7
- def initialize(objects, name: nil, context: nil)
7
+ def initialize(objects, options = {})
8
8
  self.objects = [*objects].compact
9
- self.context = context
10
- self._builder_name = name.to_s
9
+ self.context = options.fetch(:context, nil)
10
+ self._builder_name = options.fetch(:name, nil).to_s
11
11
  end
12
12
 
13
13
  def build(attrs = {})
@@ -41,11 +41,20 @@ module Conglomerate
41
41
 
42
42
  private
43
43
 
44
- def array(attr, contains: nil, cull: true)
44
+ def array(attr, options = {})
45
+ contains = options.fetch(:contains, nil)
46
+ cull = options.fetch(:cull, true)
47
+
45
48
  attribute(attr, :type => :array, :contains => contains, :cull => cull)
46
49
  end
47
50
 
48
- def attribute(attr, default: nil, type: nil, contains: nil, cull: true, required: nil)
51
+ def attribute(attr, options = {})
52
+ default = options.fetch(:default, nil)
53
+ type = options.fetch(:type, nil)
54
+ contains = options.fetch(:contains, nil)
55
+ cull = options.fetch(:cull, true)
56
+ required = options.fetch(:required, nil)
57
+
49
58
  instance_variable_get("@attributes")[attr] = {
50
59
  :default => default,
51
60
  :type => type,
@@ -4,9 +4,9 @@ module Conglomerate
4
4
  descendant.extend(ClassMethods)
5
5
  end
6
6
 
7
- def initialize(objects, context: nil)
7
+ def initialize(objects, options = {})
8
8
  self.objects = [*objects].compact
9
- self.context = context
9
+ self.context = options.fetch(:context, nil)
10
10
  end
11
11
 
12
12
  def serialize
@@ -29,7 +29,10 @@ module Conglomerate
29
29
  collection.merge({"version" => "1.0"})
30
30
  end
31
31
 
32
- def apply_href(collection, proc: self.class._href, object: nil)
32
+ def apply_href(collection, options = {})
33
+ proc = options.fetch(:proc, self.class._href)
34
+ object = options.fetch(:object, nil)
35
+
33
36
  if proc
34
37
  if object
35
38
  collection.merge({"href" => context.instance_exec(object, &proc)})
@@ -41,10 +44,12 @@ module Conglomerate
41
44
  end
42
45
  end
43
46
 
44
- def apply_data(
45
- collection, data: [], object: nil, default_value: nil,
46
- build_template: false
47
- )
47
+ def apply_data(collection, options = {})
48
+ data = options.fetch(:data, [])
49
+ object = options.fetch(:object, nil)
50
+ default_value = options.fetch(:default_value, nil)
51
+ build_template = options.fetch(:build_template, false)
52
+
48
53
  data = data.map do |datum|
49
54
  name = datum[:name]
50
55
  type = datum.fetch(:type, :value)
@@ -141,7 +146,10 @@ module Conglomerate
141
146
  end
142
147
  end
143
148
 
144
- def apply_links(collection, links: self.class._links, object: nil)
149
+ def apply_links(collection, options = {})
150
+ links = options.fetch(:links, self.class._links)
151
+ object = options.fetch(:object, nil)
152
+
145
153
  if object && !links.empty?
146
154
  links = links.map do |link|
147
155
  if !link.has_key?(:name) || present?(object.send(link[:name]))
@@ -187,12 +195,19 @@ module Conglomerate
187
195
  apply_data(command, :data => data, :default_value => "")
188
196
  end
189
197
 
190
- def build_item_link(rel, proc: nil, object: nil)
198
+ def build_item_link(rel, options = {})
199
+ proc = options.fetch(:proc, nil)
200
+ object = options.fetch(:object, nil)
201
+
191
202
  link = {"rel" => rel.to_s}
192
203
  apply_href(link, :proc => proc, :object => object)
193
204
  end
194
205
 
195
- def sanitize_value(object, name:, type: :value, default_value: nil)
206
+ def sanitize_value(object, options = {})
207
+ name = options.fetch(:name)
208
+ type = options.fetch(:type, :value)
209
+ default_value = options.fetch(:default_value, nil)
210
+
196
211
  if object.nil? || object.send(name).nil?
197
212
  if type == :array
198
213
  []
@@ -240,7 +255,9 @@ module Conglomerate
240
255
  self._item_href = block
241
256
  end
242
257
 
243
- def query(rel, data: [], &block)
258
+ def query(rel, options = {}, &block)
259
+ data = options.fetch(:data, [])
260
+
244
261
  data = [*data]
245
262
  data = data.map { |datum| {:name => datum} }
246
263
  self._queries = self._queries << {
@@ -248,7 +265,10 @@ module Conglomerate
248
265
  }
249
266
  end
250
267
 
251
- def command(rel, data: [], prompt: nil, &block)
268
+ def command(rel, options = {}, &block)
269
+ data = options.fetch(:data, [])
270
+ prompt = options.fetch(:prompt, nil)
271
+
252
272
  data = [*data]
253
273
  data = data.map { |datum| {:name => datum} }
254
274
  self._commands = self._commands << {
@@ -256,9 +276,12 @@ module Conglomerate
256
276
  }
257
277
  end
258
278
 
259
- def attribute(
260
- name, template: false, rel: nil, type: :value, prompt: nil, &block
261
- )
279
+ def attribute(name, options = {}, &block)
280
+ template = options.fetch(:template, false)
281
+ rel = options.fetch(:rel, nil)
282
+ type = options.fetch(:type, :value)
283
+ prompt = options.fetch(:prompt, nil)
284
+
262
285
  self._attributes = self._attributes << {
263
286
  :name => name, :template => template, :rel => rel, :type => type,
264
287
  :prompt => prompt, :block => block
@@ -277,7 +300,10 @@ module Conglomerate
277
300
  }
278
301
  end
279
302
 
280
- def template(name, type: :value, prompt: nil)
303
+ def template(name, options = {})
304
+ type = options.fetch(:type, :value)
305
+ prompt = options.fetch(:prompt, nil)
306
+
281
307
  self._templates = self._templates << {
282
308
  :name => name, :type => type, :prompt => prompt, :template => true
283
309
  }
@@ -1,3 +1,3 @@
1
1
  module Conglomerate
2
- VERSION = "0.14.0"
2
+ VERSION = "0.15.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require_relative "spec_helper"
2
+ require_relative "../lib/conglomerate"
3
+
4
+ describe Conglomerate::BuilderCall do
5
+ let(:builder_call) {
6
+ Conglomerate::BuilderCall.new
7
+ }
8
+
9
+ context "required arguments" do
10
+ specify "block" do
11
+ expect { builder_call }.to raise_error(ArgumentError)
12
+ end
13
+ end
14
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conglomerate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Emmons
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-07-26 00:00:00.000000000 Z
12
+ date: 2014-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -95,6 +95,7 @@ files:
95
95
  - lib/conglomerate/tree_deserializer.rb
96
96
  - lib/conglomerate/tree_serializer.rb
97
97
  - lib/conglomerate/version.rb
98
+ - spec/builder_call_spec.rb
98
99
  - spec/collection_spec.rb
99
100
  - spec/command_ext_spec.rb
100
101
  - spec/command_spec.rb
@@ -119,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
120
  requirements:
120
121
  - - ">="
121
122
  - !ruby/object:Gem::Version
122
- version: '0'
123
+ version: 1.9.3
123
124
  required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  requirements:
125
126
  - - ">="
@@ -132,6 +133,7 @@ signing_key:
132
133
  specification_version: 4
133
134
  summary: A library to serialize Ruby objects into collection+json
134
135
  test_files:
136
+ - spec/builder_call_spec.rb
135
137
  - spec/collection_spec.rb
136
138
  - spec/command_ext_spec.rb
137
139
  - spec/command_spec.rb
@@ -144,3 +146,4 @@ test_files:
144
146
  - spec/query_spec.rb
145
147
  - spec/spec_helper.rb
146
148
  - spec/tree_deserializer_spec.rb
149
+ has_rdoc: