reportly 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/reportly/console_methods.rb +41 -14
- data/lib/reportly/engine.rb +9 -6
- data/lib/reportly/version.rb +1 -1
- data/reportly.gemspec +1 -1
- data/spec/reportly_spec.rb +82 -25
- data/spec/spec_helper.rb +3 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52638256deac9c21a8f89abf855aa334d0d77b6e
|
4
|
+
data.tar.gz: e6fc77eaa0f6f4402186090774059239df2dafc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bed6e03bc4d694192d742f0bcdcbf2aa8b77d9a3761f43b4ba1658ec42ebf31702c4e2ec648c8d2d24186b467d8a3feb38101c23509913863d511b478100775
|
7
|
+
data.tar.gz: 3c44aea856d38cba204ce888f1c5dab6cda3c925f53d93dca567e4797e4933135942628fc87caa98b59a59298903dd92a1a2cda8a7c980328a6e04e888f34192
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
[![Build Status](https://travis-ci.org/msroot/reportly.svg?branch=master)](https://travis-ci.org/msroot/reportly)
|
2
1
|
[![Gem Version](https://badge.fury.io/rb/reportly.png)](http://badge.fury.io/rb/reportly)
|
2
|
+
[![Build Status](https://travis-ci.org/msroot/reportly.svg?branch=master)](https://travis-ci.org/msroot/reportly)
|
3
3
|
[![Code Climate](https://codeclimate.com/github/msroot/reportly/badges/gpa.svg)](https://codeclimate.com/github/msroot/reportly)
|
4
|
-
|
4
|
+
[![Inline docs](http://inch-ci.org/github/msroot/reportly.svg?branch=master)](http://inch-ci.org/github/msroot/reportly)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/msroot/reportly/badge.svg?branch=master)](https://coveralls.io/r/msroot/reportly?branch=master)
|
5
6
|
# Reportly
|
6
7
|
|
7
8
|
Reports for Active Record results! No configurations needed
|
@@ -2,27 +2,54 @@ require "reportly/engine"
|
|
2
2
|
|
3
3
|
module Reportly
|
4
4
|
module ConsoleMethods
|
5
|
+
extend self
|
5
6
|
|
6
7
|
class ReportlyNotValid < StandardError; end
|
7
8
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
def report(model, *fields)
|
10
|
+
|
11
|
+
model = make_array_for(model)
|
12
|
+
|
13
|
+
validate(model)
|
14
|
+
report = Reportly::Engine.report(model, *fields)
|
15
|
+
@results = report
|
16
|
+
puts report.join("\n")
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
+
def results
|
20
|
+
@results
|
21
|
+
end
|
22
|
+
|
23
|
+
def make_array_for(model)
|
24
|
+
# report User.first
|
25
|
+
# 2.1.3 :003 > User.first.class
|
26
|
+
# => User(id: uuid, partner_id: uuid, created_at: datetime, updated_at: datetime)
|
27
|
+
model = [model] if model.class.superclass == ActiveRecord::Base
|
28
|
+
# report User
|
29
|
+
# 2.1.3 :004 > User.class
|
30
|
+
# => Class
|
31
|
+
model = model.send(:all) if model.class.name == 'Class' and model.respond_to? :all
|
32
|
+
|
33
|
+
# User.all.first(2) and User.where(name: 'yannis') are kind of arrays and respond to :each
|
34
|
+
|
35
|
+
# 2.1.3 :006 > User.first(2).class
|
36
|
+
# => Array
|
37
|
+
|
38
|
+
# 2.1.3 :013 > User.all.class
|
39
|
+
# => User::ActiveRecord_Relation
|
40
|
+
model
|
41
|
+
|
19
42
|
end
|
20
43
|
|
44
|
+
def validate(model)
|
45
|
+
raise ReportlyNotValid, "Reportly accepts only ActiveRecord Objects" unless is_valid_klass?(model)
|
46
|
+
end
|
21
47
|
|
22
|
-
|
23
|
-
|
48
|
+
# accepts Array or a ActiveRecord_Relation
|
49
|
+
# Should respond_to? :each and be descend from active record
|
50
|
+
def is_valid_klass?(model)
|
51
|
+
model.first.class.descends_from_active_record? rescue false and model.respond_to? :each
|
24
52
|
end
|
25
|
-
|
53
|
+
|
26
54
|
end
|
27
55
|
end
|
28
|
-
|
data/lib/reportly/engine.rb
CHANGED
@@ -12,20 +12,23 @@ module Reportly
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
report = []
|
16
|
+
|
15
17
|
border = '+-' + fields.map {|f| '-' * max_len[f] }.join('-+-') + '-+'
|
16
18
|
title_row = '| ' + fields.map {|f| sprintf("%-#{max_len[f]}s", f.to_s) }.join(' | ') + ' |'
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
report << border
|
21
|
+
report << title_row
|
22
|
+
report << border
|
21
23
|
|
22
24
|
items.each do |item|
|
23
25
|
row = '| ' + fields.map {|f| sprintf("%-#{max_len[f]}s", item.read_attribute(f)) }.join(' | ') + ' |'
|
24
|
-
|
26
|
+
report << row
|
25
27
|
end
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
+
report << border
|
30
|
+
report << "#{items.length} rows in set"
|
31
|
+
report
|
29
32
|
end
|
30
33
|
end
|
31
34
|
end
|
data/lib/reportly/version.rb
CHANGED
data/reportly.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "guard", "~> 2.12.5"
|
25
25
|
spec.add_development_dependency "guard-rspec", "~> 4.5.0"
|
26
26
|
spec.add_development_dependency "sqlite3", "~> 1.3.10"
|
27
|
-
|
27
|
+
spec.add_development_dependency "coveralls", "~> 0.7.11"
|
28
28
|
spec.add_runtime_dependency "rails", "~> 4.1.8"
|
29
29
|
|
30
30
|
end
|
data/spec/reportly_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'active_record'
|
3
3
|
require 'rails/console/helpers'
|
4
4
|
|
5
|
-
|
5
|
+
REPORTLY = Reportly::ConsoleMethods
|
6
6
|
|
7
7
|
def run_migrations!
|
8
8
|
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
@@ -16,12 +16,12 @@ def run_migrations!
|
|
16
16
|
end
|
17
17
|
|
18
18
|
|
19
|
-
def
|
19
|
+
def create_users_class
|
20
20
|
run_migrations!
|
21
21
|
user = Class.new(ActiveRecord::Base)
|
22
22
|
user.table_name = :users
|
23
23
|
2.times {user.create}
|
24
|
-
user
|
24
|
+
user.all
|
25
25
|
end
|
26
26
|
|
27
27
|
|
@@ -29,7 +29,8 @@ end
|
|
29
29
|
describe Reportly do
|
30
30
|
|
31
31
|
let(:irb_context) {Object.new.extend(Rails::ConsoleMethods)}
|
32
|
-
let(:users) {
|
32
|
+
let(:users) {create_users_class}
|
33
|
+
|
33
34
|
let(:user) {
|
34
35
|
user = Class.new(ActiveRecord::Base)
|
35
36
|
user.table_name = :users
|
@@ -43,26 +44,22 @@ describe Reportly do
|
|
43
44
|
end
|
44
45
|
|
45
46
|
it 'raise error for not active recods' do
|
46
|
-
[
|
47
|
-
expect{irb_context.report o.new}.to raise_error(
|
47
|
+
[Hash, Object].each do |o|
|
48
|
+
expect{irb_context.report o.new}.to raise_error(REPORTLY::ReportlyNotValid)
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
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
|
52
|
+
it 'not raise error on users' do
|
56
53
|
expect{irb_context.report users}.to_not raise_error
|
57
|
-
expect{irb_context.report user}.to_not raise_error
|
58
54
|
end
|
59
55
|
|
60
|
-
it '
|
61
|
-
expect
|
56
|
+
it 'not raise error on user class' do
|
57
|
+
expect{irb_context.report user}.to_not raise_error
|
62
58
|
end
|
63
59
|
|
60
|
+
|
64
61
|
it 'accepting active record array ' do
|
65
|
-
expect{irb_context.report users.
|
62
|
+
expect{irb_context.report users.first(2)}.to_not raise_error
|
66
63
|
end
|
67
64
|
|
68
65
|
it 'accepting active record array ' do
|
@@ -73,21 +70,81 @@ describe Reportly do
|
|
73
70
|
it 'passing fields ' do
|
74
71
|
expect{irb_context.report users, :id, :name}.to_not raise_error
|
75
72
|
end
|
73
|
+
|
74
|
+
it 'respond to each' do
|
75
|
+
[user, users, users.first(2), users.first].each do |valid|
|
76
|
+
expect(REPORTLY.make_array_for(valid).respond_to?(:each)).to be true
|
77
|
+
end
|
78
|
+
end
|
76
79
|
|
77
80
|
|
78
|
-
|
81
|
+
it 'should be valid ' do
|
82
|
+
[user, users, users.first(2), users.first].each do |valid|
|
79
83
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
end
|
84
|
+
model = REPORTLY.make_array_for(valid)
|
85
|
+
|
86
|
+
expect(REPORTLY.is_valid_klass?(model)).to be true
|
84
87
|
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should not raise in validation ' do
|
91
|
+
expect(REPORTLY.is_valid_klass?(nil)).to be false
|
92
|
+
expect{REPORTLY.is_valid_klass?(nil)}.to_not raise_error
|
93
|
+
end
|
94
|
+
|
95
|
+
|
85
96
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
97
|
+
it 'should not be valid ' do
|
98
|
+
[String, Set, Hash, Class, Array].each do |klass|
|
99
|
+
expect(REPORTLY.is_valid_klass?(klass.new)).to be false
|
100
|
+
expect{REPORTLY.is_valid_klass?(klass.new)}.to_not raise_error
|
90
101
|
end
|
91
|
-
|
102
|
+
|
103
|
+
["", [], {}].each do |klass|
|
104
|
+
expect(REPORTLY.is_valid_klass?(klass)).to be false
|
105
|
+
expect{REPORTLY.is_valid_klass?(klass)}.to_not raise_error
|
106
|
+
end
|
107
|
+
|
92
108
|
end
|
109
|
+
|
110
|
+
|
111
|
+
let(:users_table) {
|
112
|
+
t = []
|
113
|
+
t << "+----+------+"
|
114
|
+
t << "| id | name |"
|
115
|
+
t << "+----+------+"
|
116
|
+
t << "| 1 | |"
|
117
|
+
t << "| 2 | |"
|
118
|
+
t << "+----+------+"
|
119
|
+
t << "2 rows in set"
|
120
|
+
t
|
121
|
+
}
|
122
|
+
|
123
|
+
let(:user_table) {
|
124
|
+
t = []
|
125
|
+
t << "+----+"
|
126
|
+
t << "| id |"
|
127
|
+
t << "+----+"
|
128
|
+
t << "| 1 |"
|
129
|
+
t << "+----+"
|
130
|
+
t << "1 rows in set"
|
131
|
+
t
|
132
|
+
}
|
133
|
+
|
134
|
+
# Not thread safe
|
135
|
+
it 'all table' do
|
136
|
+
irb_context.report(users)
|
137
|
+
expect(REPORTLY.results).to eq(users_table)
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'using first' do
|
141
|
+
irb_context.report(users.first, :id)
|
142
|
+
expect(REPORTLY.results).to eq(user_table)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'using find' do
|
146
|
+
irb_context.report(users.find(1), :id)
|
147
|
+
expect(REPORTLY.results).to eq(user_table)
|
148
|
+
end
|
149
|
+
|
93
150
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reportly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yannis Kolovos
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.3.10
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.7.11
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.7.11
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rails
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|