dm-mapping 0.3.0

by Lin Jen-Shin (a.k.a. godfat-真常)

strip any number: 18god29fat7029 (at] godfat32 -dooot- 20org

DESCRIPTION:

DataMapper plugin that helps you manipulate an existing database.
It creates mappings between existing columns and model's properties.

SYNOPSIS:

require 'dm-core'

# setup first, or dm-mapping can't determine which adapter it should load up
DataMapper.setup :default, 'sqlite3:db/development.sqlite3'

require 'dm-mapping'

class User
  include DataMapper::Resource
  # maping all
  mapping /.*/

  # mapping for ended with _at, and started with salt_
  mapping /_at$/, /^salt_/

  # mapping id and email
  mapping :id, :email

  # mapping all fields with type String, and id
  mapping String, :id

  # mapping login, and all fields with type Integer
  mapping :login, Integer
end

DataMapper.repository.adapter.storages
# => ['users']

User.fields
# => [['id',          Integer,  {:serial => true}],
      ['email',       String,   {:default => '[email protected]'}],
      ['created_at',  DateTime, {}],
      ['salt_first',  String,   {}],
      ['salt_second', String,   {}]]

DataMapper.repository.adapter.fields('users')
# => [['id',          Integer,  {:serial => true}],
      ['email',       String,   {:default => '[email protected]'}],
      ['created_at',  DateTime, {}],
      ['salt_first',  String,   {}],
      ['salt_second', String,   {}]]

DataMapper.repository.adapter.storages_and_fields
# => {'users' => [['id',          Integer,  {:serial => true}],
                  ['email',       String,   {:default => '[email protected]'}],
                  ['created_at',  DateTime, {}],
                  ['salt_first',  String,   {}],
                  ['salt_second', String,   {}]]}

REQUIREMENTS:

  • dm-core 0.9.3

INSTALL:

> sudo gem install dm-mapping

LICENSE:

Apache License 2.0

Copyright © 2008, Lin Jen-Shin (a.k.a. godfat 真常)

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.