table-name-to-class 0.0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/table-name-to-class.rb +30 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8928d9d737170cbc1eb5b7c4e5393b52b8e1e672
4
+ data.tar.gz: 5ff533249050d038ed08451c0edc3786af4141cc
5
+ SHA512:
6
+ metadata.gz: 999146ba7abe4b2e8f5d19d3b32cc36efd534bae2bcc708a6384488911e6a2ad6de10d6eb09fbe8646dcbabc8bc85510ee0418b1c6243234c13f7fca1944a3dd
7
+ data.tar.gz: fdfbb1d7103bb9e2bf441027cb650efe8ed7f651206b1ef39c88109f8fa7900dc3780b72d5a20b14798f7e8dbf72d7d1e17453bf6eb4ca3b9db1145e85878382
@@ -0,0 +1,30 @@
1
+ class TableNameToClass
2
+ @@conversion_hash = nil
3
+
4
+ def self.convert(name, force_update = nil)
5
+ init_hash unless @@conversion_hash || force_update
6
+ @@conversion_hash[name]
7
+ end
8
+
9
+ def self.debug
10
+ return @@conversion_hash
11
+ end
12
+
13
+ private
14
+
15
+ def self.init_hash
16
+ # Expanded from idea posted here: http://stackoverflow.com/a/6150228
17
+
18
+ # Recursively require all models
19
+ Dir.glob(Rails.root.join('app','models','**','*').to_s).each do |f|
20
+ begin
21
+ require f if File.file?(f) && f =~ /\.rb$/
22
+ rescue IdentityCache::AlreadyIncludedError
23
+ end
24
+ end
25
+
26
+ @@conversion_hash = Hash[
27
+ ActiveRecord::Base.descendants.map {|c| [c.table_name, c]}
28
+ ]
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: table-name-to-class
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Morgen Peschke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A slightly smarter conversion than .classify
14
+ email: morgen.peschke@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/table-name-to-class.rb
20
+ homepage: https://github.com/morgen-peschke/table-name-to-class
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.2.2
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Converts database table names to class constants
44
+ test_files: []