activerecord-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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: be2e8d5e6e5344ffa68da4836016a8bdf117963d
4
+ data.tar.gz: 4f0eb5f3797939fd09d6bb7614620b6b9117b39b
5
+ SHA512:
6
+ metadata.gz: 8d81cb6feedd98d56de521ae29b2ecd8c578ba95c58f12612228ecece714f8b4a798aaa9b9d7bde5f063619fbd111e824da3c120bf874857eb315df3848c2791
7
+ data.tar.gz: 36917a0b47329b74aa878554c634b0ae2bdebfd75642157541a88bc0c7d346b9aaf327e553cd9a971221043804c111d727c22cebf19b1520b78c00224855bee8
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activerecord-money.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Vlad Verestiuc
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,29 @@
1
+ # Activerecord::Money
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'activerecord-money'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install activerecord-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
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activerecord-money/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "activerecord-money"
8
+ gem.version = Activerecord::Money::VERSION
9
+ gem.authors = ["Vlad Verestiuc"]
10
+ gem.email = ["vlad.verestiuc@me.com"]
11
+ gem.description = %q{ActiveRecord wrapper for money gem}
12
+ gem.summary = %q{ActiveRecord wrapper for money gem}
13
+ gem.homepage = ""
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
+
21
+ gem.add_dependency 'activerecord'
22
+ gem.add_dependency 'money'
23
+ end
@@ -0,0 +1,70 @@
1
+ require "activerecord-money/version"
2
+
3
+ module ActiveRecord::Money
4
+ extend ActiveSupport::Concern
5
+
6
+ def default_money_currency(options)
7
+ options[:default_currency] ||= Money.default_currency
8
+ end
9
+
10
+ def currency_field(name, options)
11
+ options[:currency] || :"#{name}_currency"
12
+ end
13
+
14
+ def money_currency(name, options)
15
+ attribute_name = currency_field(name, options)
16
+ default_currency = default_money_currency(options)
17
+
18
+ currency = respond_to?(attribute_name) ? send(attribute_name) : nil
19
+ currency || default_currency
20
+ end
21
+
22
+ def blank_money?(value, options)
23
+ options[:allow_nil] and value.blank?
24
+ end
25
+
26
+ def money_reader(name, options = {})
27
+ value = send("#{name}_in_cents")
28
+ blank_money?(value, options) ? nil : Money.new(value || 0, money_currency(name, options))
29
+ end
30
+
31
+ def money_writer(name, value, options = {})
32
+ currency_attribute_name = currency_field(name, options)
33
+ currency_name = money_currency(name, options)
34
+
35
+ if value.is_a? Money
36
+ send("#{name}_in_cents=", value.cents)
37
+ send("#{currency_attribute_name}=", "#{value.currency.id}") if respond_to? "#{currency_attribute_name}="
38
+ elsif !value.blank?
39
+ value = value.to_money(currency_name)
40
+ money_writer(name, value, options)
41
+ else
42
+ money_writer(name, 0.to_money(currency_name), options) unless blank_money?(name, options)
43
+ end
44
+
45
+ value
46
+ end
47
+
48
+ module ClassMethods
49
+ def money(name, options = {})
50
+ class_eval(<<-EOS, __FILE__, __LINE__)
51
+ def #{name}
52
+ money_reader(:#{name},#{options.inspect})
53
+ end
54
+
55
+ def #{name}=(value)
56
+ money_writer(:#{name},value,#{options.inspect})
57
+ end
58
+
59
+ EOS
60
+ end
61
+ end
62
+ end
63
+
64
+ class Money
65
+
66
+ def -@
67
+ Money.new(-cents, currency)
68
+ end
69
+
70
+ end
@@ -0,0 +1,5 @@
1
+ module Activerecord
2
+ module Money
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-money
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vlad Verestiuc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: money
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ActiveRecord wrapper for money gem
42
+ email:
43
+ - vlad.verestiuc@me.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - activerecord-money.gemspec
54
+ - lib/activerecord-money.rb
55
+ - lib/activerecord-money/version.rb
56
+ homepage: ''
57
+ licenses: []
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.5
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: ActiveRecord wrapper for money gem
79
+ test_files: []