Skip to content

Commit

Permalink
updated for dm-1.1 support, version bump! it's been a while
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmattking committed Jul 1, 2011
1 parent c9b44c9 commit 2f7e856
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 16 deletions.
5 changes: 5 additions & 0 deletions lib/togo.rb
Expand Up @@ -8,5 +8,10 @@ def self.models

end

begin
require 'extlib'
rescue
require 'active_support'
end
require 'togo/model'
require 'togo/support'
4 changes: 2 additions & 2 deletions lib/togo/admin/admin.rb
Expand Up @@ -62,12 +62,12 @@ class Admin < Dispatch
end

get '/edit/:model/:id' do
@content = @model.get(params[:id])
@content = @model.first(:id => params[:id].to_i)
erb :edit
end

post '/update/:model/:id' do
@content = @model.stage_content(@model.get(params[:id]),params)
@content = @model.stage_content(@model.first(:id => params[:id].to_i),params)
begin
raise "Could not save content" if not @content.save
redirect params[:return_url] || "/#{@model.name}"
Expand Down
2 changes: 1 addition & 1 deletion lib/togo/dispatch/dispatch.rb
Expand Up @@ -30,7 +30,7 @@ def initialize(opts = {})
@view_path = opts[:view_path] || 'views'
@path_prefix = opts[:path_prefix]
@path_prefix_regexp = Regexp.new("^#{@path_prefix}")
ENV['RACK_ENV'] = (opts[:environment] || :development) if not ENV['RACK_ENV']
#ENV['RACK_ENV'] = (opts[:environment] || :development) if not ENV['RACK_ENV']
end

def symbolize_keys(hash)
Expand Down
16 changes: 8 additions & 8 deletions lib/togo/model/model.rb
Expand Up @@ -50,7 +50,7 @@ def form_for(property,content,opts = {})
end

def update_content!(id,attrs)
stage_content(get(id),attrs).save
stage_content(first(:id => id),attrs).save
end

def create_content!(attrs)
Expand All @@ -59,8 +59,8 @@ def create_content!(attrs)

def stage_content(content,attrs)
content.attributes = properties.inject({}){|m,p| attrs[p.name.to_sym] ? m.merge!(p.name.to_sym => attrs[p.name.to_sym]) : m}
relationships.each do |r|
val = attrs["related_#{r[0]}".to_sym]
relationships.each do |r|
val = attrs["related_#{r.name}".to_sym]
next if not val or val == 'unset'
content = RelationshipManager.create(content, r, :ids => val).relate
end
Expand Down Expand Up @@ -126,7 +126,7 @@ def type_from_property(property)
when ::DataMapper::Associations::OneToMany::Relationship
'has_n'
when ::DataMapper::Property
class_variable_get(:@@inflector).demodulize(property.type || property.class).downcase # type seems to be deprecated in 1.0
class_variable_get(:@@inflector).demodulize(property.class).downcase # type seems to be deprecated in 1.0
else
'string'
end
Expand Down Expand Up @@ -163,18 +163,18 @@ def pick_properties(selection, args)
end

def shown_properties
skip = relationships.values.collect{|r| r.through if r.respond_to?(:through) }.compact.uniq # don't include join models
properties.select{|p| not BLACKLIST.include?(p.name) and not p.name =~ /_id$/} + relationships.values.select{|r| not skip.include?(r)}
skip = relationships.to_a.collect{|r| r.through if r.respond_to?(:through) }.compact.uniq # don't include join models
properties.select{|p| not BLACKLIST.include?(p.name) and not p.name =~ /_id$/} + relationships.to_a.select{|r| not skip.include?(r)}
end

def search_properties
# Support dm 0.10.x and 1.x by checking for deprecated(?) types
only_properties = [String, ::DataMapper::Types::Text]
only_properties = [String]
begin # rescue exception when not using dm-core 1.0, these don't exist in the 0.10.x series
only_properties.concat([::DataMapper::Property::String, ::DataMapper::Property::Text])
rescue
end
properties.select{|p| only_properties.include?(p.type || p.class)} # type seems to be depracated in 1.0
properties.select{|p| only_properties.include?(p.class)} # type seems to be depracated in 1.0
end

end
Expand Down
6 changes: 3 additions & 3 deletions lib/togo/model/relationship_manager/relationship_manager.rb
Expand Up @@ -3,7 +3,7 @@ module DataMapper
class RelationshipManager

def self.create(content, relationship, opts = {})
case relationship[1]
case relationship
when ::DataMapper::Associations::ManyToOne::Relationship
ManyToOne.new(content, relationship, opts)
when ::DataMapper::Associations::OneToMany::Relationship
Expand All @@ -13,8 +13,8 @@ def self.create(content, relationship, opts = {})

def initialize(content, relationship, opts = {})
@content = content
@relationship = relationship[1]
@relationship_name = relationship[0]
@relationship = relationship
@relationship_name = relationship.name
@ids = (opts[:ids] || '').split(',').map(&:to_i)
end

Expand Down
Binary file modified spec/admin/admin.db
Binary file not shown.
1 change: 1 addition & 0 deletions spec/admin/helper.rb
@@ -1,6 +1,7 @@
$TESTING=true
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib','togo')
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib','togo','admin')
%w(do_sqlite3 togo togo/admin rack rack/test dm-core dm-serializer dm-migrations).each{|l| require l}
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/admin.db")

Expand Down
Binary file modified spec/model/model.db
Binary file not shown.
4 changes: 2 additions & 2 deletions togo.gemspec
Expand Up @@ -2,8 +2,8 @@ require 'rake/gempackagetask'

Gem::Specification.new do |s|
s.name = %q{togo}
s.version = "0.6.4"
s.date = %q{2010-11-21}
s.version = "0.7.0"
s.date = %q{2011-06-30}
s.authors = ["Matt King"]
s.email = %q{matt@mking.me}
s.summary = %q{CMS Framework for Ruby ORMs}
Expand Down

0 comments on commit 2f7e856

Please sign in to comment.