Permalink
Browse files

initial commit

  • Loading branch information...
svs committed May 22, 2012
0 parents commit 066b50be5abfc2e09839dccecac9413b05a64d76
1 .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.3@dm-pg-types
20 Gemfile
@@ -0,0 +1,20 @@
+require 'pathname'
+
+source 'http://rubygems.org'
+
+DM_VERSION = '~> 1.2.0'
+DO_VERSION = '~> 0.10.6'
+
+gem 'dm-core', DM_VERSION
+gem 'dm-migrations', DM_VERSION
+gem 'dm-types', DM_VERSION
+
+gem 'data_objects', DO_VERSION
+gem 'do_postgres', DO_VERSION
+
+gem 'dm-do-adapter', DM_VERSION
+gem 'dm-postgres-adapter', DM_VERSION
+
+gem 'rake', '~> 0.9.2'
+gem 'rspec', '~> 1.3.2'
+
@@ -0,0 +1,48 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ addressable (2.2.8)
+ bcrypt-ruby (3.0.1)
+ data_objects (0.10.8)
+ addressable (~> 2.1)
+ dm-core (1.2.0)
+ addressable (~> 2.2.6)
+ dm-do-adapter (1.2.0)
+ data_objects (~> 0.10.6)
+ dm-core (~> 1.2.0)
+ dm-migrations (1.2.0)
+ dm-core (~> 1.2.0)
+ dm-postgres-adapter (1.2.0)
+ dm-do-adapter (~> 1.2.0)
+ do_postgres (~> 0.10.6)
+ dm-types (1.2.1)
+ bcrypt-ruby (~> 3.0.0)
+ dm-core (~> 1.2.0)
+ fastercsv (~> 1.5.4)
+ json (~> 1.6.1)
+ multi_json (~> 1.0.3)
+ stringex (~> 1.3.0)
+ uuidtools (~> 2.1.2)
+ do_postgres (0.10.8)
+ data_objects (= 0.10.8)
+ fastercsv (1.5.5)
+ json (1.6.7)
+ multi_json (1.0.4)
+ rake (0.9.2.2)
+ rspec (1.3.2)
+ stringex (1.3.3)
+ uuidtools (2.1.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ data_objects (~> 0.10.6)
+ dm-core (~> 1.2.0)
+ dm-do-adapter (~> 1.2.0)
+ dm-migrations (~> 1.2.0)
+ dm-postgres-adapter (~> 1.2.0)
+ dm-types (~> 1.2.0)
+ do_postgres (~> 0.10.6)
+ rake (~> 0.9.2)
+ rspec (~> 1.3.2)
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2011 Sam Smoot, Dan Kubb
+
+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.
@@ -0,0 +1,28 @@
+= dm-pg-types
+
+DataMapper plugin providing support for PostgreSQL's HSTORE and ARRAY types. An example will suffice
+
+```ruby
+DataMapper.setup(:default, 'postgres://svs@localhost/dm_pg_types_person')
+DataMapper.repository(:default).adapter.execute("DROP TABLE IF EXISTS people")
+DataMapper.repository(:default).adapter.execute("CREATE EXTENSION HSTORE")
+
+class Person
+ include DataMapper::Resource
+
+ property :id, Serial
+ property :name, String
+ property :info, HStore
+ property :decimals, DecimalArray, :scale => 5, :precision => 10
+end
+
+DataMapper.finalize
+DataMapper.auto_migrate!
+
+p = Person.new
+p.info = {:a => "b", :c => "d"}
+p.decimals = [10.1, 11.2]
+p.save
+
+```
+
@@ -0,0 +1,25 @@
+require 'rubygems'
+require 'rake'
+
+begin
+ gem 'jeweler', '~> 1.6.4'
+ require 'jeweler'
+
+ Jeweler::Tasks.new do |gem|
+ gem.name = 'dm-types'
+ gem.summary = 'DataMapper plugin providing extra data types'
+ gem.description = gem.summary
+ gem.email = 'dan.kubb [a] gmail [d] com'
+ gem.homepage = 'http://github.com/datamapper/%s' % gem.name
+ gem.authors = [ 'Dan Kubb' ]
+ gem.has_rdoc = 'yard'
+
+ gem.rubyforge_project = 'datamapper'
+ end
+
+ Jeweler::GemcutterTasks.new
+
+ FileList['tasks/**/*.rake'].each { |task| import task }
+rescue LoadError
+ puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler -v 1.6.4'
+end
@@ -0,0 +1 @@
+1.2.1
Binary file not shown.
@@ -0,0 +1,57 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "dm-pg-types"
+ s.version = "1.2.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["svs"]
+ s.date = "2011-10-24"
+ s.description = "DataMapper plugin providing extra data types"
+ s.email = "svs [a] svs [d] io"
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.rdoc"
+ ]
+ s.files = [
+ "Gemfile",
+ "LICENSE",
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "dm-pg-types.gemspec",
+ "lib/dm-pg-types.rb",
+ "lib/dm-pg-types/hstore.rb",
+ "lib/dm-pg-types/decimal_array.rb"
+ ]
+ s.homepage = "http://github.com/svs/dm-pg-types"
+ s.require_paths = ["lib"]
+ s.rubyforge_project = "dm-pg-types"
+ s.rubygems_version = "1.8.10"
+ s.summary = "DataMapper plugin providing extra data types for postgres hstore and array types"
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.2.0"])
+ s.add_development_dependency(%q<dm-validations>, ["~> 1.2.0"])
+ s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
+ s.add_development_dependency(%q<rspec>, ["~> 1.3.2"])
+ else
+ s.add_dependency(%q<dm-core>, ["~> 1.2.0"])
+ s.add_dependency(%q<dm-validations>, ["~> 1.2.0"])
+ s.add_dependency(%q<rake>, ["~> 0.9.2"])
+ s.add_dependency(%q<rspec>, ["~> 1.3.2"])
+ end
+ else
+ s.add_dependency(%q<dm-core>, ["~> 1.2.0"])
+ s.add_dependency(%q<dm-validations>, ["~> 1.2.0"])
+ s.add_dependency(%q<rake>, ["~> 0.9.2"])
+ s.add_dependency(%q<rspec>, ["~> 1.3.2"])
+ end
+end
+
100 exit
@@ -0,0 +1,100 @@
+l.holidays
+l.id
+l.payments.destroy!
+c
+DateTime.now
+DateTime.now.strftime('%Y-%m-%d %H:%M:%S')
+repository.adapter.execute("update payments set deleted_at='#{DateTime.now.strftime('%Y-%m-%d %H:%M:%S')}' where loan_id = 28202 and type in (1,2)")
+l = Loan.get 28202
+l = Loan.get 28204
+l = Loan.get 31187
+l._show_his
+LoanHistory.all(:status => :repaid).aggregate(:loan_id)
+Time.now
+Time.now.hour
+Time.now.hourexit
+File.read("log/upgrade-29020")
+f = File.read("log/upgrade-29020")
+f.scan(/\d+/\s-/)
+f.scan(/\d+\s-/)
+f.scan(/\d+/)
+f.scan(/\d+\s\-\s/)
+f.scan(/\d+\s/)
+f.scan(/\d+\s/).map(&:to_i)
+l = Loan.get 5513
+c.center = Center.ger(c.center_id)
+l.save
+c.center
+c.client_center_memberships
+l.loan_center_memberships
+l.reload
+l.center
+l = Loan.get 55513
+u = User.first
+u.role
+u.role = "admin"
+l = Loan.get 54612
+c = l.client
+c.center = Center.get(c.center_id)
+c.save
+c.errors
+c.save!
+l.send(:set_center)
+l.save!
+l.update_history
+Math.log(0.00001) / Math.log(10)
+Math.log(0.000001) / Math.log(10)
+(Math.log(0.000001) / Math.log(10)).round(0)
+cd 1
+show-source round
+n = 61.53846153846154
+n / 100000
+n / 0.000001
+(n / 0.000001).round
+(n / 0.000001).round * 0.000001
+((n / 0.000001).round * 0.000001).round(6)
+100.round(2)
+100.send(:round,2)
+d = DigiDocument.new
+d.errors
+d.document_type = "receipt"
+d.user = User.first
+d.valid?
+d.save
+d.receipt
+u = User.new(:name => 'abc', :password => 'secret', :password_confirmation => 'secret', :role => 'customer')
+u.errors
+u.email => "abc@def.com"
+u.email = "abc@def.com"
+u.save
+require 'factory_girl_rails'
+require 'spec/factories.rb'
+`pwd`
+Factory.define do
+require 'spec/factories'
+DatabaseCleaner.strategy = :truncation
+DatabaseCleaner.orm = "mongoid"
+DatabaseCleaner.clean
+FactoryGirl.define do
+ sequence(:email) { |n| "my_email@example#{n}.com" }
+ sequence(:staff_email) { |n| "my_staff_email@example#{n}.com" }
+ sequence(:org_name) { |n| ["Bhimji Notandas","Westside","Lifestyle","Shoppers Stop","Spencers","What Katy Did"][n%5] + " #{n}"}
+ sequence(:receipt_title) { |n| ["","shopping", "nothing","jlt"][n%3] + " #{n}" }
+ factory :user do
+ name 'Test User'
+ password 'secret'
+ email
+ factory :customer do
+ role "customer"
+ email
+ end
+ end
+end
+FactoryGirl.create(:user)
+FactoryGirl.create(:customer)
+{:a => 1, :b => 2}.include?({:a => 1})
+{:a => 1, :b => 2}.include?(:a => 1)
+{:a => 1, :b => 2}.include?([:a,1])
+{:a => 1, :b => 2}.include?(:a,1)
+{:a => 1, :b => 2}.keys.include?(:a)
+exit
@@ -0,0 +1,47 @@
+require 'dm-core'
+require 'dm-migrations'
+require 'dm-types'
+require 'dm-postgres-adapter'
+
+module DataMapper
+ class Property
+ autoload :HStore, 'dm-pg-types/hstore'
+ autoload :DecimalArray, 'dm-pg-types/decimal_array'
+ end
+
+ module Migrations
+ module PostgresAdapter
+ def property_schema_hash(property)
+ schema = super
+
+ if property.kind_of?(Property::DecimalArray)
+ schema[:primitive] = "#{schema[:primitive]}(#{property.precision},#{property.scale})[]"
+ schema[:precision] = schema[:scale] = nil
+ end
+ schema
+ end
+ end
+ end
+
+ module PgTypes
+ def self.included(base)
+ base.extend ClassMethods
+ end
+
+ module ClassMethods
+ # Types for PostgreSQL databases.
+ #
+ # @return [Hash] types for PostgreSQL databases.
+ #
+ # @api private
+ def type_map
+ super.merge(
+ Property::HStore => {:primitive => 'HSTORE'},
+ Property::DecimalArray => {:primitive => "NUMERIC"}
+ ).freeze
+ end
+ end
+ end
+end
+
+DataMapper::Adapters::PostgresAdapter.send(:include,DataMapper::PgTypes)
@@ -0,0 +1,28 @@
+require 'dm-core'
+module DataMapper
+ class Property
+ class DecimalArray < Object
+ accept_options :precision, :scale, :min, :max
+ attr_reader :precision, :scale, :min, :max
+
+ def initialize(model, name, options = {})
+ super
+ @precision = @options.fetch(:precision)
+ @scale = @options.fetch(:scale)
+
+ unless @precision > 0
+ raise ArgumentError, "precision must be greater than 0, but was #{@precision.inspect}"
+ end
+ end
+
+
+ def load(value)
+ value.gsub(/[{}]/,'').split(",").map(&:to_f) if value
+ end
+
+ def dump(value)
+ "{#{value.join(",")}}" if value
+ end
+ end # class DecimalArray
+ end # class Property
+end # module DataMapper
Oops, something went wrong.

0 comments on commit 066b50b

Please sign in to comment.