module ActiveLeonardo::Leosca::Seed

Protected Instance Methods

attribute_to_hash(attribute) click to toggle source
# File lib/generators/active_leonardo.rb, line 33
def attribute_to_hash(attribute)
  name = case attribute.type
           when :references, :belongs_to then ":#{attribute.name}_id"
           else                               ":#{attribute.name}"
         end
  value = case attribute.type
            when :boolean                 then "true"
            when :integer                 then "#"
            when :float, :decimal         then "#.46"
            when :references, :belongs_to then "rand(#{attribute.name}_from..#{attribute.name}_to)"
            when :date                    then "#{Time.now.strftime("%Y-%m-%d 00:00:00.000")}".inspect
            when :datetime                then "#{Time.now.strftime("%Y-%m-%d %H:%M:%S.000")}".inspect
            when :time, :timestamp        then "#{Time.now.strftime("%H:%M:%S.000")}".inspect
            else                               "#{attribute.name.titleize}\#".inspect
          end
  " #{name} => #{value}"
end
attribute_to_range(attribute) click to toggle source
# File lib/generators/active_leonardo.rb, line 50
def attribute_to_range(attribute)
  case attribute.type
    when :references, :belongs_to then  "#{attribute.name}_from = #{attribute.name.classify}.first.id; #{attribute.name}_to = #{attribute.name.classify}.last.id#{CRLF}"
    else                                ""
  end
end
attributes_accessible(attributes, class_name) click to toggle source
# File lib/generators/active_leonardo.rb, line 56
def attributes_accessible(attributes, class_name)
  selected = attributes.select {|attribute| [:references, :belongs_to].include?(attribute.type) ? true : false }
  if selected.empty?
    ""
  else
    "#{class_name}.attr_accessible " <<
        selected.map{|attribute| ":#{attribute.name}_id"}.join(', ') <<
        CRLF
  end
end