pry-rails 0.3.1 → 0.3.2

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NDU0YWU5MTYxNTVmOWQwNGI5YmI3MzdjYmVhYzgyMDM1NzA4Mzc3NA==
5
- data.tar.gz: !binary |-
6
- YjJhMmIzNDFjZTkzNWMzNTMwNzNjMzAwZDQ0ZjkzOTA2YWEzYzdhZQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NTQzODNkMzFhMjUwZTJiMTk1Nzk3MDJiMjRlNzM3MWI3ODM3YTVlZDUzODNi
10
- ZTc1NTExOTU4OGIxYzk2OWM2NGEyMzhhNGVkZTY2NjU2ZTExNzIwZTA1OWEw
11
- M2E2M2U2NzI4MzhiMjA2ZGU2M2Q0NjU2YTA3MmNmNmM3MmJiOTg=
12
- data.tar.gz: !binary |-
13
- YjUyMmExZDYxYzQzOGZiY2FkYTFhZTFhN2FmYmJhYjliZjk3Mjc2MDAwOTY0
14
- MmE2Y2YyYzBhNjBlN2YxZGEzZjAxNDQ3N2NkNzk5ZjBhYmUyZTU3YTJhZTI0
15
- NGNmY2NhZWUzM2ZkMWM0YmQ1NTg0ZTVhMWRiYWFiYTRlMjZlZDU=
2
+ SHA1:
3
+ metadata.gz: 293e3e4ff8735803adb6aa5c43a4ce6e4b53bbd9
4
+ data.tar.gz: a99116c2b1e5636553ff3d1cf8ddd40f09386f47
5
+ SHA512:
6
+ metadata.gz: 02e7726c65f111b0bd1a8345ed8091fbe84720c18cb4ccdd938ce016debc94923ef64ba15cf4be622d17dcc4db46499948aa772139a537ab115d7f758b951cc9
7
+ data.tar.gz: 9bf905c5f585c1a3fd1953d69991987bf35635691398eff87c13774d1ee5b8711062086c2289f213b71cd3064fe3f8d9d96d054b89708ae78e83e75dde4b0941
data/.gitignore CHANGED
@@ -4,4 +4,4 @@ Gemfile.lock
4
4
  pkg/*
5
5
  spec/log
6
6
  spec/tmp
7
- gemfiles
7
+ gemfiles/*.lock
@@ -0,0 +1,16 @@
1
+ services: mongodb
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ gemfile:
7
+ - gemfiles/rails30.gemfile
8
+ - gemfiles/rails31.gemfile
9
+ - gemfiles/rails32.gemfile
10
+ - gemfiles/rails4.gemfile
11
+ matrix:
12
+ exclude:
13
+ - rvm: 1.9.2
14
+ gemfile: gemfiles/rails32.gemfile
15
+ - rvm: 1.9.2
16
+ gemfile: gemfiles/rails4.gemfile
data/Appraisals CHANGED
@@ -1,26 +1,21 @@
1
1
  appraise "rails30" do
2
- gem "rails", "3.0.15"
2
+ gem "rails", "3.0.20"
3
3
  gem "sqlite3"
4
4
  end
5
5
 
6
6
  appraise "rails31" do
7
- gem "rails", "3.1.6"
7
+ gem "rails", "3.1.12"
8
8
  gem "mongoid"
9
9
  gem "sqlite3"
10
10
  end
11
11
 
12
12
  appraise "rails32" do
13
- gem "rails", "3.2.6"
13
+ gem "rails", "3.2.14"
14
14
  gem "mongoid"
15
15
  gem "sqlite3"
16
16
  end
17
17
 
18
18
  appraise "rails4" do
19
- gem "rails",
20
- :git => "git@github.com:rails/rails.git"
21
- gem "activerecord-deprecated_finders",
22
- :git => "git@github.com:rails/activerecord-deprecated_finders"
23
- gem "journey",
24
- :git => "git@github.com:rails/journey"
19
+ gem "rails", "4.0.0"
25
20
  gem "sqlite3"
26
21
  end
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "3.0.20"
6
+ gem "sqlite3"
7
+
8
+ gemspec :path=>"../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "3.1.12"
6
+ gem "mongoid"
7
+ gem "sqlite3"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "3.2.14"
6
+ gem "mongoid"
7
+ gem "sqlite3"
8
+
9
+ gemspec :path=>"../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "rails", "4.0.0"
6
+ gem "sqlite3"
7
+
8
+ gemspec :path=>"../"
@@ -6,4 +6,5 @@ require 'pry-rails/version'
6
6
  if defined?(Rails) && !ENV['DISABLE_PRY_RAILS']
7
7
  require 'pry-rails/railtie'
8
8
  require 'pry-rails/commands'
9
+ require 'pry-rails/model_formatter'
9
10
  end
@@ -2,13 +2,13 @@
2
2
 
3
3
  PryRails::Commands.create_command "recognize-path" do
4
4
  group "Rails"
5
- description "Verify that a URL is mapped to the right controller and action"
5
+ description "See which route matches a URL."
6
6
 
7
7
  def options(opt)
8
8
  opt.banner unindent <<-USAGE
9
- Usage: recognize-path PATH [-m|--method METHOD]
9
+ Usage: recognize-path <path> [-m|--method METHOD]
10
10
 
11
- Verifies that a given PATH is mapped to the right controller and action.
11
+ Verifies that a given path is mapped to the right controller and action.
12
12
 
13
13
  recognize-path example.com
14
14
  recognize-path example.com -m post
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+
3
+ class PryRails::ShowModel < Pry::ClassCommand
4
+ match "show-model"
5
+ group "Rails"
6
+ description "Show the given model."
7
+
8
+ def options(opt)
9
+ opt.banner unindent <<-USAGE
10
+ Usage: show-model <model name>
11
+
12
+ show-model displays one model from the current Rails app.
13
+ USAGE
14
+ end
15
+
16
+ def process
17
+ Rails.application.eager_load!
18
+
19
+ if args.empty?
20
+ output.puts opts
21
+ return
22
+ end
23
+
24
+ begin
25
+ model = Object.const_get(args.first)
26
+ rescue NameError
27
+ output.puts "Couldn't find model #{args.first}!"
28
+ return
29
+ end
30
+
31
+ formatter = PryRails::ModelFormatter.new
32
+
33
+ case
34
+ when model < ActiveRecord::Base
35
+ output.puts formatter.format_active_record(model)
36
+ when defined?(Mongoid::Document) && model < Mongoid::Document
37
+ output.puts formatter.format_mongoid(model)
38
+ else
39
+ output.puts "Don't know how to show #{model}!"
40
+ end
41
+ end
42
+ end
43
+
44
+ PryRails::Commands.add_command PryRails::ShowModel
@@ -18,6 +18,8 @@ class PryRails::ShowModels < Pry::ClassCommand
18
18
  def process
19
19
  Rails.application.eager_load!
20
20
 
21
+ @formatter = PryRails::ModelFormatter.new
22
+
21
23
  display_activerecord_models
22
24
  display_mongoid_models
23
25
  end
@@ -28,32 +30,7 @@ class PryRails::ShowModels < Pry::ClassCommand
28
30
  models = ActiveRecord::Base.descendants
29
31
 
30
32
  models.sort_by(&:to_s).each do |model|
31
- out = []
32
- out.push format_model_name model
33
-
34
- if model.table_exists?
35
- model.columns.each do |column|
36
- out.push format_column column.name, column.type
37
- end
38
- else
39
- out.push format_error "Table doesn't exist"
40
- end
41
-
42
- reflections = model.reflections.sort_by do |other_model, reflection|
43
- [reflection.macro.to_s, other_model.to_s]
44
- end
45
-
46
- reflections.each do |other_model, reflection|
47
- options = []
48
-
49
- if reflection.options[:through].present?
50
- options << "through #{text.blue ":#{reflection.options[:through]}"}"
51
- end
52
-
53
- out.push format_association reflection.macro, other_model, options
54
- end
55
-
56
- print_unless_filtered out
33
+ print_unless_filtered @formatter.format_active_record(model)
57
34
  end
58
35
  end
59
36
 
@@ -75,55 +52,16 @@ class PryRails::ShowModels < Pry::ClassCommand
75
52
  end
76
53
 
77
54
  models.sort_by(&:to_s).each do |model|
78
- out = []
79
- out.push format_model_name model
80
-
81
- model.fields.values.sort_by(&:name).each do |column|
82
- out.push format_column column.name, column.options[:type]
83
- end
84
-
85
- model.relations.each do |other_model, ref|
86
- options = []
87
- options << 'autosave' if ref.options[:autosave]
88
- options << 'autobuild' if ref.options[:autobuild]
89
- options << 'validate' if ref.options[:validate]
90
-
91
- if ref.options[:dependent]
92
- options << "dependent-#{ref.options[:dependent]}"
93
- end
94
-
95
- out.push format_association \
96
- kind_of_relation(ref.relation), other_model, options
97
- end
98
-
99
- print_unless_filtered out
55
+ print_unless_filtered @formatter.format_mongoid(model)
100
56
  end
101
57
  end
102
58
 
103
- def format_model_name(model)
104
- text.bright_blue model
105
- end
106
-
107
- def format_column(name, type)
108
- " #{name}: #{text.green type}"
109
- end
110
-
111
- def format_association(type, other, options = [])
112
- options_string = (options.any?) ? " (#{options.join(', ')})" : ''
113
- " #{type} #{text.blue ":#{other}"}#{options_string}"
114
- end
115
-
116
- def format_error(message)
117
- " #{text.red message}"
118
- end
119
-
120
- def print_unless_filtered array_of_strings
121
- result = array_of_strings.join("\n")
59
+ def print_unless_filtered(str)
122
60
  if opts.present?(:G)
123
- return unless result =~ grep_regex
124
- result = colorize_matches(result) # :(
61
+ return unless str =~ grep_regex
62
+ str = colorize_matches(str) # :(
125
63
  end
126
- output.puts result
64
+ output.puts str
127
65
  end
128
66
 
129
67
  def colorize_matches(string)
@@ -137,17 +75,6 @@ class PryRails::ShowModels < Pry::ClassCommand
137
75
  def grep_regex
138
76
  @grep_regex ||= Regexp.new(opts[:G], Regexp::IGNORECASE)
139
77
  end
140
-
141
- def kind_of_relation(relation)
142
- case relation.to_s.sub(/^Mongoid::Relations::/, '')
143
- when 'Referenced::Many' then 'has_many'
144
- when 'Referenced::One' then 'has_one'
145
- when 'Referenced::In' then 'belongs_to'
146
- when 'Embedded::Many' then 'embeds_many'
147
- when 'Embedded::One' then 'embeds_one'
148
- when 'Embedded::In' then 'embedded_in'
149
- end
150
- end
151
78
  end
152
79
 
153
80
  PryRails::Commands.add_command PryRails::ShowModels
@@ -0,0 +1,93 @@
1
+ # encoding: UTF-8
2
+
3
+ module PryRails
4
+ class ModelFormatter
5
+ def format_active_record(model)
6
+ out = []
7
+ out.push format_model_name model
8
+
9
+ if model.table_exists?
10
+ model.columns.each do |column|
11
+ out.push format_column column.name, column.type
12
+ end
13
+ else
14
+ out.push format_error "Table doesn't exist"
15
+ end
16
+
17
+ reflections = model.reflections.sort_by do |other_model, reflection|
18
+ [reflection.macro.to_s, other_model.to_s]
19
+ end
20
+
21
+ reflections.each do |other_model, reflection|
22
+ options = []
23
+
24
+ if reflection.options[:through].present?
25
+ options << "through #{text.blue ":#{reflection.options[:through]}"}"
26
+ end
27
+
28
+ out.push format_association reflection.macro, other_model, options
29
+ end
30
+
31
+ out.join("\n")
32
+ end
33
+
34
+ def format_mongoid(model)
35
+ out = []
36
+ out.push format_model_name model
37
+
38
+ model.fields.values.sort_by(&:name).each do |column|
39
+ out.push format_column column.name, column.options[:type]
40
+ end
41
+
42
+ model.relations.each do |other_model, ref|
43
+ options = []
44
+ options << 'autosave' if ref.options[:autosave]
45
+ options << 'autobuild' if ref.options[:autobuild]
46
+ options << 'validate' if ref.options[:validate]
47
+
48
+ if ref.options[:dependent]
49
+ options << "dependent-#{ref.options[:dependent]}"
50
+ end
51
+
52
+ out.push format_association \
53
+ kind_of_relation(ref.relation), other_model, options
54
+ end
55
+
56
+ out.join("\n")
57
+ end
58
+
59
+ def format_model_name(model)
60
+ text.bright_blue model
61
+ end
62
+
63
+ def format_column(name, type)
64
+ " #{name}: #{text.green type}"
65
+ end
66
+
67
+ def format_association(type, other, options = [])
68
+ options_string = (options.any?) ? " (#{options.join(', ')})" : ''
69
+ " #{type} #{text.blue ":#{other}"}#{options_string}"
70
+ end
71
+
72
+ def format_error(message)
73
+ " #{text.red message}"
74
+ end
75
+
76
+ def kind_of_relation(relation)
77
+ case relation.to_s.sub(/^Mongoid::Relations::/, '')
78
+ when 'Referenced::Many' then 'has_many'
79
+ when 'Referenced::One' then 'has_one'
80
+ when 'Referenced::In' then 'belongs_to'
81
+ when 'Embedded::Many' then 'embeds_many'
82
+ when 'Embedded::One' then 'embeds_one'
83
+ when 'Embedded::In' then 'embedded_in'
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ def text
90
+ Pry::Helpers::Text
91
+ end
92
+ end
93
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  module PryRails
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
@@ -0,0 +1,57 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "show-models" do
6
+ before { Pry.color = false }
7
+ after { Pry.color = true }
8
+
9
+ it "should print one ActiveRecord model" do
10
+ output = mock_pry('show-model Beer', 'exit-all')
11
+
12
+ expected = <<MODEL
13
+ Beer
14
+ id: integer
15
+ name: string
16
+ type: string
17
+ rating: integer
18
+ ibu: integer
19
+ abv: integer
20
+ belongs_to :hacker
21
+ MODEL
22
+
23
+ output.must_equal expected
24
+ end
25
+
26
+ if defined? Mongoid
27
+ it "should print one Mongoid model" do
28
+ output = mock_pry('show-model Artist', 'exit-all')
29
+
30
+ expected = <<MODEL
31
+ Artist
32
+ _id: Moped::BSON::ObjectId
33
+ name: String
34
+ embeds_one :beer (validate)
35
+ embeds_many :instruments (validate)
36
+ MODEL
37
+
38
+ output.gsub! /^ *_type: String\n/, '' # mongoid 3.0 and 3.1 differ on this
39
+ output.must_equal expected
40
+ end
41
+ end
42
+
43
+ it "should print an error if the model doesn't exist" do
44
+ output = mock_pry('show-model FloojBulb', 'exit-all')
45
+ output.must_equal "Couldn't find model FloojBulb!\n"
46
+ end
47
+
48
+ it "should print an error if it doesn't know what to do with the model" do
49
+ output = mock_pry('show-model PryRails', 'exit-all')
50
+ output.must_equal "Don't know how to show PryRails!\n"
51
+ end
52
+
53
+ it "should print help if no model name is given" do
54
+ output = mock_pry('show-model', 'exit-all')
55
+ output.must_match /Usage: show-model/
56
+ end
57
+ end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Wenglewski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-07 00:00:00.000000000 Z
11
+ date: 2013-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- prerelease: false
15
14
  name: pry
16
- version_requirements: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ! '>='
19
- - !ruby/object:Gem::Version
20
- version: 0.9.10
21
15
  requirement: !ruby/object:Gem::Requirement
22
16
  requirements:
23
- - - ! '>='
17
+ - - '>='
24
18
  - !ruby/object:Gem::Version
25
19
  version: 0.9.10
26
20
  type: :runtime
27
- - !ruby/object:Gem::Dependency
28
21
  prerelease: false
29
- name: appraisal
30
22
  version_requirements: !ruby/object:Gem::Requirement
31
23
  requirements:
32
- - - ! '>='
24
+ - - '>='
33
25
  - !ruby/object:Gem::Version
34
- version: '0'
26
+ version: 0.9.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ! '>='
31
+ - - '>='
38
32
  - !ruby/object:Gem::Version
39
33
  version: '0'
40
34
  type: :development
41
- - !ruby/object:Gem::Dependency
42
35
  prerelease: false
43
- name: minitest
44
36
  version_requirements: !ruby/object:Gem::Requirement
45
37
  requirements:
46
- - - ! '>='
38
+ - - '>='
47
39
  - !ruby/object:Gem::Version
48
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
- - !ruby/object:Gem::Dependency
56
49
  prerelease: false
57
- name: rr
58
50
  version_requirements: !ruby/object:Gem::Requirement
59
51
  requirements:
60
- - - ! '>='
52
+ - - '>='
61
53
  - !ruby/object:Gem::Version
62
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rr
63
57
  requirement: !ruby/object:Gem::Requirement
64
58
  requirements:
65
- - - ! '>='
59
+ - - '>='
66
60
  - !ruby/object:Gem::Version
67
61
  version: '0'
68
62
  type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
69
  description:
70
70
  email:
71
71
  - robin@wenglewski.de
@@ -74,19 +74,26 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
+ - .travis.yml
77
78
  - Appraisals
78
79
  - Appraisals-1.8
79
80
  - Gemfile
80
81
  - LICENCE
81
82
  - Rakefile
82
83
  - Readme.md
84
+ - gemfiles/rails30.gemfile
85
+ - gemfiles/rails31.gemfile
86
+ - gemfiles/rails32.gemfile
87
+ - gemfiles/rails4.gemfile
83
88
  - lib/pry-rails.rb
84
89
  - lib/pry-rails/commands.rb
85
90
  - lib/pry-rails/commands/recognize_path.rb
86
91
  - lib/pry-rails/commands/show_middleware.rb
92
+ - lib/pry-rails/commands/show_model.rb
87
93
  - lib/pry-rails/commands/show_models.rb
88
94
  - lib/pry-rails/commands/show_routes.rb
89
95
  - lib/pry-rails/console.rb
96
+ - lib/pry-rails/model_formatter.rb
90
97
  - lib/pry-rails/railtie.rb
91
98
  - lib/pry-rails/version.rb
92
99
  - pry-rails.gemspec
@@ -97,6 +104,7 @@ files:
97
104
  - spec/railtie_spec.rb
98
105
  - spec/recognize_path_spec.rb
99
106
  - spec/show_middleware_spec.rb
107
+ - spec/show_model_spec.rb
100
108
  - spec/show_models_spec.rb
101
109
  - spec/show_routes_spec.rb
102
110
  - spec/spec_helper.rb
@@ -110,17 +118,17 @@ require_paths:
110
118
  - lib
111
119
  required_ruby_version: !ruby/object:Gem::Requirement
112
120
  requirements:
113
- - - ! '>='
121
+ - - '>='
114
122
  - !ruby/object:Gem::Version
115
123
  version: '0'
116
124
  required_rubygems_version: !ruby/object:Gem::Requirement
117
125
  requirements:
118
- - - ! '>='
126
+ - - '>='
119
127
  - !ruby/object:Gem::Version
120
128
  version: '0'
121
129
  requirements: []
122
130
  rubyforge_project:
123
- rubygems_version: 2.0.3
131
+ rubygems_version: 2.0.2
124
132
  signing_key:
125
133
  specification_version: 4
126
134
  summary: Use Pry as your rails console
@@ -132,6 +140,7 @@ test_files:
132
140
  - spec/railtie_spec.rb
133
141
  - spec/recognize_path_spec.rb
134
142
  - spec/show_middleware_spec.rb
143
+ - spec/show_model_spec.rb
135
144
  - spec/show_models_spec.rb
136
145
  - spec/show_routes_spec.rb
137
146
  - spec/spec_helper.rb