smuggle 0.2.0 → 0.3.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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +12 -0
- data/{LICENSE.txt → LICENSE} +1 -1
- data/README.md +25 -1
- data/lib/smuggle/exporter/base.rb +17 -0
- data/lib/smuggle/services/export.rb +1 -1
- data/lib/smuggle/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fa3dadc3be4934ed2b6829c8b96a80a7a10da5cc4466d251e9306007f555c52a
|
4
|
+
data.tar.gz: 5768506f6b6bfa05bad2f2e51c357f210545a2e0d7da4748a71b976f5702d027
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f63495bd7e4cd81c3df888123990444c310c932886ce087b76817d29ed0964ffdb2842e2edf413f9e7a0b70f19a383a61faba689278273209c7950f86393def4
|
7
|
+
data.tar.gz: '08959772994e511e90bf5fb6996b3ceab6880e27cc1d9f025e88f8b9084c1c0150e3fd452786ee93bfae3080824e55fc343f9959aadecb9f7baf8a56b9cf157f'
|
data/CHANGELOG.md
ADDED
data/{LICENSE.txt → LICENSE}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2018 Inspire Innovation BV (Utrecht, The Netherlands).
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -99,9 +99,33 @@ Or if you are using active record, the exporter class will be automatically reso
|
|
99
99
|
Smuggle::Services::Export.call(scope: User.all)
|
100
100
|
```
|
101
101
|
|
102
|
+
## Attribute labels
|
103
|
+
|
104
|
+
To add labels for your attributes (to show in the header instead of the raw attribute keys) you can add **attribute_labels** to your exporter:
|
105
|
+
|
106
|
+
``` ruby
|
107
|
+
class User
|
108
|
+
attr_accessor :name
|
109
|
+
|
110
|
+
def initialize(name)
|
111
|
+
@name = name
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class UserExporter < ApplicationExporter
|
116
|
+
attributes :name
|
117
|
+
attribute_labels name: 'Full name'
|
118
|
+
end
|
119
|
+
|
120
|
+
users = [User.new('Rick Sanchez'), User.new('Morty Smith')]
|
121
|
+
|
122
|
+
Smuggle::Services::Export.call(scope: users, exporter: UserExporter)
|
123
|
+
# => "Full name\n" + "Rick Sanchez\n" + "Morty Smith\n"
|
124
|
+
```
|
125
|
+
|
102
126
|
## Contributing
|
103
127
|
|
104
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
128
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/InspireNL/smuggle.
|
105
129
|
|
106
130
|
## Todo
|
107
131
|
|
@@ -3,9 +3,11 @@ module Smuggle
|
|
3
3
|
class Base < SimpleDelegator
|
4
4
|
class << self
|
5
5
|
attr_accessor :attributes
|
6
|
+
attr_accessor :attribute_labels
|
6
7
|
|
7
8
|
def inherited(base)
|
8
9
|
base.attributes = []
|
10
|
+
base.attribute_labels = {}
|
9
11
|
end
|
10
12
|
|
11
13
|
def attributes(*names)
|
@@ -15,6 +17,21 @@ module Smuggle
|
|
15
17
|
def attributes?
|
16
18
|
@attributes.any?
|
17
19
|
end
|
20
|
+
|
21
|
+
def attribute_labels(labels)
|
22
|
+
@attribute_labels.merge!(labels)
|
23
|
+
end
|
24
|
+
|
25
|
+
def attribute_labels?
|
26
|
+
@attribute_labels.any?
|
27
|
+
end
|
28
|
+
|
29
|
+
def header
|
30
|
+
return @attributes unless attribute_labels?
|
31
|
+
return @attributes.map do |attribute|
|
32
|
+
@attribute_labels.fetch(attribute, attribute)
|
33
|
+
end
|
34
|
+
end
|
18
35
|
end
|
19
36
|
|
20
37
|
def to_csv
|
data/lib/smuggle/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smuggle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Crivella
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -120,9 +120,10 @@ files:
|
|
120
120
|
- ".rspec"
|
121
121
|
- ".rubocop.yml"
|
122
122
|
- ".travis.yml"
|
123
|
+
- CHANGELOG.md
|
123
124
|
- CODE_OF_CONDUCT.md
|
124
125
|
- Gemfile
|
125
|
-
- LICENSE
|
126
|
+
- LICENSE
|
126
127
|
- README.md
|
127
128
|
- Rakefile
|
128
129
|
- bin/console
|
@@ -160,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
161
|
version: '0'
|
161
162
|
requirements: []
|
162
163
|
rubyforge_project:
|
163
|
-
rubygems_version: 2.
|
164
|
+
rubygems_version: 2.7.7
|
164
165
|
signing_key:
|
165
166
|
specification_version: 4
|
166
167
|
summary: It Exports stuff to CSV
|