datamapper-money 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/datamapper-money.gemspec +22 -0
- data/lib/datamapper-money.rb +52 -0
- data/lib/datamapper-money/version.rb +5 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Smudge
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# datamapper-money
|
2
|
+
|
3
|
+
Adds a 'money' instance method to DataMapper-based models, for creating properties powered by the 'money' rubygem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'datamapper-money'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install datamapper-money
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
30
|
+
|
31
|
+
## License
|
32
|
+
|
33
|
+
See LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'datamapper-money/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "datamapper-money"
|
8
|
+
gem.version = Datamapper::Money::VERSION
|
9
|
+
gem.authors = ["Smudge"]
|
10
|
+
gem.email = ["nathan@ngriffith.com"]
|
11
|
+
gem.summary = %q{DataMapper-enabled use of 'money' rubygem.}
|
12
|
+
gem.description = %q{Adds a 'money' instance method to DataMapper-based models, for creating properties powered by the 'money' rubygem.}
|
13
|
+
gem.homepage = "http://github.com/Smudge/datamapper-money"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'dm-core', '~> 1.2.0'
|
21
|
+
gem.add_dependency 'money', '~> 5.0.0'
|
22
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "datamapper-money/version"
|
2
|
+
require 'money'
|
3
|
+
require 'dm-core'
|
4
|
+
|
5
|
+
module DataMapper
|
6
|
+
module Money
|
7
|
+
def self.included(model)
|
8
|
+
model.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def money(name, options = {})
|
14
|
+
raise ArgumentError.new('Name must be specified.') if name.empty?
|
15
|
+
|
16
|
+
default = options.delete(:default)
|
17
|
+
property = DataMapper::Property::Decimal.new(self, name, options)
|
18
|
+
name = property.name.to_s
|
19
|
+
instance_variable_name = property.instance_variable_name
|
20
|
+
name_cents = "#{name}_cents"
|
21
|
+
name_currency = "#{name}_currency"
|
22
|
+
|
23
|
+
options_cents = options.slice(:required, :precision, :scale).merge(:accessor => :private)
|
24
|
+
options_cents.merge!(:default => default.cents) if default
|
25
|
+
self.property name_cents.to_sym, DataMapper::Property::Decimal, options_cents
|
26
|
+
|
27
|
+
options_currency = options.slice(:required).merge(:accessor => :private, :length => 3)
|
28
|
+
options_currency.merge!(:default => default.currency.to_s) if default
|
29
|
+
self.property name_currency.to_sym, DataMapper::Property::String, options_currency
|
30
|
+
|
31
|
+
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
32
|
+
#{property.reader_visibility}
|
33
|
+
def #{name}
|
34
|
+
return #{instance_variable_name} if defined?(#{instance_variable_name})
|
35
|
+
return unless #{name_cents} && #{name_currency}
|
36
|
+
#{instance_variable_name} = Money.new(#{name_cents}, #{name_currency})
|
37
|
+
end
|
38
|
+
|
39
|
+
#{property.writer_visibility}
|
40
|
+
def #{name}=(value)
|
41
|
+
self.#{name_cents} = value.cents
|
42
|
+
self.#{name_currency} = value.currency
|
43
|
+
#{instance_variable_name} = value
|
44
|
+
end
|
45
|
+
RUBY
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
Model.append_inclusions self
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datamapper-money
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Smudge
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: dm-core
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: money
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 5.0.0
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 5.0.0
|
46
|
+
description: Adds a 'money' instance method to DataMapper-based models, for creating
|
47
|
+
properties powered by the 'money' rubygem.
|
48
|
+
email:
|
49
|
+
- nathan@ngriffith.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- datamapper-money.gemspec
|
60
|
+
- lib/datamapper-money.rb
|
61
|
+
- lib/datamapper-money/version.rb
|
62
|
+
homepage: http://github.com/Smudge/datamapper-money
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.23
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: DataMapper-enabled use of 'money' rubygem.
|
86
|
+
test_files: []
|