class ActiveContent::ModelGenerator
Public Instance Methods
create_migration_file()
click to toggle source
# File lib/generators/active_content/model_generator.rb, line 12 def create_migration_file template 'model.rb', "app/models/#{model_file}.rb" end
Private Instance Methods
model_class()
click to toggle source
# File lib/generators/active_content/model_generator.rb, line 18 def model_class name.camelize end
model_file()
click to toggle source
# File lib/generators/active_content/model_generator.rb, line 26 def model_file "#{name.downcase.underscore}" end
model_meta()
click to toggle source
# File lib/generators/active_content/model_generator.rb, line 30 def model_meta args.map do |arg| field, cast_type, default = arg.split(':') items = [":#{field.to_sym}", ":#{cast_type.to_sym}"] items << ["default: #{value_type_cast(cast_type.to_sym, default)}"] if default.present? items.join(', ') end end
type_class()
click to toggle source
# File lib/generators/active_content/model_generator.rb, line 22 def type_class type.camelize end
value_type_cast(cast_type, value)
click to toggle source
# File lib/generators/active_content/model_generator.rb, line 41 def value_type_cast(cast_type, value) strings = [:string, :date, :datetime, :time] cast_type.in?(strings) ? "'#{value}'" : value end