Sha256: d8caab8ef80549a06431ce529179c7ab3230ea1d40985a47f42dfb50d901b4db
Contents?: true
Size: 786 Bytes
Versions: 2
Compression:
Stored size: 786 Bytes
Contents
module Blueprints class ModelGenerator < Rails::Generators::NamedBase argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" def create_blueprint blueprint = "#{class_name}.blueprint :#{singular_name}" attributes.each do |attribute| blueprint << ", :#{attribute.name} => #{default_for(attribute)}" end dir = File.exists?('spec') ? 'spec' : 'test' file = "#{dir}/blueprint.rb" create_file file unless File.exists?(file) append_file file, "#{blueprint}\n" end private def default_for(attribute) if attribute.reference? "d(:#{attribute.name})" else attribute.default.inspect end end end end Rails::Generators.hide_namespace(:blueprints)
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
blueprints-1.0.1 | lib/generators/blueprints/model/model_generator.rb |
blueprints-1.0.0 | lib/generators/blueprints/model/model_generator.rb |