mm-money 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ announcement.txt
2
+ coverage
3
+ doc
4
+ pkg
5
+
@@ -0,0 +1,4 @@
1
+ == 1.0.0 / 2010-07-03
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
@@ -0,0 +1,51 @@
1
+ mm-money
2
+ by Toni Tuominen
3
+ http://github.com/tjtuom/mm-money
4
+
5
+ == DESCRIPTION:
6
+
7
+ Handle money keys with MongoMapper.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ Defines to_mongo and from_mongo methods for the Money gem (http://money.rubyforge.org).
12
+ Stores the currency along with the value in the database.
13
+
14
+ == SYNOPSIS:
15
+
16
+ class Foo
17
+ key :value, Money
18
+ end
19
+
20
+ == REQUIREMENTS:
21
+
22
+ The Money gem.
23
+
24
+ == INSTALL:
25
+
26
+ gem install mm-money
27
+
28
+ == LICENSE:
29
+
30
+ (The MIT License)
31
+
32
+ Copyright (c) 2010
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining
35
+ a copy of this software and associated documentation files (the
36
+ 'Software'), to deal in the Software without restriction, including
37
+ without limitation the rights to use, copy, modify, merge, publish,
38
+ distribute, sublicense, and/or sell copies of the Software, and to
39
+ permit persons to whom the Software is furnished to do so, subject to
40
+ the following conditions:
41
+
42
+ The above copyright notice and this permission notice shall be
43
+ included in all copies or substantial portions of the Software.
44
+
45
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
46
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
47
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
48
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
49
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
50
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
51
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,23 @@
1
+ begin
2
+ require 'bones'
3
+ rescue LoadError
4
+ abort '### Please install the "bones" gem ###'
5
+ end
6
+
7
+ task :default => 'test:run'
8
+ task 'gem:release' => 'spec:run'
9
+
10
+ Bones {
11
+ name 'mm-money'
12
+ authors 'Toni Tuominen'
13
+ email 'toni@piranhadigital.fi'
14
+ url 'http://github.com/tjtuom/mm-money'
15
+
16
+ ignore_file '.gitignore'
17
+
18
+ depend_on 'money', '3.0.4'
19
+
20
+ depend_on 'mongo_mapper', '0.8.2', :development => true
21
+ depend_on 'rspec', '1.3.0', :development => true
22
+ }
23
+
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'money'
3
+
4
+ class Money
5
+ def self.to_mongo(value)
6
+ value = if value.instance_of? Money
7
+ value
8
+ elsif value.kind_of? Numeric
9
+ value.to_money
10
+ elsif value.kind_of? String
11
+ value.to_money
12
+ end
13
+
14
+ unless value.nil?
15
+ value.format(:with_currency => true)
16
+ else
17
+ nil
18
+ end
19
+ end
20
+
21
+ def self.from_mongo(value)
22
+ if value.instance_of? Money
23
+ value
24
+ elsif value.kind_of? Numeric
25
+ value.to_money
26
+ elsif value.kind_of? String
27
+ value.to_money
28
+ else
29
+ nil
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{mm-money}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Toni Tuominen"]
9
+ s.date = %q{2010-07-04}
10
+ s.description = %q{Handle money keys with MongoMapper.}
11
+ s.email = %q{toni@piranhadigital.fi}
12
+ s.extra_rdoc_files = ["History.txt", "README.txt", "version.txt"]
13
+ s.files = [".gitignore", "History.txt", "README.txt", "Rakefile", "lib/mm-money.rb", "spec/log/spec.log", "spec/mm-money_spec.rb", "spec/spec_helper.rb", "version.txt"]
14
+ s.homepage = %q{http://github.com/tjtuom/mm-money}
15
+ s.rdoc_options = ["--main", "README.txt"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{mm-money}
18
+ s.rubygems_version = %q{1.3.6}
19
+ s.summary = %q{Handle money keys with MongoMapper}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_runtime_dependency(%q<money>, [">= 3.0.4"])
27
+ s.add_development_dependency(%q<mongo_mapper>, [">= 0.8.2"])
28
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
29
+ s.add_development_dependency(%q<bones>, [">= 3.4.3"])
30
+ else
31
+ s.add_dependency(%q<money>, [">= 3.0.4"])
32
+ s.add_dependency(%q<mongo_mapper>, [">= 0.8.2"])
33
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
34
+ s.add_dependency(%q<bones>, [">= 3.4.3"])
35
+ end
36
+ else
37
+ s.add_dependency(%q<money>, [">= 3.0.4"])
38
+ s.add_dependency(%q<mongo_mapper>, [">= 0.8.2"])
39
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
40
+ s.add_dependency(%q<bones>, [">= 3.4.3"])
41
+ end
42
+ end
@@ -0,0 +1,69 @@
1
+ # Logfile created on Sun Jul 04 10:28:58 +0300 2010 by logger.rb/22285
2
+ MONGODB admin['$cmd'].find({:ismaster=>1}, {}).limit(-1)
3
+ MONGODB mm-money-test-1-8-7['system.namespaces'].find({}, {})
4
+ MONGODB mm-money-test-1-8-7['products'].remove({})
5
+ MONGODB mm-money-test-1-8-7['system.indexes'].remove({})
6
+ MONGODB mm-money-test-1-8-7['products'].remove({})
7
+ MONGODB mm-money-test-1-8-7['products'].remove({})
8
+ MONGODB mm-money-test-1-8-7['products'].remove({})
9
+ MONGODB mm-money-test-1-8-7['products'].remove({})
10
+ MONGODB mm-money-test-1-8-7['products'].remove({})
11
+ MONGODB mm-money-test-1-8-7['products'].remove({})
12
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30383a0e9dab57f0000006')}, {"price"=>"$10.00 USD", "_id"=>BSON::ObjectID('4c30383a0e9dab57f0000006')})
13
+ MONGODB mm-money-test-1-8-7['products'].find({}, {}).limit(-1)
14
+ MONGODB mm-money-test-1-8-7['products'].remove({})
15
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30383a0e9dab57f0000007')}, {"price"=>"€10.00 EUR", "_id"=>BSON::ObjectID('4c30383a0e9dab57f0000007')})
16
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30383a0e9dab57f0000008')}, {"price"=>"€30.00 EUR", "_id"=>BSON::ObjectID('4c30383a0e9dab57f0000008')})
17
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30383a0e9dab57f0000009')}, {"price"=>"€20.00 EUR", "_id"=>BSON::ObjectID('4c30383a0e9dab57f0000009')})
18
+ MONGODB mm-money-test-1-8-7['products'].find({}, {}).sort([["price", 1]])
19
+ MONGODB admin['$cmd'].find({:ismaster=>1}, {}).limit(-1)
20
+ MONGODB mm-money-test-1-8-7['system.namespaces'].find({}, {})
21
+ MONGODB mm-money-test-1-8-7['products'].remove({})
22
+ MONGODB mm-money-test-1-8-7['system.indexes'].remove({})
23
+ MONGODB mm-money-test-1-8-7['products'].remove({})
24
+ MONGODB mm-money-test-1-8-7['products'].remove({})
25
+ MONGODB mm-money-test-1-8-7['products'].remove({})
26
+ MONGODB mm-money-test-1-8-7['products'].remove({})
27
+ MONGODB mm-money-test-1-8-7['products'].remove({})
28
+ MONGODB mm-money-test-1-8-7['products'].remove({})
29
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c3039180e9dab5d86000006')}, {"price"=>"$10.00 USD", "_id"=>BSON::ObjectID('4c3039180e9dab5d86000006')})
30
+ MONGODB mm-money-test-1-8-7['products'].find({}, {}).limit(-1)
31
+ MONGODB mm-money-test-1-8-7['products'].remove({})
32
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c3039180e9dab5d86000007')}, {"price"=>"€10.00 EUR", "_id"=>BSON::ObjectID('4c3039180e9dab5d86000007')})
33
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c3039180e9dab5d86000008')}, {"price"=>"€30.00 EUR", "_id"=>BSON::ObjectID('4c3039180e9dab5d86000008')})
34
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c3039180e9dab5d86000009')}, {"price"=>"€20.00 EUR", "_id"=>BSON::ObjectID('4c3039180e9dab5d86000009')})
35
+ MONGODB mm-money-test-1-8-7['products'].find({}, {}).sort([["price", 1]])
36
+ MONGODB admin['$cmd'].find({:ismaster=>1}, {}).limit(-1)
37
+ MONGODB mm-money-test-1-8-7['system.namespaces'].find({}, {})
38
+ MONGODB mm-money-test-1-8-7['products'].remove({})
39
+ MONGODB mm-money-test-1-8-7['system.indexes'].remove({})
40
+ MONGODB mm-money-test-1-8-7['products'].remove({})
41
+ MONGODB mm-money-test-1-8-7['products'].remove({})
42
+ MONGODB mm-money-test-1-8-7['products'].remove({})
43
+ MONGODB mm-money-test-1-8-7['products'].remove({})
44
+ MONGODB mm-money-test-1-8-7['products'].remove({})
45
+ MONGODB mm-money-test-1-8-7['products'].remove({})
46
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30396b0e9dab5fae000006')}, {"price"=>"$10.00 USD", "_id"=>BSON::ObjectID('4c30396b0e9dab5fae000006')})
47
+ MONGODB mm-money-test-1-8-7['products'].find({}, {}).limit(-1)
48
+ MONGODB mm-money-test-1-8-7['products'].remove({})
49
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30396b0e9dab5fae000007')}, {"price"=>"€10.00 EUR", "_id"=>BSON::ObjectID('4c30396b0e9dab5fae000007')})
50
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30396b0e9dab5fae000008')}, {"price"=>"€30.00 EUR", "_id"=>BSON::ObjectID('4c30396b0e9dab5fae000008')})
51
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30396b0e9dab5fae000009')}, {"price"=>"€20.00 EUR", "_id"=>BSON::ObjectID('4c30396b0e9dab5fae000009')})
52
+ MONGODB mm-money-test-1-8-7['products'].find({}, {}).sort([["price", 1]])
53
+ MONGODB admin['$cmd'].find({:ismaster=>1}, {}).limit(-1)
54
+ MONGODB mm-money-test-1-8-7['system.namespaces'].find({}, {})
55
+ MONGODB mm-money-test-1-8-7['products'].remove({})
56
+ MONGODB mm-money-test-1-8-7['system.indexes'].remove({})
57
+ MONGODB mm-money-test-1-8-7['products'].remove({})
58
+ MONGODB mm-money-test-1-8-7['products'].remove({})
59
+ MONGODB mm-money-test-1-8-7['products'].remove({})
60
+ MONGODB mm-money-test-1-8-7['products'].remove({})
61
+ MONGODB mm-money-test-1-8-7['products'].remove({})
62
+ MONGODB mm-money-test-1-8-7['products'].remove({})
63
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30397d0e9dab6021000006')}, {"price"=>"$10.00 USD", "_id"=>BSON::ObjectID('4c30397d0e9dab6021000006')})
64
+ MONGODB mm-money-test-1-8-7['products'].find({}, {}).limit(-1)
65
+ MONGODB mm-money-test-1-8-7['products'].remove({})
66
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30397d0e9dab6021000007')}, {"price"=>"€10.00 EUR", "_id"=>BSON::ObjectID('4c30397d0e9dab6021000007')})
67
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30397d0e9dab6021000008')}, {"price"=>"€30.00 EUR", "_id"=>BSON::ObjectID('4c30397d0e9dab6021000008')})
68
+ MONGODB mm-money-test-1-8-7['products'].update({:_id=>BSON::ObjectID('4c30397d0e9dab6021000009')}, {"price"=>"€20.00 EUR", "_id"=>BSON::ObjectID('4c30397d0e9dab6021000009')})
69
+ MONGODB mm-money-test-1-8-7['products'].find({}, {}).sort([["price", 1]])
@@ -0,0 +1,53 @@
1
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
2
+
3
+ describe "Money key" do
4
+ before(:all) do
5
+ Money.default_currency = 'EUR'
6
+ class ::Product
7
+ include MongoMapper::Document
8
+
9
+ key :price, Money
10
+ end
11
+ end
12
+
13
+ before(:each) do
14
+ ::Product.collection.remove
15
+ end
16
+
17
+ after(:all) do
18
+ Object.send :remove_const, :Product if defined?(::Product)
19
+ end
20
+
21
+ it 'returns money objects' do
22
+ Product.new(:price => 10).price.should be_kind_of(Money)
23
+ end
24
+
25
+ it 'handles integers correctly' do
26
+ Product.new(:price => 10).price.should == Money.new(1000, 'EUR')
27
+ end
28
+
29
+ it 'handles floats correctly' do
30
+ Product.new(:price => 9.99).price.should == Money.new(999, 'EUR')
31
+ end
32
+
33
+ it 'handles strings correctly' do
34
+ Product.new(:price => '10').price.should == Money.new(1000, 'EUR')
35
+ end
36
+
37
+ it 'handles strings with currency in them correctly' do
38
+ Product.new(:price => '10 USD').price.should == Money.new(1000, 'USD')
39
+ end
40
+
41
+ it 'handles saving and loading to the db correctly' do
42
+ Product.new(:price => '10 USD').save!
43
+ Product.first.price.should == Money.new(1000, 'USD')
44
+ end
45
+
46
+ it 'handles sorting in the db properly' do
47
+ first = Product.create!(:price => 10)
48
+ third = Product.create!(:price => 30)
49
+ second = Product.create!(:price => 20)
50
+
51
+ Product.sort(:price.asc).all.should == [first, second, third]
52
+ end
53
+ end
@@ -0,0 +1,27 @@
1
+ require File.expand_path(
2
+ File.join(File.dirname(__FILE__), %w[.. lib mm-money]))
3
+
4
+ require 'rubygems'
5
+ require 'mongo_mapper'
6
+ require 'fileutils'
7
+
8
+ Spec::Runner.configure do |config|
9
+ # == Mock Framework
10
+ #
11
+ # RSpec uses it's own mocking framework by default. If you prefer to
12
+ # use mocha, flexmock or RR, uncomment the appropriate line:
13
+ #
14
+ # config.mock_with :mocha
15
+ # config.mock_with :flexmock
16
+ # config.mock_with :rr
17
+
18
+ log_dir = File.expand_path('../log', __FILE__)
19
+ FileUtils.mkdir_p(log_dir) unless File.exist?(log_dir)
20
+ logger = Logger.new(log_dir + '/spec.log')
21
+
22
+ MongoMapper.connection = Mongo::Connection.new('127.0.0.1', 27017, :logger => logger)
23
+ MongoMapper.database = "mm-money-test-#{RUBY_VERSION.gsub('.', '-')}"
24
+ MongoMapper.database.collections.each { |c| c.remove }
25
+
26
+ end
27
+
@@ -0,0 +1 @@
1
+ 0.1.0
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mm-money
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Toni Tuominen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-04 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: money
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 4
31
+ version: 3.0.4
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: mongo_mapper
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ - 8
44
+ - 2
45
+ version: 0.8.2
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 3
58
+ - 0
59
+ version: 1.3.0
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: bones
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 3
71
+ - 4
72
+ - 3
73
+ version: 3.4.3
74
+ type: :development
75
+ version_requirements: *id004
76
+ description: Handle money keys with MongoMapper.
77
+ email: toni@piranhadigital.fi
78
+ executables: []
79
+
80
+ extensions: []
81
+
82
+ extra_rdoc_files:
83
+ - History.txt
84
+ - README.txt
85
+ - version.txt
86
+ files:
87
+ - .gitignore
88
+ - History.txt
89
+ - README.txt
90
+ - Rakefile
91
+ - lib/mm-money.rb
92
+ - mm-money.gemspec
93
+ - spec/log/spec.log
94
+ - spec/mm-money_spec.rb
95
+ - spec/spec_helper.rb
96
+ - version.txt
97
+ has_rdoc: true
98
+ homepage: http://github.com/tjtuom/mm-money
99
+ licenses: []
100
+
101
+ post_install_message:
102
+ rdoc_options:
103
+ - --main
104
+ - README.txt
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 0
113
+ version: "0"
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project: mm-money
124
+ rubygems_version: 1.3.6
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Handle money keys with MongoMapper
128
+ test_files: []
129
+