Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit 066b50be5abfc2e09839dccecac9413b05a64d76 @svs committed
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'
+
48 Gemfile.lock
@@ -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.
28 README.rdoc
@@ -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
+
+```
+
25 Rakefile
@@ -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
1 VERSION
@@ -0,0 +1 @@
+1.2.1
BIN dm-pg-types-1.2.1.gem
Binary file not shown.
57 dm-pg-types.gemspec
@@ -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
47 lib/dm-pg-types.rb
@@ -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)
28 lib/dm-pg-types/decimal_array.rb
@@ -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
34 lib/dm-pg-types/hstore.rb
@@ -0,0 +1,34 @@
+require 'dm-core'
+require 'debugger'
+module DataMapper
+ class Property
+ class HStore < Object
+
+ def load(value)
+ return nil unless value
+ rv = value.split(",").map{|i| i.split("=>").map{|x| x.gsub('"','').strip}}
+ Hash[*(rv.map{|k,v| [k, v == "NULL" ? nil : v]}.flatten)]
+ end
+
+ def dump(value)
+ return "" unless value
+
+ value.map { |idx, val|
+ iv = [idx,val].map { |_|
+ e = _.to_s.gsub(/"/, '\"')
+ if _.nil?
+ 'NULL'
+ elsif e =~ /[,\s=>]/ || e.empty?
+ '"%s"' % e
+ else
+ e
+ end
+ }
+
+ "%s => %s" % iv
+ } * ","
+ end
+
+ end # class HStore
+ end # class Property
+end # module DataMapper
20 spec/fixtures/person.rb
@@ -0,0 +1,20 @@
+module DataMapper
+ module TypesFixtures
+ class Person
+ #
+ # Behaviors
+ #
+
+ include DataMapper::Resource
+
+ #
+ # Properties
+ #
+
+ property :id, Serial
+ property :name, String
+ property :other_information, HStore
+ property :numbers, DecimalArray
+ end
+ end
+end
69 spec/integration/decimal_array_spec.rb
@@ -0,0 +1,69 @@
+require 'spec_helper'
+
+require 'debugger'
+try_spec do
+
+ require './spec/fixtures/person'
+
+ describe DataMapper::TypesFixtures::Person do
+ supported_by :all do
+ before :all do
+ @resource = DataMapper::TypesFixtures::Person.new(:name => '')
+ end
+
+ describe 'with no other information' do
+ before :all do
+ @resource.numbers = nil
+ end
+
+ describe 'when dumped and loaded again' do
+ before :all do
+ @resource.save.should be(true)
+ @resource.reload
+ end
+
+ it 'has no numbers' do
+ @resource.numbers.should == nil
+ end
+ end
+ end
+
+ describe 'with no numbers information' do
+ before :all do
+ @resource.numbers = []
+ end
+
+ describe 'when dumped and loaded again' do
+ before :all do
+ debugger
+ @resource.save.should be(true)
+ @resource.reload
+ end
+
+ it 'has empty numbers list' do
+ @resource.numbers.should == []
+ end
+ end
+ end
+
+ describe 'with a few items on the numbers list' do
+ before :all do
+ @input = [10.1,11.2,12.3]
+ @resource.numbers = @input
+ end
+
+ describe 'when dumped and loaded again' do
+ before :all do
+ @resource.save.should be(true)
+ @resource.reload
+ end
+
+ it 'includes "fire" in numbers' do
+ @resource.numbers.should == [10.1,11.2,12.3]
+ end
+
+ end
+ end
+ end
+ end
+end
36 spec/integration/full_spec.rb
@@ -0,0 +1,36 @@
+require 'spec_helper'
+
+describe "dm-pg-types" do
+ before :all do
+ # Create the table manually before running this spec.
+ 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
+ @p = Person.last
+ end
+
+ it "should provide a person with info" do
+ @p.info.should == {"a" => "b", "c" => "d"}
+ end
+
+ it "should provide a person with decimals" do
+ @p.decimals.should == [10.1,11.2]
+ end
+
+end
70 spec/integration/hstore_spec.rb
@@ -0,0 +1,70 @@
+require 'spec_helper'
+
+try_spec do
+
+ require './spec/fixtures/person'
+
+ describe DataMapper::TypesFixtures::Person do
+ supported_by :all do
+ before :all do
+ @resource = DataMapper::TypesFixtures::Person.new(:name => '')
+ end
+
+ describe 'with no other information' do
+ before :all do
+ @resource.other_information = nil
+ end
+
+ describe 'when dumped and loaded again' do
+ before :all do
+ @resource.save.should be(true)
+ @resource.reload
+ end
+
+ it 'has no other_information' do
+ @resource.other_information.should == {}
+ end
+ end
+ end
+
+ describe 'with no other_information information' do
+ before :all do
+ @resource.other_information = {}
+ end
+
+ describe 'when dumped and loaded again' do
+ before :all do
+ @resource.save.should be(true)
+ @resource.reload
+ end
+
+ it 'has empty other_information list' do
+ @resource.other_information.should == {}
+ end
+ end
+ end
+
+ describe 'with a few items on the other_information list' do
+ before :all do
+ @input = {:a => 'b', :c => 'd'}
+ @resource.other_information = @input
+ end
+
+ describe 'when dumped and loaded again' do
+ before :all do
+ @resource.save.should be(true)
+ @resource.reload
+ end
+
+ it 'includes "fire" in other_information' do
+ @resource.other_information.keys.should include("a")
+ end
+
+ it 'has blank entries removed' do
+ @resource.other_information.any? { |i| DataMapper::Ext.blank?(i) }.should be(false)
+ end
+ end
+ end
+ end
+ end
+end
6 spec/rcov.opts
@@ -0,0 +1,6 @@
+--exclude "spec,^/"
+--sort coverage
+--callsites
+--xrefs
+--profile
+--text-summary
37 spec/shared/flags_shared_spec.rb
@@ -0,0 +1,37 @@
+share_examples_for "A property with flags" do
+ before :all do
+ %w[ @property_klass ].each do |ivar|
+ raise "+#{ivar}+ should be defined in before block" unless instance_variable_defined?(ivar)
+ end
+
+ @flags = [ :one, :two, :three ]
+
+ class ::User
+ include DataMapper::Resource
+ end
+
+ @property = User.property :item, @property_klass[@flags], :key => true
+ end
+
+ describe ".generated_classes" do
+ it "should cache the generated class" do
+ @property_klass.generated_classes[@flags].should_not be_nil
+ end
+ end
+
+ it "should include :flags in accepted_options" do
+ @property_klass.accepted_options.should include(:flags)
+ end
+
+ it "should respond to :generated_classes" do
+ @property_klass.should respond_to(:generated_classes)
+ end
+
+ it "should respond to :flag_map" do
+ @property.should respond_to(:flag_map)
+ end
+
+ it "should be custom" do
+ @property.custom?.should be(true)
+ end
+end
5 spec/shared/identity_function_group.rb
@@ -0,0 +1,5 @@
+describe "identity function", :shared => true do
+ it "returns value unchanged" do
+ @result.should == @input
+ end
+end
4 spec/spec.opts
@@ -0,0 +1,4 @@
+--colour
+--loadby random
+--format profile
+--backtrace
28 spec/spec_helper.rb
@@ -0,0 +1,28 @@
+require 'dm-core/spec/setup'
+require 'dm-core/spec/lib/adapter_helpers'
+
+require 'dm-types'
+require 'dm-migrations'
+require 'dm-validations'
+require 'dm-pg-types'
+
+Dir["#{Pathname(__FILE__).dirname.expand_path}/shared/*.rb"].each { |file| require file }
+
+DataMapper::Spec.setup
+
+Spec::Runner.configure do |config|
+ config.extend(DataMapper::Spec::Adapters::Helpers)
+end
+
+
+def try_spec
+ begin
+ yield
+ rescue LoadError => error
+ raise error unless lib = error.message.match(/\Ano such file to load -- (.+)\z/)[1]
+
+ gem_location = DEPENDENCIES[lib] || raise("Unknown lib #{lib}")
+
+ warn "[WARNING] Skipping specs using #{lib}, please do: gem install #{gem_location}"
+ end
+end
55 spec/unit/hstore_spec.rb
@@ -0,0 +1,55 @@
+require 'spec_helper'
+
+try_spec do
+ describe DataMapper::Property::HStore do
+ supported_by :all do
+ before :all do
+ class User
+ include DataMapper::Resource
+ property :id, Serial
+ property :doc, HStore
+ end
+
+ @property = User.properties[:doc]
+ end
+
+ describe '.load' do
+ describe "argument is a string that is an hstore document" do
+ before :all do
+ @input = '"branch_id"=>"3", "center_id"=>"5", "client_id"=>"4"'
+ @result = @property.load(@input)
+ end
+
+ it "parses the input into a hash" do
+ @result.should == {"branch_id" => "3", "center_id" => "5", "client_id" => "4"}
+ end
+
+ it "should read NULLs properly" do
+ @property.load('"a" => "3", "b" => "NULL"').should == {"a" => "3", "b" => nil}
+ end
+ end
+ end
+
+ describe ".dump" do
+ before :all do
+ @input = {:a => 1, :b => "def"}
+ @result = @property.dump(@input)
+ end
+
+ describe "when argument is a Hash" do
+ it "should result in a Hashified string" do
+ @result.should == 'a => 1,b => def'
+ end
+
+ it "should write a nil as NULL" do
+ @property.dump({:a => 1, :b => nil}).should == 'a => 1,b => NULL'
+ end
+
+ end
+ end
+
+
+
+ end
+ end
+end
43 spec/unit/pg_array_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+try_spec do
+ describe DataMapper::Property::DecimalArray do
+ supported_by :all do
+ before :all do
+ class User
+ include DataMapper::Resource
+ property :id, Serial
+ property :things, DecimalArray
+ end
+
+ @property = User.properties[:things]
+ end
+
+ describe '.load' do
+ describe "argument is a string that is a decimal array" do
+ before :all do
+ @input = '{10.1,2.3,4,5,6}'
+ @result = @property.load(@input)
+ end
+
+ it "parses the input into an array" do
+ @result.should == [10.1,2.3,4,5,6]
+ end
+ end
+ end
+
+ describe ".dump" do
+ before :all do
+ @input = [1,2,3.4,5,6]
+ @result = @property.dump(@input)
+ end
+
+ describe "when argument is a Hash" do
+ it "should result in a postgres array string" do
+ @result.should == '{1,2,3.4,5,6}'
+ end
+ end
+ end
+ end
+ end
+end
38 tasks/spec.rake
@@ -0,0 +1,38 @@
+spec_defaults = lambda do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.libs << 'lib' << 'spec'
+ spec.spec_opts << '--options' << 'spec/spec.opts'
+end
+
+begin
+ require 'spec/rake/spectask'
+
+ Spec::Rake::SpecTask.new(:spec, &spec_defaults)
+rescue LoadError
+ task :spec do
+ abort 'rspec is not available. In order to run spec, you must: gem install rspec'
+ end
+end
+
+begin
+ require 'rcov'
+ require 'spec/rake/verify_rcov'
+
+ Spec::Rake::SpecTask.new(:rcov) do |rcov|
+ spec_defaults.call(rcov)
+ rcov.rcov = true
+ rcov.rcov_opts = File.read('spec/rcov.opts').split(/\s+/)
+ end
+
+ RCov::VerifyTask.new(:verify_rcov => :rcov) do |rcov|
+ rcov.threshold = 100
+ end
+rescue LoadError
+ %w[ rcov verify_rcov ].each do |name|
+ task name do
+ abort "rcov is not available. In order to run #{name}, you must: gem install rcov"
+ end
+ end
+end
+
+task :default => :spec
9 tasks/yard.rake
@@ -0,0 +1,9 @@
+begin
+ require 'yard'
+
+ YARD::Rake::YardocTask.new
+rescue LoadError
+ task :yard do
+ abort 'YARD is not available. In order to run yard, you must: gem install yard'
+ end
+end
19 tasks/yardstick.rake
@@ -0,0 +1,19 @@
+begin
+ require 'pathname'
+ require 'yardstick/rake/measurement'
+ require 'yardstick/rake/verify'
+
+ # yardstick_measure task
+ Yardstick::Rake::Measurement.new
+
+ # verify_measurements task
+ Yardstick::Rake::Verify.new do |verify|
+ verify.threshold = 100
+ end
+rescue LoadError
+ %w[ yardstick_measure verify_measurements ].each do |name|
+ task name.to_s do
+ abort "Yardstick is not available. In order to run #{name}, you must: gem install yardstick"
+ end
+ end
+end

0 comments on commit 066b50b

Please sign in to comment.
Something went wrong with that request. Please try again.