leaflet 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/leaflet.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'leaflet/configuration'
2
2
  require 'leaflet/collection'
3
+ require 'leaflet/decoration'
3
4
  require 'leaflet/version'
4
5
 
5
6
  module Leaflet
@@ -0,0 +1,16 @@
1
+ module Leaflet
2
+ class Collection < Array
3
+
4
+ # Basic support for decorating collections just like draper does.
5
+ # Could be improved with more options using something like this:
6
+ # https://github.com/drapergem/draper/blob/4b933ef39d252ecfe93c573a072633be545c49fb/lib/draper/collection_decorator.rb
7
+ # Also a #decorated? would be nice. But the following works in 99% of the cases as is.
8
+ #
9
+ def decorate
10
+ result = dup
11
+ result.map!(&:decorate)
12
+ result
13
+ end
14
+
15
+ end
16
+ end
@@ -2,7 +2,7 @@ module Leaflet
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -101,4 +101,25 @@ describe Leaflet::Collection do
101
101
  end
102
102
  end
103
103
  end
104
+
105
+ context 'decoration' do
106
+ let(:decorated_entry1) { double(:decorated_entry1) }
107
+ let(:decorated_entry2) { double(:decorated_entry2) }
108
+ let(:entry1) { double(:entry, decorate: decorated_entry1) }
109
+ let(:entry2) { double(:entry, decorate: decorated_entry2) }
110
+ let(:array) { [entry1, entry2] }
111
+ let(:collection) { Leaflet::Collection.new(array) }
112
+
113
+ it 'decorates all objects' do
114
+ decorated_collection = collection.decorate
115
+ decorated_collection.first.should be decorated_entry1
116
+ decorated_collection.last.should be decorated_entry2
117
+ end
118
+
119
+ it 'is not destructive' do
120
+ collection.decorate
121
+ collection.first.should be entry1
122
+ collection.last.should be entry2
123
+ end
124
+ end
104
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leaflet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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-06 00:00:00.000000000 Z
12
+ date: 2013-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: positify
@@ -84,6 +84,7 @@ extra_rdoc_files: []
84
84
  files:
85
85
  - lib/leaflet/collection.rb
86
86
  - lib/leaflet/configuration.rb
87
+ - lib/leaflet/decoration.rb
87
88
  - lib/leaflet/version.rb
88
89
  - lib/leaflet.rb
89
90
  - spec/lib/leaflet/collection_spec.rb