Class: RDL::Rails
- Inherits:
-
Object
- Object
- RDL::Rails
- Defined in:
- lib/types/rails/_helpers.rb
Class Method Summary collapse
-
.attribute_types(model) ⇒ Object
- + model +
-
is an ActiveRecord::Base subclass that has been loaded.
-
.column_to_rdl(rails_type) ⇒ Object
- + rails_type +
-
is a Rails column type (:string, :integer, etc) returns a String containing an RDL type.
Class Method Details
.attribute_types(model) ⇒ Object
- + model +
-
is an ActiveRecord::Base subclass that has been loaded.
Gets the columns_hash of the model and returns a String that can serve as the paramter list to a method that accepts any number of the model’s attributes keyed by the attribute names.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/types/rails/_helpers.rb', line 37 def self.attribute_types(model) args = [] model.columns_hash.each { |name, col| t = column_to_rdl(col.type) if col.null args << "#{name}: ?#{t}" else args << "#{name}: ?!#{t}" end } return args.join ',' end |
.column_to_rdl(rails_type) ⇒ Object
- + rails_type +
-
is a Rails column type (:string, :integer, etc)
returns a String containing an RDL type
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/types/rails/_helpers.rb', line 10 def self.column_to_rdl(rails_type) case rails_type when :string, :text, :binary return 'String' when :integer return 'Fixnum' when :float return 'Float' when :decimal return 'BigDecimal' when :boolean return '%bool' when :date return 'Date' when :time return 'Time' when :datetime return 'DateTime' else raise RuntimeError, "Unrecoganized column type #{rails_type}" end end |