-
Notifications
You must be signed in to change notification settings - Fork 9
Notes
*Don't take this too seriously, it's all a work in progress :-)
This plugin is intended to compliment the rails_admin export function. It is intended to allow the user to import data from a variety of file formats.
- CSV, delimited by comma, semi-colon and tab
- JSON
- XML
- YAML *Note that this format is not supported by rails_admin_export (but it should be!)
- RSS *See section below
This particular fork also allows for the configuration of a 'key' field, which determines if a record is new, wherein a new record should be created, or if the record already exists and should only be updated.
Currently, the only working file format is comma delimited CSV files.
RSS files must be handled as a special case. Other file formats allow one to serialize data isomorphically. RSS, however, imposes a strict structure and therefore, a mapping between item fields must be established. For every <item>
in an RSS file, there exists:
- The title of the item
<title>
- A description of the item
<description>
- A link to that item
<link>
- A unique identifier
<guid>
- The data published
<pubDate>
Given a ActiveRecord defined thus:
create_table "posts", :force => true do |t|
t.string "post_title", :null => false
t.text "post_body", :null => false
t.datetime "published_at"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "edited_at", :null => false
end
an RSS mapping might appear thusly as pure Ruby code:
RailsAdminImport.config do |config|
config.model Post do
rss_map[:post_title] => Proc.new{ |item| item.title + Date.parse(item.pubDate) }
rss_map[:post_body] => Proc.new{ |item| item.description}
end
end
or as a DSL
RailsAdminImport.config do |config|
config.model Post do
rss_mapping do
:post_title, item.title + Date.parse(item.pubDate)
:post_body, item.description
end
end