cmdjohnson-acts_as_money 0.0.1

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,4 @@
1
+ === 0.0.1 2013-02-02
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,9 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/acts_as_money.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
@@ -0,0 +1,7 @@
1
+
2
+ For more information on cmdjohnson-acts_as_money, see http://cmdjohnson-acts_as_money.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
@@ -0,0 +1,89 @@
1
+ = acts_as_money
2
+
3
+ * http://github.com/cmdjohnson/acts_as_money
4
+
5
+ == DESCRIPTION:
6
+
7
+ Improved version of acts_as_money.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Fixes a problem in acts_as_money 0.2.5 [https://rubygems.org/gems/acts_as_money/versions/0.2.5] that causes strings such as "3,25" and "3.25" to be interpreted differently. This gem handles both inputs equally.
12
+ * This gem simply tries to call "to_money" on the received object which seems much simpler to me.
13
+ * This also means that it doesn't matter what you enter, be it 3 (Fixnum), 3.00 (Float), "3.00" (String) or "3,00" (String).
14
+ * Leveraging the "to_money" method provided by the money gem seems like a good thing to do.
15
+
16
+ == SYNOPSIS:
17
+
18
+ (modified description from the acts_as_money gem)
19
+
20
+ acts_as_money is a fairly trivial plugin that makes it easier to work with the money gem.
21
+
22
+ class Product < ActiveRecord::Base
23
+ acts_as_money
24
+ money :price
25
+ end
26
+
27
+ This assumes that there are 2 columns in the database, cents (integer) and currency (string). These fields can be changed by setting the :cents and :currency options. To use the default currency, you can simple set :currency to false
28
+
29
+ class Room < ActiveRecord::Base
30
+ acts_as_money
31
+ money :rate, :cents => :rate_in_cents, :currency => :rate_currency
32
+ money :discount, :cents => :discount_in_cents, :currency => false
33
+ end
34
+
35
+ By default, your money field will default to a value of 0. If you require it to default to nil, you may set the :allow_nil option:
36
+
37
+ class Meal < ActiveRecord::Base
38
+ acts_as_money
39
+ money :bill, :allow_nil => true
40
+ end
41
+
42
+ m = Meal.new
43
+ m.bill #returns nil
44
+
45
+ r = Room.new
46
+ r.rate #returns <Money:0x24fd53a6 @currency="USD", @cents=0>
47
+
48
+ acts_as_money allows you to pass a String, Fixnum, Float or Money object as a parameter to the setter, and it will call #to_money to convert it to a Money object. This makes it convenient for using money fields in forms.
49
+
50
+ r = Room.new :rate => "100.00"
51
+ r.rate # returns <Money:0x249ef9c @currency="USD", @cents=10000>
52
+
53
+ == REQUIREMENTS:
54
+
55
+ * activerecord
56
+ * money
57
+
58
+ == INSTALL:
59
+
60
+ gem install cmdjohnson-acts_as_money
61
+
62
+ In your Gemfile:
63
+
64
+ gem "cmdjohnson-acts_as_money", "0.0.1", :require => "acts_as_money"
65
+
66
+ == LICENSE:
67
+
68
+ (The MIT License)
69
+
70
+ Copyright (c) 2013 Commander Johnson
71
+
72
+ Permission is hereby granted, free of charge, to any person obtaining
73
+ a copy of this software and associated documentation files (the
74
+ 'Software'), to deal in the Software without restriction, including
75
+ without limitation the rights to use, copy, modify, merge, publish,
76
+ distribute, sublicense, and/or sell copies of the Software, and to
77
+ permit persons to whom the Software is furnished to do so, subject to
78
+ the following conditions:
79
+
80
+ The above copyright notice and this permission notice shall be
81
+ included in all copies or substantial portions of the Software.
82
+
83
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
84
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
85
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
86
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
87
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
88
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
89
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/acts_as_money'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'cmdjohnson-acts_as_money' do
14
+ self.developer 'Commander Johnson', 'commanderjohnson@gmail.com'
15
+ #self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ self.extra_deps = [['activerecord','>= 0'], ['money', '>= 0']]
18
+ self.version = "0.0.1"
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ # task :default => [:spec, :features]
@@ -0,0 +1,41 @@
1
+ require 'money'
2
+
3
+ if defined?(Rails)
4
+ class ActiveRecord::Base
5
+ class << self
6
+ def acts_as_money
7
+ include(ActsAsMoney)
8
+ end
9
+ end
10
+ end
11
+
12
+
13
+ module ActsAsMoney #:nodoc:
14
+ def self.included(base) #:nodoc:
15
+ base.extend ClassMethods
16
+ end
17
+
18
+ module ClassMethods
19
+ def money(name, options = {})
20
+ mapping = [[(options[:cents] || :cents).to_s, 'cents']]
21
+ mapping << [(options[:currency] || :currency).to_s, 'currency_as_string'] if options[:currency] != false
22
+ composed_of name, {
23
+ :class_name => 'Money',
24
+ :allow_nil => options[:allow_nil],
25
+ :mapping => mapping,
26
+ :constructor => Proc.new { |cents, currency| options[:allow_nil] && !cents ? nil : Money.new(cents || 0, currency || Money.default_currency) },
27
+ :converter => Proc.new { |value|
28
+ ret = value
29
+
30
+ begin
31
+ ret = value.to_money
32
+ rescue
33
+ end
34
+
35
+ ret
36
+ }
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/cmdjohnson-acts_as_money.rb'}"
9
+ puts "Loading cmdjohnson-acts_as_money gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmdjohnson-acts_as_money
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Commander Johnson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '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: '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: '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: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.10'
62
+ - !ruby/object:Gem::Dependency
63
+ name: newgem
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 1.5.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.5.3
78
+ - !ruby/object:Gem::Dependency
79
+ name: hoe
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '3.3'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '3.3'
94
+ description: Improved version of acts_as_money.
95
+ email:
96
+ - commanderjohnson@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files:
100
+ - History.txt
101
+ - Manifest.txt
102
+ - PostInstall.txt
103
+ - README.rdoc
104
+ files:
105
+ - History.txt
106
+ - Manifest.txt
107
+ - PostInstall.txt
108
+ - README.rdoc
109
+ - Rakefile
110
+ - lib/acts_as_money.rb
111
+ - script/console
112
+ - script/destroy
113
+ - script/generate
114
+ homepage: http://github.com/cmdjohnson/acts_as_money
115
+ licenses: []
116
+ post_install_message:
117
+ rdoc_options:
118
+ - --main
119
+ - README.rdoc
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project: cmdjohnson-acts_as_money
136
+ rubygems_version: 1.8.23
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: Improved version of acts_as_money.
140
+ test_files: []