Skip to content

Commit

Permalink
I have made rails_datamapper a gem
Browse files Browse the repository at this point in the history
  • Loading branch information
tom committed Jan 21, 2009
1 parent e7c030a commit 115af58
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 49 deletions.
3 changes: 3 additions & 0 deletions rails_datamapper/History.txt
@@ -0,0 +1,3 @@
=== 0.9.11 / not released

* Made a gem
20 changes: 20 additions & 0 deletions rails_datamapper/LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2008 Tom Malone

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 16 additions & 0 deletions rails_datamapper/Manifest.txt
@@ -0,0 +1,16 @@
History.txt
LICENSE
Manifest.txt
README.txt
Rakefile
TODO
lib/rails_datamapper.rb
lib/rails_datamapper/rails_datamapper.rb
lib/rails_datamapper/version.rb
generators/dm_model/dm_model_generator.rb
generators/dm_model/templates/migration.rb
generators/dm_model/templates/model.rb
generators/dm_model/templates/unit_test.rb
generators/rspec_dm_model/rspec_dm_model_generator.rb
generators/rspec_dm_model/templates/model.rb
generators/rspec_dm_model/templates/model_spec.rb
26 changes: 26 additions & 0 deletions rails_datamapper/README.txt
@@ -0,0 +1,26 @@
This is a Rails plugin that provides datamapper as an orm

== Setup

add the following line to your projects environment.rb

config.gem "rails_datamapper"

== Generators

Two generators are added by default

script/generate dm_model
script/generate rspec_dm_model

These by default add an active record migrations but you can call

script/generate dm_model --skip-migration
script/generate rspec_dm_model --skip-migration

To avoid any dependency on active record add this to your projects environment.rb

config.frameworks -= [ :active_record ]

== Future
I really should sort out migrations but with rails3 round the corner don't hold your breath
25 changes: 25 additions & 0 deletions rails_datamapper/Rakefile
@@ -0,0 +1,25 @@
require 'pathname'
require 'rubygems'

ROOT = Pathname(__FILE__).dirname.expand_path
JRUBY = RUBY_PLATFORM =~ /java/
WINDOWS = Gem.win_platform?
SUDO = (WINDOWS || JRUBY) ? '' : ('sudo' unless ENV['SUDOLESS'])

require ROOT + 'lib/rails_datamapper/version'

AUTHOR = 'Tom Malone'
EMAIL = 'tomjmalone [a] gmail [d] com'
GEM_NAME = 'rails_datamapper'
GEM_VERSION = DataMapper::RailsDatamapper::VERSION
GEM_DEPENDENCIES = [['dm-core', "~>#{GEM_VERSION}"]]
GEM_CLEAN = %w[ pkg ]
GEM_EXTRAS = { :has_rdoc => false, :extra_rdoc_files => %w[ README.txt LICENSE TODO History.txt ] }

PROJECT_NAME = 'datamapper'
PROJECT_URL = "http://github.com/sam/dm-more/tree/master/#{GEM_NAME}"
PROJECT_DESCRIPTION = PROJECT_SUMMARY = 'Rails Plugin for datamapper'

[ ROOT, ROOT.parent ].each do |dir|
Pathname.glob(dir.join('tasks/**/*.rb').to_s).each { |f| require f }
end
Empty file added rails_datamapper/TODO
Empty file.
4 changes: 0 additions & 4 deletions rails_datamapper/init.rb

This file was deleted.

50 changes: 5 additions & 45 deletions rails_datamapper/lib/rails_datamapper.rb
@@ -1,45 +1,5 @@
def config_file()
Rails.root + "/config/database.yml"
end

def create_connection()
conf = config.dup
repositories = conf.delete(:repositories)
::DataMapper.setup(:default, conf) unless conf.empty?
end

def get_config_for_environment
if hash = full_config[RAILS_ENV]
symbolize_keys(hash)
elsif hash = full_config[RAILS_ENV.to_sym]
hash
else
raise ArgumentError, "missing environment '#{RAILS_ENV}' in config file #{config_file}"
end
end

def full_config
@full_config ||= YAML::load(ERB.new(IO.read(config_file)).result)
end

def config
@config ||= get_config_for_environment
end

def symbolize_keys(h)
config = {}

h.each do |k, v|
if k == 'port'
config[k.to_sym] = v.to_i
elsif k == 'adapter' && v == 'postgresql'
config[k.to_sym] = 'postgres'
elsif v.is_a?(Hash)
config[k.to_sym] = symbolize_keys(v)
else
config[k.to_sym] = v
end
end

config
end
gem 'dm-core', '~>0.9.11'
require 'pathname'
require 'dm-core'
require Pathname(__FILE__).dirname.expand_path / 'rails_datamapper/rails_datamapper'
create_connection()
45 changes: 45 additions & 0 deletions rails_datamapper/lib/rails_datamapper/rails_datamapper.rb
@@ -0,0 +1,45 @@
def config_file()
Rails.root + "/config/database.yml"
end

def create_connection()
conf = config.dup
repositories = conf.delete(:repositories)
::DataMapper.setup(:default, conf) unless conf.empty?
end

def get_config_for_environment
if hash = full_config[RAILS_ENV]
symbolize_keys(hash)
elsif hash = full_config[RAILS_ENV.to_sym]
hash
else
raise ArgumentError, "missing environment '#{RAILS_ENV}' in config file #{config_file}"
end
end

def full_config
@full_config ||= YAML::load(ERB.new(IO.read(config_file)).result)
end

def config
@config ||= get_config_for_environment
end

def symbolize_keys(h)
config = {}

h.each do |k, v|
if k == 'port'
config[k.to_sym] = v.to_i
elsif k == 'adapter' && v == 'postgresql'
config[k.to_sym] = 'postgres'
elsif v.is_a?(Hash)
config[k.to_sym] = symbolize_keys(v)
else
config[k.to_sym] = v
end
end

config
end
5 changes: 5 additions & 0 deletions rails_datamapper/lib/rails_datamapper/version.rb
@@ -0,0 +1,5 @@
module DataMapper
module RailsDatamapper
VERSION = '0.9.11'
end
end
13 changes: 13 additions & 0 deletions rails_datamapper/tasks/install.rb
@@ -0,0 +1,13 @@
def sudo_gem(cmd)
sh "#{SUDO} #{RUBY} -S gem #{cmd}", :verbose => false
end

desc "Install #{GEM_NAME} #{GEM_VERSION}"
task :install => [ :package ] do
sudo_gem "install --local pkg/#{GEM_NAME}-#{GEM_VERSION} --no-update-sources"
end

desc "Uninstall #{GEM_NAME} #{GEM_VERSION}"
task :uninstall => [ :clobber ] do
sudo_gem "uninstall #{GEM_NAME} -v#{GEM_VERSION} -Ix"
end

0 comments on commit 115af58

Please sign in to comment.