Module: ActiveFacts::Persistence
- Defined in:
- lib/activefacts/persistence/columns.rb,
lib/activefacts/mapping/rails.rb,
lib/activefacts/persistence/index.rb,
lib/activefacts/generate/rails/models.rb,
lib/activefacts/persistence/reference.rb,
lib/activefacts/generate/helpers/rails.rb,
lib/activefacts/persistence/foreignkey.rb,
lib/activefacts/generate/transform/surrogate.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Column, ForeignKey, Index, Reference
Class Method Summary collapse
- .rails_plural_name(name) ⇒ Object
- .rails_singular_name(name) ⇒ Object
-
.rails_type(type, length) ⇒ Object
Return ActiveRecord type and (modified?) length for the passed base type.
Class Method Details
.rails_plural_name(name) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/activefacts/mapping/rails.rb', line 54 def self.rails_plural_name name # Crunch spaces and pluralise the first part, all in snake_case name.pop if name.is_a?(Array) and name.last == [] name = name[0]*'_' if name.is_a?(Array) and name.size == 1 if name.is_a?(Array) name = ActiveSupport::Inflector.tableize((name[0]*'_').gsub(/\s+/, '_')) + '_' + ActiveSupport::Inflector.underscore((name[1..-1].flatten*'_').gsub(/\s+/, '_')) else ActiveSupport::Inflector.tableize(name.gsub(/\s+/, '_')) end end |
.rails_singular_name(name) ⇒ Object
67 68 69 70 71 |
# File 'lib/activefacts/mapping/rails.rb', line 67 def self.rails_singular_name name # Crunch spaces and convert to snake_case name = name.flatten*'_' if name.is_a?(Array) ActiveSupport::Inflector.underscore(name.gsub(/\s+/, '_')) end |
.rails_type(type, length) ⇒ Object
Return ActiveRecord type and (modified?) length for the passed base type
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/activefacts/mapping/rails.rb', line 10 def self.rails_type(type, length) rails_type = case type when /^Auto ?Counter$/ 'integer' # REVISIT: Need to detect surrogate ID fields and handle them correctly when /^Unsigned ?Integer$/, /^Integer$/, /^Signed ?Integer$/, /^Unsigned ?Small ?Integer$/, /^Signed ?Small ?Integer$/, /^Unsigned ?Tiny ?Integer$/ length = nil 'integer' when /^Decimal$/ 'decimal' when /^Fixed ?Length ?Text$/, /^Char$/ 'string' when /^Variable ?Length ?Text$/, /^String$/ 'string' when /^Large ?Length ?Text$/, /^Text$/ 'text' when /^Date ?And ?Time$/, /^Date ?Time$/ 'datetime' when /^Date$/ 'datetime' when /^Time$/ 'time' when /^Auto ?Time ?Stamp$/ 'timestamp' when /^Money$/ 'decimal' when /^Picture ?Raw ?Data$/, /^Image$/, /^Variable ?Length ?Raw ?Data$/, /^Blob$/ 'binary' when /^BIT$/ 'boolean' else type # raise "ActiveRecord type unknown for standard type #{type}" end [rails_type, length] end |