table-name-to-class 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/table-name-to-class.rb +25 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8928d9d737170cbc1eb5b7c4e5393b52b8e1e672
4
- data.tar.gz: 5ff533249050d038ed08451c0edc3786af4141cc
3
+ metadata.gz: 62c84a19f2ea2438eb46054d82703b4cf9a23148
4
+ data.tar.gz: abe7e707df9b27b9b7d36036f56d76eda2c9469d
5
5
  SHA512:
6
- metadata.gz: 999146ba7abe4b2e8f5d19d3b32cc36efd534bae2bcc708a6384488911e6a2ad6de10d6eb09fbe8646dcbabc8bc85510ee0418b1c6243234c13f7fca1944a3dd
7
- data.tar.gz: fdfbb1d7103bb9e2bf441027cb650efe8ed7f651206b1ef39c88109f8fa7900dc3780b72d5a20b14798f7e8dbf72d7d1e17453bf6eb4ca3b9db1145e85878382
6
+ metadata.gz: f8607a8c8e1cb413b522c545daa201ec14dafe2c604b71380d777ece9a4bd182b2f2b8d6b6c1e8009c1be5da286bfaf3405e82f453ded0bd37a64a7096880193
7
+ data.tar.gz: 9a634a6d2b5417a961115218228ef0848bd9d7015b586ff19ff86538c030858086b53d3ab0b24a1ed68b48a874d2cac83d9286f3c1f25a32a9c8e06abff53b65
@@ -1,17 +1,41 @@
1
1
  class TableNameToClass
2
2
  @@conversion_hash = nil
3
3
 
4
+ ##
5
+ # Convert a table name into a class constant (or nil if no constant for that
6
+ # table)
7
+ # ---
8
+ # Expects:
9
+ # name (object like string):: Name of database table, this can be anything
10
+ # that returns a valid table name when hit with
11
+ # to_s
12
+ # force_update (boolean):: Should the table/class correspondence be updated?
13
+ # Any none-nil value triggers a reload.
14
+ #
15
+ # Returns:
16
+ # nil if the lookup fails, the constant for the class associated with the
17
+ # table otherwise.
4
18
  def self.convert(name, force_update = nil)
5
19
  init_hash unless @@conversion_hash || force_update
6
- @@conversion_hash[name]
20
+ @@conversion_hash[name.to_s]
7
21
  end
8
22
 
23
+ ##
24
+ # Debug helper
25
+ # ---
26
+ # Returns the hash of table name and class constant pairs
9
27
  def self.debug
10
28
  return @@conversion_hash
11
29
  end
12
30
 
13
31
  private
14
32
 
33
+ ## :doc:
34
+ # Loads the correspondence cache
35
+ # ----
36
+ # Recursively visits every .rb file in app/models and requires them all. This
37
+ # is required to avoid failures when trying to convert the name of a table
38
+ # who's model has not yet been loaded.
15
39
  def self.init_hash
16
40
  # Expanded from idea posted here: http://stackoverflow.com/a/6150228
17
41
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table-name-to-class
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morgen Peschke