reportly 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a38a9e9dff8b088244834bc6735b82f3aa574a8
4
+ data.tar.gz: 4222d9fcd393396de4cc31f45c7a31d00dcd62e3
5
+ SHA512:
6
+ metadata.gz: 3838c24e4448f7a0ad4805d8bdf8377dc4293e88a004cbe0f15c947c503341d2cd29ae057e20f714425c4b3a16040d70730d75f698d321c5d7e9afd956da181d
7
+ data.tar.gz: 1c9ed0dcea838a1f64a629abda931fa5961322b585440c0f8510670a14dd80e0d6a86cade2088c601ea3fef979767110c4432da9bbe5e35ee70297cf71419965
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in reportly.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,12 @@
1
+ guard :rspec, cmd: "bundle exec rspec" do
2
+ # watch /lib/ files
3
+ watch(%r{^lib/(.+).rb$}) do |m|
4
+ "spec/#{m[1]}_spec.rb"
5
+ end
6
+
7
+ # watch /spec/ files
8
+ watch(%r{^spec/(.+).rb$}) do |m|
9
+ "spec/#{m[1]}.rb"
10
+ end
11
+ end
12
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ioannis Kolovos
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,119 @@
1
+ [![Build Status](https://travis-ci.org/msroot/reportly.svg?branch=master)](https://travis-ci.org/msroot/reportly)
2
+ [![Gem Version](https://badge.fury.io/rb/reportly.png)](http://badge.fury.io/rb/reportly)
3
+ [![Code Climate](https://codeclimate.com/github/msroot/reportly/badges/gpa.svg)](https://codeclimate.com/github/msroot/reportly)
4
+
5
+ # Reportly
6
+
7
+ Reports for Active Record results! No configurations needed
8
+
9
+ Creates a `:report` helper method and exposed to rails console
10
+
11
+ Accepts `ActiveRecord::Relation` and `ActiveRecord::Base` objects and generates a table
12
+
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'reportly'
20
+ ```
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it yourself as:
27
+
28
+ $ gem install reportly
29
+
30
+ ## Usage
31
+ From Rails console
32
+
33
+ report User
34
+ or
35
+
36
+ report Post.all
37
+
38
+ using ActiveRecord finders
39
+
40
+ report Admin.where(email: 'me@localhost.com'), :id
41
+
42
+ or use the `:r` alias
43
+
44
+ r Translation
45
+
46
+ or by selecting fields
47
+
48
+ r Query, :text
49
+
50
+ or by selecting fields on ActiveRecord objects
51
+
52
+ r Query.all.first(5), :text, :id
53
+
54
+ Will generate:
55
+
56
+ +------------------+--------------------------------------+
57
+ | text | id |
58
+ +------------------+--------------------------------------+
59
+ | Ansley Bechtelar | a673cec9-b1f2-4ec4-8104-a0dbfca23771 |
60
+ | Tevin Gerlach | 92f6c49f-4628-4dbd-9812-4b2094151ff6 |
61
+ | Vivien Langosh | c452e939-4858-4113-bc3a-9db77617b11e |
62
+ | Kadin Hahn | 4aed4438-434c-4761-a119-ba4a6aa3e1b6 |
63
+ | Brenda Huels | c28c9bd4-74a9-491b-9897-12380c2cb3c8 |
64
+ +------------------+--------------------------------------+
65
+
66
+ ## Motivation
67
+
68
+ Looking for a simple method to generate a simple report i found [this](https://gist.github.com/bgreenlee/72234)
69
+ and i decided to make it a gem
70
+
71
+ ## For RockStars only
72
+
73
+ <a href="http://www.youtube.com/watch?feature=player_embedded&v=sFZjqVnWBhc
74
+ " target="_blank"><img src="http://img.youtube.com/vi/sFZjqVnWBhc/0.jpg" width="240" height="180" border="10" /></a>
75
+
76
+
77
+ ## Todo
78
+
79
+ - Create a method `Model.report` to all active record objects
80
+
81
+ ## Testing
82
+
83
+ run `bundle` and `rake`
84
+
85
+ ## Authors
86
+
87
+ Yannis Kolovos [@yannis_kolovos](http://twitter.com/yannis_kolovos)
88
+
89
+
90
+ ## Contributing
91
+
92
+ 1. Fork it ( https://github.com/msroot/reportly/fork )
93
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
94
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
95
+ 4. Push to the branch (`git push origin my-new-feature`)
96
+ 5. Create a new Pull Request
97
+
98
+
99
+ ## License
100
+ MIT License Copyright (c) 2015 Yannis Kolovos
101
+
102
+ Permission is hereby granted, free of charge, to any person obtaining
103
+ a copy of this software and associated documentation files (the
104
+ "Software"), to deal in the Software without restriction, including
105
+ without limitation the rights to use, copy, modify, merge, publish,
106
+ distribute, sublicense, and/or sell copies of the Software, and to
107
+ permit persons to whom the Software is furnished to do so, subject to
108
+ the following conditions:
109
+
110
+ The above copyright notice and this permission notice shall be
111
+ included in all copies or substantial portions of the Software.
112
+
113
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
114
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
115
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
116
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
117
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
118
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
119
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ require 'bundler/gem_tasks'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |task|
6
+ end
7
+
8
+ task :default => :spec
9
+
data/lib/reportly.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "reportly/version"
2
+ require "reportly/console_methods"
3
+
4
+ module Rails
5
+ module ConsoleMethods
6
+ # Creates a +:report+ method helper exposed to rails console
7
+ #
8
+ # Accepts <tt>ActiveRecord::Relation</tt> and <tt>ActiveRecord::Base</tt> objects
9
+ # and generated a table
10
+ #
11
+ #Example:
12
+ # report User
13
+ # or
14
+ # report Post.all
15
+ # Note <tt>:r</tt> its the alias method for <tt>:report</tt>
16
+ #
17
+ # Usage:
18
+ # report(records) # displays report with all fields
19
+ # report(records, :field1, :field2, ...) # displays report with given fields
20
+ #
21
+ # ==== Options
22
+ # * <tt>items</tt> - The ActiveRecord objects
23
+ # * <tt>fields</tt> - Filter only the given fields
24
+
25
+ def report(model, *fields)
26
+ Reportly::ConsoleMethods.report(model, *fields)
27
+ end
28
+
29
+ alias_method :r, :report
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ require "reportly/engine"
2
+
3
+ module Reportly
4
+ module ConsoleMethods
5
+
6
+ class ReportlyNotValid < StandardError; end
7
+
8
+ def self.report(model, *fields)
9
+
10
+ raise ReportlyNotValid, "Reportly accepts only ActiveRecord Objects" unless is_valid_klass?(model)
11
+
12
+ # call :all for ActiveRecord::Base model
13
+ model = model.send(:all) unless model.is_a?(Array)
14
+
15
+ # create a new array if its a single record
16
+ model = [model] unless model.respond_to? :each
17
+
18
+ Reportly::Engine.report(model, *fields)
19
+ end
20
+
21
+
22
+ def self.is_valid_klass?(klass)
23
+ klass.descends_from_active_record? rescue false or klass.is_a?(Array)
24
+ end
25
+
26
+ end
27
+ end
28
+
@@ -0,0 +1,31 @@
1
+ module Reportly
2
+ module Engine
3
+ # Original code https://gist.github.com/bgreenlee/72234
4
+ def self.report(items, *fields)
5
+ # find max length for each field; start with the field names themselves
6
+ fields = items.first.class.column_names unless fields.any?
7
+ max_len = Hash[*fields.map {|f| [f, f.to_s.length]}.flatten]
8
+ items.each do |item|
9
+ fields.each do |field|
10
+ len = item.read_attribute(field).to_s.length
11
+ max_len[field] = len if len > max_len[field]
12
+ end
13
+ end
14
+
15
+ border = '+-' + fields.map {|f| '-' * max_len[f] }.join('-+-') + '-+'
16
+ title_row = '| ' + fields.map {|f| sprintf("%-#{max_len[f]}s", f.to_s) }.join(' | ') + ' |'
17
+
18
+ puts border
19
+ puts title_row
20
+ puts border
21
+
22
+ items.each do |item|
23
+ row = '| ' + fields.map {|f| sprintf("%-#{max_len[f]}s", item.read_attribute(f)) }.join(' | ') + ' |'
24
+ puts row
25
+ end
26
+
27
+ puts border
28
+ puts "#{items.length} rows in set\n"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Reportly
2
+ VERSION = "0.0.1"
3
+ end
data/reportly.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reportly/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reportly"
8
+ spec.version = Reportly::VERSION
9
+ spec.authors = ["Yannis Kolovos"]
10
+ spec.email = ["yannis.kolovos@gmail.com"]
11
+ spec.summary = "Reports for Active record objects"
12
+ spec.description = "Generates tables from Active record objects"
13
+ spec.homepage = "http://johnkolovos.blogspot.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2.0"
24
+ spec.add_development_dependency "guard", "~> 2.12.5"
25
+ spec.add_development_dependency "guard-rspec", "~> 4.5.0"
26
+ spec.add_development_dependency "sqlite3", "~> 1.3.10"
27
+
28
+ spec.add_runtime_dependency "rails", "~> 4.1.8"
29
+
30
+ end
@@ -0,0 +1,93 @@
1
+ require 'spec_helper'
2
+ require 'active_record'
3
+ require 'rails/console/helpers'
4
+
5
+ NAMESPACE = Reportly::ConsoleMethods
6
+
7
+ def run_migrations!
8
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
9
+
10
+ m = ActiveRecord::Migration.new
11
+ m.verbose = false
12
+ m.create_table :users do |t|
13
+ t.string :name
14
+ end
15
+
16
+ end
17
+
18
+
19
+ def create_user_class
20
+ run_migrations!
21
+ user = Class.new(ActiveRecord::Base)
22
+ user.table_name = :users
23
+ 2.times {user.create}
24
+ user
25
+ end
26
+
27
+
28
+
29
+ describe Reportly do
30
+
31
+ let(:irb_context) {Object.new.extend(Rails::ConsoleMethods)}
32
+ let(:users) {create_user_class}
33
+ let(:user) {
34
+ user = Class.new(ActiveRecord::Base)
35
+ user.table_name = :users
36
+ user
37
+ }
38
+
39
+
40
+ it 'respond to report' do
41
+ expect(irb_context).to respond_to(:report)
42
+ expect(irb_context).to respond_to(:r)
43
+ end
44
+
45
+ it 'raise error for not active recods' do
46
+ [Class, Hash, Object].each do |o|
47
+ expect{irb_context.report o.new}.to raise_error(NAMESPACE::ReportlyNotValid)
48
+ end
49
+ end
50
+
51
+ it 'not raise error' do
52
+ expect{irb_context.report users.all}.to_not raise_error
53
+ end
54
+
55
+ it 'not raise error on class' do
56
+ expect{irb_context.report users}.to_not raise_error
57
+ expect{irb_context.report user}.to_not raise_error
58
+ end
59
+
60
+ it 'should call :all' do
61
+ expect(irb_context.report users).to equal(irb_context.report users.all)
62
+ end
63
+
64
+ it 'accepting active record array ' do
65
+ expect{irb_context.report users.all.first(2)}.to_not raise_error
66
+ end
67
+
68
+ it 'accepting active record array ' do
69
+ expect{irb_context.report users.where(id: 1)}.to_not raise_error
70
+ end
71
+
72
+
73
+ it 'passing fields ' do
74
+ expect{irb_context.report users, :id, :name}.to_not raise_error
75
+ end
76
+
77
+
78
+ describe "Validations" do
79
+
80
+ it 'should be valid ' do
81
+ [users, users.all, users.all.first(2)].each do |valid|
82
+ expect(NAMESPACE.is_valid_klass?(valid)).to be true
83
+ end
84
+ end
85
+
86
+ it 'should not be valid ' do
87
+ [Hash.new, Class.new].each do |valid|
88
+ expect(NAMESPACE.is_valid_klass?(valid)).to be false
89
+ end
90
+ end
91
+
92
+ end
93
+ end
@@ -0,0 +1,13 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'rails'
5
+ require 'reportly'
6
+
7
+ def make_basic_app
8
+ @app = Class.new(Rails::Application)
9
+ @app.config.secret_token = "3b7cd727ee24e8444053437c36cc66c4"
10
+ @app.config.session_store :cookie_store, :key => "_myapp_session"
11
+ @app.config.active_support.deprecation = :log
12
+ @app.initialize!
13
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reportly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yannis Kolovos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-24 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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.2.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.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.12.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 4.5.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 4.5.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.3.10
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.3.10
97
+ - !ruby/object:Gem::Dependency
98
+ name: rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 4.1.8
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 4.1.8
111
+ description: Generates tables from Active record objects
112
+ email:
113
+ - yannis.kolovos@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - Guardfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - lib/reportly.rb
126
+ - lib/reportly/console_methods.rb
127
+ - lib/reportly/engine.rb
128
+ - lib/reportly/version.rb
129
+ - reportly.gemspec
130
+ - spec/reportly_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage: http://johnkolovos.blogspot.com
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.2.2
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Reports for Active record objects
156
+ test_files:
157
+ - spec/reportly_spec.rb
158
+ - spec/spec_helper.rb