decisive 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3700264badd95fb4a4cece6399f68caf4f68258f
4
+ data.tar.gz: 5971eda2dfeb494f0990e4d96823926d4a0faafa
5
+ SHA512:
6
+ metadata.gz: ff8952f02b479c471a23015fdfd969217fcdb4690b4b979d4043698fbf431c64108dddc91af8bd2138af37ae5ebac8d35388e4ad57710274d32f2cbf239ed32c
7
+ data.tar.gz: 49702ed4d64bf5ef20c7d408d7a4f2ab56f2cedce256436c0747f8ac89028089826cad4dc60bc3701c78c0353ed52aa42d0f90d8be772d46b3a3806d9a79993d
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ decisive
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.4.3
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.2.0
7
+ before_install: gem install bundler -v 1.16.5
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in decisive.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ decisive (0.1.0)
5
+ actionview
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionview (5.2.1)
11
+ activesupport (= 5.2.1)
12
+ builder (~> 3.1)
13
+ erubi (~> 1.4)
14
+ rails-dom-testing (~> 2.0)
15
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
16
+ activesupport (5.2.1)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (>= 0.7, < 2)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ builder (3.2.3)
22
+ concurrent-ruby (1.0.5)
23
+ crass (1.0.4)
24
+ diff-lcs (1.3)
25
+ erubi (1.7.1)
26
+ i18n (1.1.0)
27
+ concurrent-ruby (~> 1.0)
28
+ loofah (2.2.2)
29
+ crass (~> 1.0.2)
30
+ nokogiri (>= 1.5.9)
31
+ mini_portile2 (2.3.0)
32
+ minitest (5.11.3)
33
+ nokogiri (1.8.4)
34
+ mini_portile2 (~> 2.3.0)
35
+ rails-dom-testing (2.0.3)
36
+ activesupport (>= 4.2.0)
37
+ nokogiri (>= 1.6)
38
+ rails-html-sanitizer (1.0.4)
39
+ loofah (~> 2.2, >= 2.2.2)
40
+ rake (10.5.0)
41
+ rspec (3.8.0)
42
+ rspec-core (~> 3.8.0)
43
+ rspec-expectations (~> 3.8.0)
44
+ rspec-mocks (~> 3.8.0)
45
+ rspec-core (3.8.0)
46
+ rspec-support (~> 3.8.0)
47
+ rspec-expectations (3.8.1)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.8.0)
50
+ rspec-mocks (3.8.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.8.0)
53
+ rspec-support (3.8.0)
54
+ thread_safe (0.3.6)
55
+ tzinfo (1.2.5)
56
+ thread_safe (~> 0.1)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 1.16)
63
+ decisive!
64
+ rake (~> 10.0)
65
+ rspec (~> 3.0)
66
+
67
+ BUNDLED WITH
68
+ 1.16.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Micah Geisel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Decisive
2
+
3
+ DSL for rendering CSVs
4
+
5
+ ## Installation
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
20
+
21
+ ## Usage
22
+
23
+ Example usage:
24
+
25
+ ```ruby
26
+ # app/controllers/users_controller.rb
27
+
28
+ class UsersController < ApplicationController
29
+ def index
30
+ @users = User.all
31
+ end
32
+ end
33
+ ```
34
+
35
+ ```ruby
36
+ # app/views/users/index.csv.decisive
37
+
38
+ @filename = "users-#{Time.zone.now.strftime("%Y_%m_%d")}.csv"
39
+ @records = @users
40
+
41
+ column :email
42
+ column :name, label: "Full name"
43
+ column :signed_up do |user|
44
+ user.created_at.to_date
45
+ end
46
+ ```
47
+
48
+ Then visit /users.csv to get file named "users-2010_01_01.csv" with the following contents:
49
+ ```csv
50
+ Email,Full name,Signed up
51
+ frodo@example.com,"Frodo Baggins",2010-01-01
52
+ sam@example.com,"Samwise Gamgee",2010-01-01
53
+ ```
54
+
55
+ ## Development
56
+
57
+ 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.
58
+
59
+ 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).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/botandrose/decisive.
64
+
65
+ ## License
66
+
67
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "decisive"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/decisive.gemspec ADDED
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "decisive/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "decisive"
8
+ spec.version = Decisive::VERSION
9
+ spec.authors = ["Micah Geisel"]
10
+ spec.email = ["micah@botandrose.com"]
11
+
12
+ spec.summary = %q{DSL for rendering CSVs}
13
+ spec.description = %q{DSL for rendering CSVs from an array of objects}
14
+ spec.homepage = "https://github.com/botandrose/decisive"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "actionview"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
@@ -0,0 +1,53 @@
1
+ require "csv"
2
+ require "action_view"
3
+ require "active_support/core_ext/string/inflections"
4
+
5
+ module Decisive
6
+ class TemplateHandler
7
+ def self.register
8
+ ActionView::Template.register_template_handler 'decisive', self
9
+ end
10
+
11
+ def self.call template
12
+ <<~RUBY
13
+ extend Decisive::DSL
14
+ #{template.source}
15
+ response.headers["Content-Disposition"] = %(attachment; filename="\#{@filename}")
16
+ rows
17
+ .map { |rows| rows.map(&:to_s) }
18
+ .map(&:to_csv)
19
+ .join
20
+ RUBY
21
+ end
22
+ end
23
+
24
+ module DSL
25
+ def self.extended object
26
+ object.instance_variable_set :@columns, []
27
+ end
28
+
29
+ class Column < Struct.new(:field, :label, :block); end
30
+
31
+ def column field, label: field.to_s.humanize, &block
32
+ block ||= ->(record) { record.send(field) }
33
+ @columns << Column.new(field, label, block)
34
+ end
35
+
36
+ def header
37
+ @columns.map(&:label)
38
+ end
39
+
40
+ def body
41
+ @records.map do |record|
42
+ @columns.map do |column|
43
+ column.block.call(record)
44
+ end
45
+ end
46
+ end
47
+
48
+ def rows
49
+ [header] + body
50
+ end
51
+ end
52
+ end
53
+
@@ -0,0 +1,3 @@
1
+ module Decisive
2
+ VERSION = "0.1.0"
3
+ end
data/lib/decisive.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "decisive/version"
2
+ require "decisive/template_handler"
3
+
4
+ module Decisive
5
+ class Rails < ::Rails::Engine
6
+ initializer "decisive.register_template_handler" do
7
+ TemplateHandler.register
8
+ end
9
+ end if defined?(Rails)
10
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decisive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Micah Geisel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: actionview
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: DSL for rendering CSVs from an array of objects
70
+ email:
71
+ - micah@botandrose.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".ruby-gemset"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - decisive.gemspec
89
+ - lib/decisive.rb
90
+ - lib/decisive/template_handler.rb
91
+ - lib/decisive/version.rb
92
+ homepage: https://github.com/botandrose/decisive
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.14
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: DSL for rendering CSVs
116
+ test_files: []