decisive 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -3
- data/Gemfile.lock +17 -17
- data/README.md +12 -29
- data/decisive.gemspec +2 -2
- data/lib/decisive/template_handler.rb +38 -24
- data/lib/decisive/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d28c31cc0299732df3599ea1902bfa2d6586ae70
|
4
|
+
data.tar.gz: 5002e3b395a7fb0f56ff77ec1bab7e9280fa9016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f413f05a6292d19c47d716f8792ff58ee5f3715d13105b1823b450e32b99f696c86cd65f529a6d10a90f2aeef74dec45aaaf64193e65db195095a226de79fb86
|
7
|
+
data.tar.gz: 4ed224da57a64802dbaeb0126a98ffbc472c33a28b833eb3d69728ada9f5c690a5723ae62a574b45879a49cedada464b7025abd7a4e65e69195210e59b51345d
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,51 +1,51 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
decisive (0.
|
4
|
+
decisive (0.3.0)
|
5
5
|
actionview
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionview (5.2.
|
11
|
-
activesupport (= 5.2.
|
10
|
+
actionview (5.2.3)
|
11
|
+
activesupport (= 5.2.3)
|
12
12
|
builder (~> 3.1)
|
13
13
|
erubi (~> 1.4)
|
14
14
|
rails-dom-testing (~> 2.0)
|
15
15
|
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
16
|
-
activesupport (5.2.
|
16
|
+
activesupport (5.2.3)
|
17
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
18
|
i18n (>= 0.7, < 2)
|
19
19
|
minitest (~> 5.1)
|
20
20
|
tzinfo (~> 1.1)
|
21
21
|
builder (3.2.3)
|
22
|
-
byebug (
|
23
|
-
concurrent-ruby (1.
|
22
|
+
byebug (11.0.1)
|
23
|
+
concurrent-ruby (1.1.5)
|
24
24
|
crass (1.0.4)
|
25
25
|
diff-lcs (1.3)
|
26
|
-
erubi (1.
|
27
|
-
i18n (1.
|
26
|
+
erubi (1.8.0)
|
27
|
+
i18n (1.6.0)
|
28
28
|
concurrent-ruby (~> 1.0)
|
29
|
-
loofah (2.2.
|
29
|
+
loofah (2.2.3)
|
30
30
|
crass (~> 1.0.2)
|
31
31
|
nokogiri (>= 1.5.9)
|
32
|
-
mini_portile2 (2.
|
32
|
+
mini_portile2 (2.4.0)
|
33
33
|
minitest (5.11.3)
|
34
|
-
nokogiri (1.
|
35
|
-
mini_portile2 (~> 2.
|
34
|
+
nokogiri (1.10.3)
|
35
|
+
mini_portile2 (~> 2.4.0)
|
36
36
|
rails-dom-testing (2.0.3)
|
37
37
|
activesupport (>= 4.2.0)
|
38
38
|
nokogiri (>= 1.6)
|
39
39
|
rails-html-sanitizer (1.0.4)
|
40
40
|
loofah (~> 2.2, >= 2.2.2)
|
41
|
-
rake (
|
41
|
+
rake (12.3.2)
|
42
42
|
rspec (3.8.0)
|
43
43
|
rspec-core (~> 3.8.0)
|
44
44
|
rspec-expectations (~> 3.8.0)
|
45
45
|
rspec-mocks (~> 3.8.0)
|
46
46
|
rspec-core (3.8.0)
|
47
47
|
rspec-support (~> 3.8.0)
|
48
|
-
rspec-expectations (3.8.
|
48
|
+
rspec-expectations (3.8.3)
|
49
49
|
diff-lcs (>= 1.2.0, < 2.0)
|
50
50
|
rspec-support (~> 3.8.0)
|
51
51
|
rspec-mocks (3.8.0)
|
@@ -60,11 +60,11 @@ PLATFORMS
|
|
60
60
|
ruby
|
61
61
|
|
62
62
|
DEPENDENCIES
|
63
|
-
bundler
|
63
|
+
bundler
|
64
64
|
byebug
|
65
65
|
decisive!
|
66
|
-
rake
|
66
|
+
rake
|
67
67
|
rspec (~> 3.0)
|
68
68
|
|
69
69
|
BUNDLED WITH
|
70
|
-
|
70
|
+
2.0.1
|
data/README.md
CHANGED
@@ -1,22 +1,9 @@
|
|
1
1
|
# Decisive
|
2
2
|
|
3
|
-
DSL for rendering CSVs
|
3
|
+
DSL for rendering CSVs in Rails apps
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'decisive'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install decisive
|
5
|
+
[![Build Status](https://travis-ci.org/botandrose/decisive.svg?branch=master)](https://travis-ci.org/botandrose/decisive)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/botandrose/decisive/badges/gpa.svg)](https://codeclimate.com/github/botandrose/decisive)
|
20
7
|
|
21
8
|
## Usage
|
22
9
|
|
@@ -35,28 +22,24 @@ end
|
|
35
22
|
```ruby
|
36
23
|
# app/views/users/index.csv.decisive
|
37
24
|
|
38
|
-
csv @users, filename: "users-#{Time.zone.now.strftime("%Y_%m_%d")}.csv" do
|
39
|
-
column :email
|
40
|
-
column
|
41
|
-
column
|
42
|
-
user.created_at.to_date
|
43
|
-
end
|
25
|
+
csv @users, filename: "users-#{Time.zone.now.strftime("%Y_%m_%d")}.csv" do |user|
|
26
|
+
column "Email" # omitted accessor field gets inferred: user.email
|
27
|
+
column "Full name", :name # explicit accessor field: user.name
|
28
|
+
column "Signed up", user.created_at.to_date # other values get passed straight through
|
44
29
|
end
|
45
30
|
```
|
46
31
|
|
47
32
|
Then visit /users.csv to get file named "users-2010_01_01.csv" with the following contents:
|
48
|
-
|
49
|
-
Email
|
50
|
-
|
51
|
-
|
52
|
-
|
33
|
+
|
34
|
+
| Email | Full name | Signed up |
|
35
|
+
| ----------------- | -------------- | ---------- |
|
36
|
+
| frodo@example.com | Frodo Baggins | 2002-06-19 |
|
37
|
+
| sam@example.com | Samwise Gamgee | 2008-10-13 |
|
53
38
|
|
54
39
|
## Development
|
55
40
|
|
56
41
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
57
42
|
|
58
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
59
|
-
|
60
43
|
## Contributing
|
61
44
|
|
62
45
|
Bug reports and pull requests are welcome on GitHub at https://github.com/botandrose/decisive.
|
data/decisive.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
|
26
26
|
spec.add_dependency "actionview"
|
27
27
|
|
28
|
-
spec.add_development_dependency "bundler"
|
29
|
-
spec.add_development_dependency "rake"
|
28
|
+
spec.add_development_dependency "bundler"
|
29
|
+
spec.add_development_dependency "rake"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.0"
|
31
31
|
end
|
@@ -20,44 +20,58 @@ module Decisive
|
|
20
20
|
|
21
21
|
module DSL
|
22
22
|
def csv records, filename:, &block
|
23
|
-
Context.new(
|
24
|
-
context.instance_eval &block
|
25
|
-
end
|
23
|
+
Context.new(records, filename, block)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
class Context < Struct.new(:
|
30
|
-
class Column < Struct.new(:field, :label, :block); end
|
31
|
-
|
32
|
-
def column field, label: field.to_s.humanize, &block
|
33
|
-
block ||= ->(record) { record.send(field) }
|
34
|
-
columns << Column.new(field, label, block)
|
35
|
-
end
|
36
|
-
|
27
|
+
class Context < Struct.new(:records, :filename, :block)
|
37
28
|
def to_csv
|
38
|
-
|
39
|
-
.map { |rows| rows.map(&:to_s) }
|
40
|
-
.map(&:to_csv)
|
41
|
-
.join
|
29
|
+
(header + body).map(&:to_csv).join
|
42
30
|
end
|
43
31
|
|
44
32
|
private
|
45
33
|
|
46
|
-
def rows
|
47
|
-
[header] + body
|
48
|
-
end
|
49
|
-
|
50
34
|
def header
|
51
|
-
|
35
|
+
[keys]
|
52
36
|
end
|
53
37
|
|
54
38
|
def body
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
39
|
+
hashes.map do |hash|
|
40
|
+
hash.values_at(*keys)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def keys
|
45
|
+
@keys ||= hashes.flat_map(&:keys).uniq
|
46
|
+
end
|
47
|
+
|
48
|
+
def hashes
|
49
|
+
@hashes ||= records.map do |record|
|
50
|
+
Row.new(record, block).to_hash
|
59
51
|
end
|
60
52
|
end
|
61
53
|
end
|
54
|
+
|
55
|
+
class Row < Struct.new(:record, :block)
|
56
|
+
def to_hash
|
57
|
+
@hash = {}
|
58
|
+
instance_exec record, &block
|
59
|
+
@hash
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def column key, value=nil, &block
|
65
|
+
@hash[key] = if block_given?
|
66
|
+
block.call(record)
|
67
|
+
elsif value.is_a?(Symbol)
|
68
|
+
record.send(value)
|
69
|
+
elsif value.nil?
|
70
|
+
record.send(key.parameterize.underscore.to_sym)
|
71
|
+
else
|
72
|
+
value
|
73
|
+
end.to_s
|
74
|
+
end
|
75
|
+
end
|
62
76
|
end
|
63
77
|
|
data/lib/decisive/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decisive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micah Geisel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionview
|
@@ -28,30 +28,30 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|