Module: Transcribable

Extended by:
ActiveSupport::Concern
Included in:
TranscribableGenerator
Defined in:
lib/transcribable.rb,
lib/transcribable/railtie.rb,
lib/transcribable/version.rb

Defined Under Namespace

Modules: ClassMethods, LocalInstanceMethods Classes: Railtie

Constant Summary collapse

VERSION =
"0.0.6"

Class Method Summary collapse

Class Method Details

.new_columnsObject

If we’ve migrated our master table, and need transcriptions to catch up. Returns a hash like transcribable_attrs



44
45
46
47
48
49
50
51
52
# File 'lib/transcribable.rb', line 44

def self.new_columns
  return nil unless defined?(Transcription)

  cols = Transcribable.transcribable_attrs.keys - Transcription.columns_hash.keys
  cols.reduce(Hash.new(0)) do |memo, it|
    memo[it] = Kernel.const_get(@@table.classify).columns_hash[it].type
    memo
  end
end

.tableObject



15
16
17
18
19
20
# File 'lib/transcribable.rb', line 15

def self.table
  # transcribable_attrs() "discovers" the columns
  # and table. run it if we don't have a table yet.
  transcribable_attrs if @@table.nil?
  @@table
end

.transcribable_attrsObject

creates a hash like… => :string, ‘amount’ => :integer



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/transcribable.rb', line 24

def self.transcribable_attrs
  return @@transcribable_attrs if @@transcribable_attrs

  @@transcribable_attrs = {}
  ActiveRecord::Base.connection.tables.reject {|t| t == "schema_migrations" }.each do |table|
    klass = Kernel.const_get(table.classify)
    klass.column_names.each do |col|
      if klass.transcribable?(col)
        @@table = table
        @@transcribable_attrs[col] = klass.columns_hash[col].type
      end
    end
  end

  @@transcribable_attrs
end