table_view 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
+ SHA256:
3
+ metadata.gz: 476e9d19235a9aa447fd2ef34c4674ea8973ab28f0a060f234ad995f9cd44b78
4
+ data.tar.gz: ba50dcdee078e4430a3bf79054430203c82b829754a94fe1c099a56d5b59fce5
5
+ SHA512:
6
+ metadata.gz: 611592ed47d624624ee67598836a7a89dca3de47e5e7abea507c5c192bb2e57c44730658fdde80b3f96e6928c9484f781fda20a10222816382b7ddf141484d18
7
+ data.tar.gz: fe40a86cc404326c3925ea6b3fcedca89dd6ce7686cdfa15909fbaa35bc624a777499f09169abf7aa72f8cd43225eefecec2fdbe51c7047fee817b74776ebfd0
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,68 @@
1
+ ---
2
+ AllCops:
3
+ Exclude:
4
+ - bin/**/*
5
+ - node_modules/**/*
6
+ - vendor/**/*
7
+ - ".git/**/*"
8
+
9
+ Layout/AlignParameters:
10
+ EnforcedStyle: with_fixed_indentation
11
+
12
+ Layout/ClassStructure:
13
+ Enabled: true
14
+
15
+ Layout/EndAlignment:
16
+ AutoCorrect: true
17
+
18
+ Layout/IndentationConsistency:
19
+ EnforcedStyle: normal
20
+
21
+ Lint/AmbiguousBlockAssociation:
22
+ Exclude:
23
+ - spec/**/*
24
+
25
+ Lint/EmptyWhen:
26
+ Enabled: false
27
+
28
+ Metrics/BlockLength:
29
+ CountComments: false
30
+ Max: 25
31
+ ExcludedMethods:
32
+ - context
33
+ - describe
34
+ - namespace
35
+ - shared_examples_for
36
+ - shared_examples
37
+ - pending
38
+ - shared_context
39
+ - it
40
+ - specify
41
+ Exclude:
42
+ - spec/factories/**/*
43
+
44
+ Metrics/LineLength:
45
+ Enabled: false
46
+
47
+ Style/BlockDelimiters:
48
+ EnforcedStyle: braces_for_chaining
49
+
50
+ Style/ClassAndModuleChildren:
51
+ AutoCorrect: true
52
+
53
+ Style/Documentation:
54
+ Enabled: false
55
+
56
+ Style/GlobalVars:
57
+ AllowedVariables:
58
+ - "$redis"
59
+
60
+ Style/StringLiterals:
61
+ EnforcedStyle: double_quotes
62
+
63
+ Style/TernaryParentheses:
64
+ EnforcedStyle: require_parentheses_when_complex
65
+
66
+ Style/UnneededPercentQ:
67
+ Exclude:
68
+ - '*.gemspec'
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 1.16.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ NB: it's so early in the project not yet using it. But we will ...
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tim@red56.uk. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in table_view.gemspec
8
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tim Diggins
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,107 @@
1
+ # TableView
2
+
3
+ Writing this before I'm writing code. Likely to progress very slowly in this vision.
4
+
5
+ The aim of this project is to create a way of describing tabular data to be viewed in various ways, primarily from a rails project (so it might be an engine, but it might just require rails).
6
+
7
+ The word `View` is probably a bit confusing given the rails context. Yes it might be a rails view, but it also might not. The aim here isn't to produce something that only outputs as the result of a a controller action, but rather something can output as the result of a controller action, but could also asynchronously produce a result - after a while. But these should be just as easy to generate from a script / console as from a web request. However, this is a view of some data, and typically (though not exclusively I guess) your models.
8
+
9
+ The aim is to be able to describe something that might have:
10
+
11
+ * synchronous (for immediate output/display/download) or asychronous (converting seamlessly to an ActiveJob) modes.
12
+ * paginated (page=2) or not (get me everything)
13
+ * ordering may be specified (and yet there's a way to run this without using all the memory in the world. This is fun in a rails context: find_each is not possible)
14
+ * output format: could be csv, could be json, could be html, could be xls, could be (how?) a googlesheet, could be an array (particularly useful for scripts, and for unforseen usages)
15
+ * personalization somehow (I'm not interested in some of these columns, don't show me)
16
+ * access control somehow (I'm not allowed to see some of these columns, don't show me)
17
+
18
+ And the notion of "View" still stands: how do you select your ordering? your output format? We don't know and don't care -- that's the job of your controller (in the widest possible sense) to sort out. it's just part of the API.
19
+
20
+ ## Installation
21
+
22
+ Add this line to your application's Gemfile:
23
+
24
+ ```ruby
25
+ gem 'table_view'
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install table_view
35
+
36
+ ## Usage
37
+
38
+
39
+ ### Possible now
40
+
41
+ #### 1. Define your TableView (e.g. at app/table_views/my_table_view)
42
+
43
+ ```ruby
44
+ class MyTableView < TableView::Base
45
+ # likely to change a lot
46
+ def initialize(somethings)
47
+ @somethings = somethings
48
+ end
49
+
50
+ # headers must be ruby identifiers -- lower_snake_case
51
+ def headers
52
+ %w[one two three]
53
+ end
54
+
55
+ def each_row
56
+ @somethings.each do |something|
57
+ yield [
58
+ @something.one,
59
+ @something.two,
60
+ @something.three
61
+ ]
62
+ end
63
+ end
64
+ end
65
+ ```
66
+
67
+ #### 2. Use your table view
68
+
69
+ ```ruby
70
+ mtv = MyTableView.new(Something.some_scope) # probably will need to change to new(:some_scope) to allow for activejob
71
+ mtv.write_csv(filename)
72
+ mtv.as_csv # => string
73
+ mtv.as_array # => array of arrays
74
+ ```
75
+
76
+ ### Possible in the future
77
+
78
+ TODO: need to sketch how will work in the future
79
+
80
+ * a dsl to specify fields -- to_s for headers, send for each_row
81
+ * a mechanism to specify initialization to work for async (to_global_id, or serialize/marshall)
82
+ * a mechanism to specify pagination, ordering
83
+
84
+ ```ruby
85
+ mtv = MyTableView.new(Something.some_scope) # probably will need to change to new(:some_scope) to allow for activejob
86
+ mtv.output(defined_output).perform_later # ? creates ActiveJob and performs it later, how is the output defined?
87
+ mtv.as_json
88
+ mtv.as_html # will need some definition of formatting/wrapping for row e.g `def format_row(ary)` or better a partial (which is given hash (row data by headers))
89
+ ```
90
+
91
+ ## Development
92
+
93
+ 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.
94
+
95
+ 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).
96
+
97
+ ## Contributing
98
+
99
+ Bug reports and pull requests are welcome on GitHub at https://github.com/timdiggins/table_view. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/timdiggins/table_view/blob/master/CODE_OF_CONDUCT.md).
100
+
101
+ ## License
102
+
103
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
104
+
105
+ ## Code of Conduct
106
+
107
+ Everyone interacting in the TableView project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/timdiggins/table_view/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "table_view"
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
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "csv"
4
+
5
+ module TableView
6
+ class Base
7
+ def as_array
8
+ array = []
9
+ array << headers
10
+ each_row do |row|
11
+ array << row
12
+ end
13
+ array
14
+ end
15
+
16
+ def write_csv(io)
17
+ csv = CSV.new(io)
18
+ csv << headers
19
+ each_row do |row|
20
+ csv << row
21
+ end
22
+ csv.close
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module TableView
4
+ VERSION = "0.1.0"
5
+ end
data/lib/table_view.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "table_view/version"
4
+ require "table_view/base"
5
+
6
+ module TableView
7
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "table_view/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "table_view"
9
+ spec.version = TableView::VERSION
10
+ spec.authors = ["Tim Diggins"]
11
+ spec.email = ["tim@red56.uk"]
12
+
13
+ spec.summary = %q(A wrapper to allow tabular data to be returned in various output formats)
14
+ spec.description = %q(
15
+ TableView provides easy tools
16
+ )
17
+ spec.homepage = "https://github.com/timdiggins/table_view"
18
+ spec.license = "MIT"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "rubocop", "0.68.1"
33
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: table_view
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tim Diggins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.68.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.68.1
69
+ description: "\n TableView provides easy tools\n "
70
+ email:
71
+ - tim@red56.uk
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".travis.yml"
80
+ - CHANGELOG.md
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/table_view.rb
89
+ - lib/table_view/base.rb
90
+ - lib/table_view/version.rb
91
+ - table_view.gemspec
92
+ homepage: https://github.com/timdiggins/table_view
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.7.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: A wrapper to allow tabular data to be returned in various output formats
116
+ test_files: []