DEVELOPMENT ON THIS WILL STOP AS THIS IS BEING PORTED INTO THE RESTFULX GEM
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
rails_generators
tasks
templates
MIT-LICENSE
README.rdoc
Rakefile
init.rb
install.rb

README.rdoc

SchemaToYaml

A simple rails plugin that adds a new rake task [rake db:schema:to_yaml]. It will analyze your database and create a model.yml file for use in RestfulX scaffolding via the [./script/generate my_rx_scaffold] command. This is also very useful for adding in additional functionality to the model.yml file. Please see below for the juicy details.

Installing:

./script/plugin install git://github.com/malkomalko/schema_to_yaml.git
  • This requires the restfulx gem:

    http://github.com/dima/restfulx/tree/master

Post Install:

You will notice that there is a schema_to_yaml.yml file located in the config dir:

defaults: &defaults
  attachment_plugin:  'paperclip'              # => paperclip
  controller_pattern: 'default'                # => default/resource_controller
  layouts:
    enabled:  'true'                           # => true/false
    default:  'default'                        # => default (more coming soon)
  ignored:                                     # => ignored tables/fields won't appear in model.yml
    tables: [table1 table2]
    fields: [field1 field2]

development:
  <<: *defaults

test:
  <<: *defaults

production:
  <<: *defaults

These settings will be updating over time, but will help in determining what the scaffold will generate. More templates coming soon!

Quickstart:

Make sure you already have a schema, or create some migrations and migrate, or create a schema.rb file using PJ Hyett's auto_migrations plugin: github.com/pjhyett/auto_migrations/tree/master

  • rake db:schema:to_yaml

  • ./script/generate my_rx_scaffold

Special YAML Columns:

attachment_field: [avatar]
  * argument takes Paperclip field name, with Attachment-Fu option coming soon
belongs_to: [account]
has_many: [announcements, files, folders, users]
has_many_through: [permissions, roles]
  * you will have to manually add/modify this to model.yml, you're allowed to have multiple has_many_throughs
has_one:  [suitcase]
polymorphic: [commentable]
tree_model: [parent]
layout: [default]
  * you will have to manually add/modify this to model.yml, with only a default layout currently present
ignored_fields: [children_count, ancestors_count, descendants_count, position]
  * specify fields you don't want being generated

Schema.rb example:

ActiveRecord::Schema.define do

  create_table "accounts", :force => true do |t|
    t.string   "name"
    t.text     "description"
    t.string   "color1"
    t.string   "color2"
    t.string   "color3"
    t.string   "logo_file_name"
    t.string   "logo_content_type"
    t.integer  "logo_file_size"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "uuid",  :limit => 36
  end

  create_table "announcements", :force => true do |t|
    t.integer  "account_id"
    t.string   "subject"
    t.text     "body"
    t.date     "starts_at"
    t.date     "ends_at"
    t.boolean  "show_to_mom"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "uuid",  :limit => 36
  end
  add_index 'announcements', 'account_id'

  create_table "attachments", :force => true do |t|
    t.integer  "account_id"
    t.integer  "folder_id"
    t.text     "notes"
    t.string   "file_file_name"
    t.string   "file_content_type"
    t.integer  "file_file_size"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "uuid",  :limit => 36
  end
  add_index 'attachments', 'account_id'
  add_index 'attachments', 'folder_id'

  create_table "favorites", :force => true do |t|
    t.integer  "user_id"
    t.integer  "favoriteable_id"
    t.string   "favoriteable_type"
    t.string   "uuid",  :limit => 36
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  add_index :favorites, :user_id
  add_index :favorites, [:favoriteable_type, :favoriteable_id]

  create_table "folders", :force => true do |t|
    t.integer  "parent_id"
    t.integer  "position"
    t.integer  "children_count"
    t.integer  "ancestors_count"
    t.integer  "descendants_count"
    t.string   "name"
    t.integer  "account_id"
    t.string   "uuid",  :limit => 36
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  add_index 'folders', 'parent_id'
  add_index 'folders', 'account_id'

  create_table "permissions", :force => true do |t|
    t.integer  "user_id"
    t.integer  "role_id"
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  add_index "permissions", ["user_id"], :name => "index_permissions_on_user_id"
  add_index "permissions", ["role_id"], :name => "index_permissions_on_role_id"

  create_table "roles", :force => true do |t|
    t.string  "name"
  end

  create_table "users", :force => true do |t|
    t.integer  "account_id"
    t.string   "email"
    t.string   "first_name"
    t.float    "happiness"
    t.string   "last_name"
    t.string   "avatar_file_name"
    t.string   "avatar_content_type"
    t.integer  "avatar_file_size"
    t.string   "uuid", :limit => 36
    t.datetime "created_at"
    t.datetime "updated_at"
  end
  add_index 'users', 'account_id'

end

Resulting Model.yml example:

account:
 - name: string
 - description: text
 - color1: string
 - color2: string
 - color3: string
 - logo_file_name: string
 - logo_content_type: string
 - logo_file_size: integer
 - attachment_field: [logo]
 - has_many: [announcements, files, folders, users]

attachment:
 - notes: text
 - file_file_name: string
 - file_content_type: string
 - file_file_size: integer
 - attachment_field: [file]
 - belongs_to: [account, folder]

announcement:
 - subject: string
 - body: text
 - starts_at: date
 - ends_at: date
 - show_to_mom: boolean
 - belongs_to: [account]

favorite:
 - favoriteable_type: string
 - polymorphic: [favoriteable]
 - belongs_to: [user]

folder:
 - tree_model: [parent]
 - position: integer
 - children_count: integer
 - ancestors_count: integer
 - descendants_count: integer
 - name: string
 - belongs_to: [account]
 - has_many: [attachments]
 - ignored_fields: [children_count, ancestors_count, descendants_count, position]

permission:
 - belongs_to: [user, role]

role:
 - name: string
 - has_many: [permissions]

user:
 - email: string
 - first_name: string
 - happiness: float
 - last_name: string
 - avatar_file_name: string
 - avatar_content_type: string
 - avatar_file_size: integer
 - attachment_field: [avatar]
 - belongs_to: [account]
 - has_many: [favorites, permissions]

Copyright © 2009 Robert Malko, released under the MIT license