attribute-stats 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 02a8733b9a9fee7f8391d8855ee3d1a9106f1196
4
- data.tar.gz: 2b07627c92d58fa5ac459ed1fbb8ab27493d1390
3
+ metadata.gz: 7c859c509e53910fa8ae29b43e7c34843a9da02f
4
+ data.tar.gz: 6355de45fcd0dea7370e39665d801b5a8bf79983
5
5
  SHA512:
6
- metadata.gz: bcdfba6645eea57014decabf2e8ba5ee935cf6fa3285c545622a59b8e2c13c87512b628824d551b0be8bfc7f95e3fa113043facc720025084371f2a9676bdac0
7
- data.tar.gz: f6f439d0aeac841c04846708bdd90a40550afeda98710a1d497f8f5a0ce9968f27a3f304c8ef24e8d15dd39647a9b45a2c51251322bee2459c7290a28ac280cb
6
+ metadata.gz: e97db1b7cf0a71d90f095e9922f4e1f1d0d801738e331f3f3c052fe5a44d118ca59521138d339b7bc203efcc9808fac1b0af39e50ee26dd4f7c0c78cb62dab7c
7
+ data.tar.gz: 0774b4ac6d48cfadeec8b8a807f06a87b462b16296967976a00bdaa607080f7dc9ad0589006bdcdfed59b854afd3fc0576cf43ffd8bd45f43c8ea6b10db422a0
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  Attribute Stats gives you insight into which persisted attributes are actually used in your Rails models. Whether you're joining an existing project or have been using it for years, get a quick look at the landscape of the database.
2
2
 
3
3
  It helps you find smells in your project:
4
- - Attributes which have never had data set (indicates a potentially forgotten attribute)
5
- - Tables which haven't been updated for X years (indicates a potentially unused or legacy model)
6
- - Attributes used by very few objects in your table (is this being used? Should it be an attribute?)
7
- - Attributes which are all set to the default value (if they're all default, is this really being used?)
4
+ - **Attributes are completely empty in the database** (smells like a potentially unused attribute)
5
+ - **Tables which haven't been updated for X years** (smells like a potentially unused or legacy model)
6
+ - **Attributes used by very few objects in your table** (smells like something that maybe shouldn't be an attribute)
7
+ - **Attributes which are all set to the default value** (if they're all default, is this really being used?)
8
8
 
9
9
  ## Installation
10
10
 
@@ -12,8 +12,6 @@ It helps you find smells in your project:
12
12
 
13
13
  Add `gem 'attribute-stats'` to your Gemfile, bundle, and follow the Usage instructions below.
14
14
 
15
- View [attribute-stats on RubyGems](https://rubygems.org/gems/attribute-stats) for more info, or just read the [gemspec](attribute-stats.gemspec).
16
-
17
15
  ## Usage
18
16
 
19
17
  ### Programmatic
@@ -22,11 +20,11 @@ You can use `AttributeStats` from within Rails (or a Rails console):
22
20
 
23
21
  irb:1> stats = AttributeStats::StatsGenerator.new()
24
22
  irb:2> stats.attribute_usage
25
- => # a list of your attributes and what % of records have a value set
23
+ => {...} # a list of your attributes and what % of records have a value set
26
24
  irb:3> stats.unused_attributes
27
- => # a list of your attributes which have no value set in the database
25
+ => {...} # a list of your attributes which have no value set in the database
28
26
  irb:4> stats.dormant_tables
29
- => # a list of your tables which have not been updated in awhile
27
+ => [...] # a list of your tables which have not been updated in awhile
30
28
  irb:5> stats.migration
31
29
  => # sample migration up/down to remove your unused attributes
32
30
  irb:6> stats.set_formatter :json
@@ -94,7 +92,6 @@ Generates a sample migration syntax to remove all unused attributes. (This is ju
94
92
  The gem does not support:
95
93
 
96
94
  1. Detection of unset encrypted attributes. `attribute-stats` works by searching for empty values using SQL. If you are encrypting data before storing it in the database, a value of `nil` might have a value in the database which, decrypted, equals `nil`.
97
- 1. Custom table names. If you are defining a model called House, and configure the model to use the table 'domiciles' instead of 'houses', `attribute-stats` skips analysis of the table. *(TODO: fix)*
98
95
  1. Tables not associated with a model. If your database has tables which do not correspond with a model (see point #2), `attribute-stats` skips analysis of that table. *(TODO: fix)*
99
96
 
100
97
  ## Compatability
@@ -117,6 +114,6 @@ Or, you can run tests for all supported Rails versions and supported databases:
117
114
  1. `bundle exec appraisal install` *(this Generates gemfiles for all permutations of our dependencies, so you'll see lots of bundler output))*
118
115
  1. `bundle exec appraisal rspec`. *(This runs rspec for each dependency permutation. If one fails, appraisal exits immediately and does not test permutations it hasn't gotten to yet. Tests are not considered passing until all 12 permutations are passing)*
119
116
 
120
- If you only want to test a certain dependency set, such as Rails 5.2 for MySQL: `bundle exec appraisals rails-5-2-mysql`. In this case, you would *not* need to configure postgresql in your database.yml, nor have postgres running on your machine.
117
+ If you only want to test a certain dependency set, such as Rails 5.2 for MySQL: `bundle exec appraisals rails-5-2-mysql rspec`. In this case, you would *not* need to configure postgresql in your database.yml, nor have postgres running on your machine.
121
118
 
122
119
  You can view all available dependency sets in [Appraisals](Appraisals)
@@ -0,0 +1,10 @@
1
+ require 'attribute-stats'
2
+ namespace :db do
3
+ namespace :stats do
4
+ desc "list all models"
5
+ task :list_models => :environment do
6
+ # puts Rails.application.eager_load!
7
+ puts ActiveRecord::Base.descendants.inspect
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module AttributeStats
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -116,7 +116,9 @@ module AttributeStats
116
116
  end
117
117
 
118
118
  def setup_table_and_model(table)
119
- @table_info << TableData.new(table.classify.constantize)
119
+ ar_class = ActiveRecord::Base.descendants.detect{|klass| klass.table_name == table }
120
+ return if ar_class.name == 'ActiveRecord::InternalMetadata' # Table for Rails 5 internal use only
121
+ @table_info << TableData.new(ar_class || table.classify.constantize)
120
122
  rescue NameError => ex
121
123
  end
122
124
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attribute-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Hodges
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-08 00:00:00.000000000 Z
11
+ date: 2018-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -134,6 +134,7 @@ files:
134
134
  - lib/attribute-stats/railtie.rb
135
135
  - lib/attribute-stats/tasks/attribute_usage.rake
136
136
  - lib/attribute-stats/tasks/dormant.rake
137
+ - lib/attribute-stats/tasks/list_models.rake
137
138
  - lib/attribute-stats/tasks/migration.rake
138
139
  - lib/attribute-stats/tasks/unused_attributes.rake
139
140
  - lib/attribute-stats/version.rb
@@ -160,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
161
  requirements:
161
162
  - - ">="
162
163
  - !ruby/object:Gem::Version
163
- version: 2.2.0
164
+ version: 2.0.0
164
165
  required_rubygems_version: !ruby/object:Gem::Requirement
165
166
  requirements:
166
167
  - - ">="