shipping_materials 0.0.3 → 0.0.4
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.
- checksums.yaml +4 -4
- data/lib/shipping_materials/csv_dsl.rb +13 -12
- data/lib/shipping_materials/version.rb +1 -1
- metadata +2 -3
- data/examples/example.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1b9dcdb8da0785953c8a428897ce709a78c6e05
|
4
|
+
data.tar.gz: 4ed7a1040730d06520f138c0abc334d8def0898c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b142a834c498b01f23d8d7dffa239ddd886953ec7d035d344b50356004ae177cdfad10878b037e0381a7b21d23b4b0f4d716efe3f0d3eefcec49ee2428d03556
|
7
|
+
data.tar.gz: a491f84810ac38439f42f0674f6eb81e8ae136a866e7465caba4912bc934cdf07cb1ae372cdb9229e428b65284dfe472c9e9bfff6d15b2a3d2ab097daf76f46b
|
@@ -7,7 +7,7 @@ module ShippingMaterials
|
|
7
7
|
|
8
8
|
def initialize(objects, options={})
|
9
9
|
@objects = objects
|
10
|
-
@row_maps =
|
10
|
+
@row_maps = []
|
11
11
|
@options = options
|
12
12
|
end
|
13
13
|
|
@@ -15,7 +15,6 @@ module ShippingMaterials
|
|
15
15
|
# performs type-checking and also sets the headers.
|
16
16
|
# Be sure to see headers=() defined below
|
17
17
|
def row(collection, callbacks={})
|
18
|
-
@callbacks = callbacks
|
19
18
|
if collection.is_a? Array
|
20
19
|
update_row_maps(:object, collection, callbacks)
|
21
20
|
elsif collection.is_a? Hash
|
@@ -36,13 +35,13 @@ module ShippingMaterials
|
|
36
35
|
CSV.generate do |csv|
|
37
36
|
csv << headers if headers?
|
38
37
|
@objects.each do |object|
|
39
|
-
@row_maps.each do |
|
40
|
-
next unless apply_callbacks(
|
41
|
-
if context == :object
|
42
|
-
csv << get_row(object,
|
38
|
+
@row_maps.each do |row_map|
|
39
|
+
next unless apply_callbacks(row_map[:callbacks], object)
|
40
|
+
if row_map[:context] == :object
|
41
|
+
csv << get_row(object, row_map[:values])
|
43
42
|
else
|
44
|
-
object.send(context).each do |obj|
|
45
|
-
csv << get_row(obj,
|
43
|
+
object.send(row_map[:context]).each do |obj|
|
44
|
+
csv << get_row(obj, row_map[:values])
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
@@ -87,10 +86,12 @@ module ShippingMaterials
|
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
90
|
-
def update_row_maps(
|
91
|
-
@row_maps
|
92
|
-
|
93
|
-
|
89
|
+
def update_row_maps(context, values, callbacks)
|
90
|
+
@row_maps << {
|
91
|
+
context: context,
|
92
|
+
values: values,
|
93
|
+
callbacks: callbacks
|
94
|
+
}
|
94
95
|
end
|
95
96
|
end
|
96
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shipping_materials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Haust
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
11
|
+
date: 2013-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -94,7 +94,6 @@ files:
|
|
94
94
|
- LICENSE.txt
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
|
-
- examples/example.rb
|
98
97
|
- lib/shipping_materials.rb
|
99
98
|
- lib/shipping_materials/config.rb
|
100
99
|
- lib/shipping_materials/csv_dsl.rb
|
data/examples/example.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
ShippingMaterials.config do |config|
|
2
|
-
config.save_path = MyProject::Config[:asset_storage_location]
|
3
|
-
end
|
4
|
-
|
5
|
-
packager = ShippingMaterials::Packager.new
|
6
|
-
|
7
|
-
orders = Orders.where(state: 'placed')
|
8
|
-
|
9
|
-
packager.package orders do
|
10
|
-
pdf 'path/to/template',
|
11
|
-
|
12
|
-
sort(:line_items) {
|
13
|
-
rule { type == 'Vinyl' }
|
14
|
-
rule { type == 'CD' }
|
15
|
-
rule { type == 'Cassette' }
|
16
|
-
}
|
17
|
-
|
18
|
-
sort {
|
19
|
-
rule { line_items.detect {|li| li.type == 'vinyl' } }
|
20
|
-
}
|
21
|
-
|
22
|
-
group 'canada_standard_shipping' do
|
23
|
-
filter { country == 'CA' && shipping_method == 'std' }
|
24
|
-
|
25
|
-
csv(extenstion: 'txt', headers: true) {
|
26
|
-
row code: 'Q',
|
27
|
-
order_id: :id,
|
28
|
-
hello: :hello
|
29
|
-
|
30
|
-
row line_items: [ 'H', :id, :name, :price, :quantity ]
|
31
|
-
}
|
32
|
-
end
|
33
|
-
end
|