console_util 0.3.1 → 0.4.0

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.
@@ -1,3 +1,3 @@
1
1
  module ConsoleUtil
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/console_util.rb CHANGED
@@ -26,18 +26,24 @@ module ConsoleUtil
26
26
  # Import a MySQL dump file.
27
27
  # [This may work with other databases, but has only been tested with MySQL.]
28
28
  def import_mysql_dump(filename)
29
- sql_dump_file = File.open(Rails.root.join('sql', "#{filename}.sql"))
29
+ sql_dump_file = File.open(filename)
30
30
  while sql_statement = sql_dump_file.gets(";\n") do
31
31
  ActiveRecord::Base.connection.execute(sql_statement) unless sql_statement.blank?
32
32
  end
33
33
  end
34
34
 
35
- # Load all models into the environment
36
- def load_all_models
37
- Rails.root.join('app/models').each_entry do |model_file|
38
- model_match = model_file.to_s.match(/^(.*)\.rb$/)
39
- model_match[1].camelize.constantize if model_match
40
- end
35
+ # Load all models into the environment and return them.
36
+ #
37
+ # Options:
38
+ # :active_record If true, returns only ActiveRecord models.
39
+ def load_all_models(options = {})
40
+ model_path = Rails.root.join("app/models")
41
+ model_filenames = Dir[model_path.join("**/*.rb")]
42
+ model_filepaths = model_filenames.map { |filename| Pathname(filename).relative_path_from(model_path) }
43
+ model_names = model_filepaths.map { |filepath| filepath.to_s.chomp(".rb").camelize }
44
+ models = model_names.map(&:constantize)
45
+ models = models.select { |model| model.is_a?(Class) && (model < ActiveRecord::Base) } if options[:active_record]
46
+ models
41
47
  end
42
48
 
43
49
  # Allows you to filter output to the console using grep
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_util
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Clyde Law
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-24 00:00:00 -07:00
19
- default_executable:
18
+ date: 2013-07-16 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
21
  name: rails
@@ -52,7 +51,6 @@ files:
52
51
  - lib/console_util.rb
53
52
  - lib/console_util/color.rb
54
53
  - lib/console_util/version.rb
55
- has_rdoc: true
56
54
  homepage: http://github.com/FutureAdvisor/console_util
57
55
  licenses:
58
56
  - MIT
@@ -82,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
80
  requirements: []
83
81
 
84
82
  rubyforge_project: console_util
85
- rubygems_version: 1.6.2
83
+ rubygems_version: 1.8.24
86
84
  signing_key:
87
85
  specification_version: 3
88
86
  summary: Contains various utilities for working in the Rails console.