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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b542958f709628b6a1d1fce332e11074c8e00a4c
4
- data.tar.gz: 8df40c91ed11cd51f8e5b526a31f630cff4a7d9f
2
+ SHA256:
3
+ metadata.gz: fa3dadc3be4934ed2b6829c8b96a80a7a10da5cc4466d251e9306007f555c52a
4
+ data.tar.gz: 5768506f6b6bfa05bad2f2e51c357f210545a2e0d7da4748a71b976f5702d027
5
5
  SHA512:
6
- metadata.gz: 187563335fa1100e557bdbbddc7c155f82f755746f546e435d49ac55053ae5e60ce1d8b97cd8e6112eefad5daed8ea6fa584f4791b76e99706a5d7625d310c9e
7
- data.tar.gz: 11ffc896106586065d7673f3f31dc6c9c4b4c5f60735104d507cc8f70b433d2c3806af62592f4446143ee574e5e8da7f6e6f17df9bb1c4d1f74d6ed17bc6919a
6
+ metadata.gz: f63495bd7e4cd81c3df888123990444c310c932886ce087b76817d29ed0964ffdb2842e2edf413f9e7a0b70f19a383a61faba689278273209c7950f86393def4
7
+ data.tar.gz: '08959772994e511e90bf5fb6996b3ceab6880e27cc1d9f025e88f8b9084c1c0150e3fd452786ee93bfae3080824e55fc343f9959aadecb9f7baf8a56b9cf157f'
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
6
+
7
+ ## 0.3.0 - 2018-08-29
8
+
9
+ ### Added
10
+
11
+ - Changelog
12
+ - Attribute labels
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 Pablo Crivella
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/pablocrivella/smuggle.
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
@@ -34,7 +34,7 @@ module Smuggle
34
34
 
35
35
  def generate_csv
36
36
  CSV.generate do |csv|
37
- csv << exporter.attributes
37
+ csv << exporter.header
38
38
 
39
39
  scope.each do |record|
40
40
  csv << exporter.new(record).to_csv
@@ -1,3 +1,3 @@
1
1
  module Smuggle
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
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.2.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: 2017-09-20 00:00:00.000000000 Z
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.txt
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.6.13
164
+ rubygems_version: 2.7.7
164
165
  signing_key:
165
166
  specification_version: 4
166
167
  summary: It Exports stuff to CSV