Permalink
Browse files

Remove cramp/model and move it to a new gem called tramp - http://git…

  • Loading branch information...
1 parent c8e125d commit 8c84041caff2e05094db6644b33ac4fde4566502 @lifo committed Jul 17, 2010
View
10 Gemfile
@@ -1,14 +1,10 @@
source 'http://rubygems.org'
-gem "cramp", :path => File.dirname(__FILE__)
+gem 'cramp', :path => File.dirname(__FILE__)
gem 'activesupport', '3.0.0.beta4'
-gem 'activemodel', '3.0.0.beta4'
-
-gem "arel", '>= 0.4.0'
-gem "rack", "1.1.0"
-gem "mysqlplus", "0.1.1"
-gem "eventmachine", "0.12.10"
+gem 'rack', '~> 1.1.0'
+gem 'eventmachine', '~> 0.12.10'
group :test do
gem 'usher'
View
@@ -8,21 +8,4 @@ Rake::TestTask.new(:test) do |t|
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
-Rake::Task['test'].comment = "Run model and controller tests"
-
-namespace :test do
- Rake::TestTask.new(:controller) do |t|
- t.libs << "test"
- t.pattern = 'test/controller/**/*_test.rb'
- t.verbose = true
- end
- Rake::Task['test:controller'].comment = "Run controller tests"
-
- Rake::TestTask.new(:model) do |t|
- t.libs << "test"
- t.pattern = 'test/model/**/*_test.rb'
- t.verbose = true
- end
- Rake::Task['test:model'].comment = "Run model tests"
-end
-
+Rake::Task['test'].comment = "Run tests"
View
@@ -2,20 +2,15 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.name = 'cramp'
s.version = '0.10'
- s.summary = "Async ORM and controller layer."
- s.description = <<-EOF
- Cramp provides ORM and controller layers for developing asynchronous web applications.
- EOF
+ s.summary = 'Asynchronous web framework.'
+ s.description = 'Cramp is a framework for developing asynchronous web applications.'
- s.author = "Pratik Naik"
- s.email = "pratiknaik@gmail.com"
- s.homepage = "http://m.onkey.org"
+ s.author = 'Pratik Naik'
+ s.email = 'pratiknaik@gmail.com'
+ s.homepage = 'http://m.onkey.org'
s.add_dependency('activesupport', '~> 3.0.0.beta4')
- s.add_dependency('activemodel', '~> 3.0.0.beta4')
- s.add_dependency('arel', '~> 0.4.0')
s.add_dependency('rack', '~> 1.1.0')
- s.add_dependency('mysqlplus', '~> 0.1.1')
s.add_dependency('eventmachine', '~> 0.12.10')
s.files = Dir['README', 'MIT-LICENSE', 'lib/**/*']
View
@@ -1,40 +0,0 @@
-require 'cramp'
-require 'cramp/model/evented_mysql'
-require 'cramp/model/emysql_ext'
-
-require 'mysqlplus'
-
-require 'arel'
-require 'cramp/model/arel_monkey_patches'
-
-require 'active_model'
-
-module Cramp
- module Model
- autoload :Quoting, "cramp/model/quoting"
- autoload :Engine, "cramp/model/engine"
- autoload :Column, "cramp/model/column"
- autoload :Relation, "cramp/model/relation"
-
- autoload :Base, "cramp/model/base"
- autoload :Finders, "cramp/model/finders"
- autoload :Attribute, "cramp/model/attribute"
- autoload :AttributeMethods, "cramp/model/attribute_methods"
- autoload :Status, "cramp/model/status"
- autoload :Callbacks, "cramp/model/callbacks"
-
- def self.init(settings)
- Arel::Table.engine = Cramp::Model::Engine.new(settings)
- end
-
- def self.select(query, callback = nil, &block)
- callback ||= block
-
- EventedMysql.select(query) do |rows|
- callback.arity == 1 ? callback.call(rows) : callback.call if callback
- end
- end
-
- end
-end
-
@@ -1,66 +0,0 @@
-class Arel::Session
- def create(insert, &block)
- insert.call(&block)
- end
-
- def read(select, &block)
- select.call(&block)
- end
-
- def update(update, &block)
- update.call(&block)
- end
-
- def delete(delete, &block)
- delete.call(&block)
- end
-
-end
-
-module Arel::Relation
- def call(&block)
- engine.read(self, &block)
- end
-
- def all(&block)
- session.read(self) {|rows| block.call(rows) }
- end
-
- def first(&block)
- session.read(self) {|rows| block.call(rows[0]) }
- end
-
- def each(&block)
- session.read(self) {|rows| rows.each {|r| block.call(r) } }
- end
-
- def insert(record, &block)
- session.create(Arel::Insert.new(self, record), &block)
- end
-
- def update(assignments, &block)
- session.update(Arel::Update.new(self, assignments), &block)
- end
-
- def delete(&block)
- session.delete(Arel::Deletion.new(self), &block)
- end
-end
-
-class Arel::Deletion
- def call(&block)
- engine.delete(self, &block)
- end
-end
-
-class Arel::Insert
- def call(&block)
- engine.create(self, &block)
- end
-end
-
-class Arel::Update
- def call(&block)
- engine.update(self, &block)
- end
-end
@@ -1,104 +0,0 @@
-# Copyright (c) 2009 Koziarski Software Ltd
-#
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-module Cramp
- module Model
- class Attribute
-
- FORMATS = {}
- FORMATS[Date] = /^\d{4}\/\d{2}\/\d{2}$/
- FORMATS[Integer] = /^-?\d+$/
- FORMATS[Float] = /^-?\d*\.\d*$/
- FORMATS[Time] = /\A\s*
- -?\d+-\d\d-\d\d
- T
- \d\d:\d\d:\d\d
- (\.\d*)?
- (Z|[+-]\d\d:\d\d)?
- \s*\z/ix # lifted from the implementation of Time.xmlschema
-
- CONVERTERS = {}
- CONVERTERS[Date] = Proc.new do |str|
- Date.strptime(str, "%Y/%m/%d")
- end
-
- CONVERTERS[Integer] = Proc.new do |str|
- Integer(str)
- end
-
- CONVERTERS[Float] = Proc.new do |str|
- Float(str)
- end
-
- CONVERTERS[Time] = Proc.new do |str|
- Time.xmlschema(str)
- end
-
- attr_reader :name
- def initialize(name, owner_class, options)
- @name = name.to_s
- @owner_class = owner_class
- @options = options
-
- # append_validations!
- define_methods!
- end
-
- # I think this should live somewhere in Amo
- def check_value!(value)
- # Allow nil and Strings to fall back on the validations for typecasting
- # Everything else gets checked with is_a?
- if value.nil?
- nil
- elsif value.is_a?(String)
- value
- elsif value.is_a?(expected_type)
- value
- else
- raise TypeError, "Expected #{expected_type.inspect} but got #{value.inspect}"
- end
- end
-
- def expected_type
- @options[:type] || String
- end
-
- def type_cast(value)
- if value.is_a?(expected_type)
- value
- elsif (converter = CONVERTERS[expected_type]) && (value =~ FORMATS[expected_type])
- converter.call(value)
- else
- value
- end
- end
-
- def append_validations!
- if f = FORMATS[expected_type]
- @owner_class.validates_format_of @name, :with => f, :unless => lambda {|obj| obj.send(name).is_a? expected_type }, :allow_nil => @options[:allow_nil]
- end
- end
-
- def define_methods!
- @owner_class.define_attribute_methods(true)
- end
-
- def primary_key?
- @options[:primary_key]
- end
-
- end
-
- end
-end
@@ -1,83 +0,0 @@
-# Copyright (c) 2009 Koziarski Software Ltd
-#
-# Permission to use, copy, modify, and/or distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-
-module Cramp
- module Model
- module AttributeMethods
-
- extend ActiveSupport::Concern
- include ActiveModel::AttributeMethods
-
- module ClassMethods
- def attribute(name, options = {})
- write_inheritable_hash(:model_attributes, {name => Attribute.new(name, self, options)})
- end
-
- def define_attribute_methods(force = false)
- return unless model_attributes
- undefine_attribute_methods if force
- super(model_attributes.keys)
- end
- end
-
- included do
- class_inheritable_hash :model_attributes
- undef_method(:id) if method_defined?(:id)
-
- attribute_method_suffix("", "=")
- end
-
- def write_attribute(name, value)
- if ma = self.class.model_attributes[name.to_sym]
- value = ma.check_value!(value)
- end
- if(@attributes[name] != value)
- send "#{name}_will_change!".to_sym
- @attributes[name] = value
- end
- end
-
- def read_attribute(name)
- if ma = self.class.model_attributes[name]
- ma.type_cast(@attributes[name])
- else
- @attributes[name]
- end
- end
-
- def attributes=(attributes)
- attributes.each do |(name, value)|
- send("#{name}=", value)
- end
- end
-
- protected
-
- def attribute_method?(name)
- @attributes.include?(name.to_sym) || model_attributes[name.to_sym]
- end
-
- private
-
- def attribute(name)
- read_attribute(name.to_sym)
- end
-
- def attribute=(name, value)
- write_attribute(name.to_sym, value)
- end
-
- end
- end
-end
Oops, something went wrong.

0 comments on commit 8c84041

Please sign in to comment.