acts_as_priceable_on 0.0.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f8c501cb4d735981450c69a16dea79577e27ae3
4
- data.tar.gz: 5a2254bc82b9924d64471ecf8e4b460d1fea63a3
3
+ metadata.gz: a764e262e9bb7a2c03f88ab9b679ef22b33617a0
4
+ data.tar.gz: aace5ecf3e3456bce6b631474b53c8164d34995b
5
5
  SHA512:
6
- metadata.gz: 3207a86d6f8fd14e06ee1c591de6c137c28e802b04ac15b01506393f15621a47b2b3cd7241443a3032d525dbade62d0edf464d05b89edae61f48ac204b0109a9
7
- data.tar.gz: eba26191fa031a882a4ae41b9acd061b997d82dbfc78726daa71b7d0f88f24c5a142e24ff18c002d87af4c50baff93704ba2e7d1ae0bcc8795112d7e8fd9c5d2
6
+ metadata.gz: 7a378b1869584f1dce5f3fb822927d0ceba611d5f40c60944b80c551168cc0961f98ad4447d9668b454d2228d41766efaf793f67881fd3d1729043ffabaf6fa5
7
+ data.tar.gz: 60a72234b518f3188371142bc627b3bd7b2525b6f3f45f8448e9b5903fe302b0c8be76658e07564b79a20f55bf6e2aab48b24ccd532cc34482ab19e27d831221
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in acts_as_priceable_on.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kyle Crop
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.
@@ -0,0 +1,29 @@
1
+ # ActsAsPriceableOn
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'acts_as_priceable_on'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install acts_as_priceable_on
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/acts_as_priceable_on/fork )
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 a new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'acts_as_priceable_on/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'acts_as_priceable_on'
8
+ spec.version = ActsAsPriceableOn::VERSION
9
+ spec.authors = ['Kyle Crop', 'Chris Massey']
10
+ spec.email = ['kylecrop@utexas.edu']
11
+ spec.summary = %q{Add price attribute to your classes}
12
+ spec.description = %q{Allows methods and attributes of priceability also employing money rails}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_runtime_dependency 'money-rails'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.6'
24
+ spec.add_development_dependency 'rake'
25
+ spec.add_development_dependency 'rails'
26
+ spec.add_development_dependency 'rspec-rails', '~> 3.0.0'
27
+ spec.add_development_dependency 'sqlite3'
28
+ end
@@ -1,5 +1,9 @@
1
- class Acts_as_priceable_on
2
- def self.hi
3
- puts "Hello World"
4
- end
5
- end
1
+ # Dependencies
2
+ require 'rails'
3
+ require 'active_support'
4
+ require 'active_record'
5
+
6
+ # Library
7
+ require 'acts_as_priceable_on/version'
8
+ require 'acts_as_priceable_on/price'
9
+ require 'acts_as_priceable_on/railtie' if defined?(Rails)
@@ -0,0 +1,34 @@
1
+ require 'active_support'
2
+ require 'active_record'
3
+
4
+ module ActsAsPriceableOn
5
+ module ActiveRecord
6
+ module Priceable
7
+ extend ActiveSupport::Concern
8
+
9
+ module ClassMethods
10
+ def acts_as_priceable
11
+ acts_as_priceable_on :prices
12
+ end # acts_as_priceable
13
+
14
+ def acts_as_priceable_on(*types, options)
15
+ types << options unless options.is_a? Hash
16
+
17
+ types.each do |type|
18
+ name = type.to_s.singularize.titleize # :charges => 'Charge'
19
+
20
+ #if constant doesn't already exist, create it as subclass of Price
21
+ unless ActsAsPriceableOn.const_defined?(name)
22
+ ActsAsPriceableOn.const_set name, Class.new(Price)
23
+ end
24
+
25
+ has_many type, as: :priceable, class_name: "ActsAsPriceableOn::#{name}"
26
+ end
27
+ end # acts_as_priceable_on
28
+
29
+ end # ClassMethods
30
+ end # Priceable
31
+ end # ActiveRecord
32
+ end # ActsAsPriceableOn
33
+
34
+ ActiveRecord::Base.send :include, ActsAsPriceableOn::ActiveRecord::Priceable
@@ -0,0 +1,9 @@
1
+ module ActsAsPriceableOn
2
+ class Price < ActiveRecord::Base
3
+ # Associations
4
+ belongs_to :priceable, polymorphic: true
5
+
6
+ # Attributes
7
+ monetize :amount_cents
8
+ end # Price
9
+ end # ActsAsPriceableOn
@@ -0,0 +1,9 @@
1
+ module ActsAsPriceableOn
2
+ class Railtie < Rails::Railtie
3
+ initializer 'acts_as_priceable_on.active_record' do |app|
4
+ ActiveSupport.on_load :active_record do
5
+ require 'acts_as_priceable_on/active_record/priceable'
6
+ end
7
+ end
8
+ end # Railtie
9
+ end # ActsAsPriceableOn
@@ -0,0 +1,3 @@
1
+ module ActsAsPriceableOn
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ class Product < ::ActiveRecord::Base
4
+ acts_as_priceable_on :charges, :surcharges#, :fees
5
+ end
6
+
7
+ class Service < ::ActiveRecord::Base
8
+ acts_as_priceable
9
+ end
10
+
11
+ # Specs
12
+ describe ActiveRecord::Base do
13
+ it 'includes #acts_as_priceable' do
14
+ expect(ActiveRecord::Base).to respond_to(:acts_as_priceable)
15
+ end
16
+
17
+ context Product do
18
+ it { is_expected.to respond_to(:prices) }
19
+ end # Product
20
+
21
+ context Service do
22
+ it { is_expected.to respond_to(:prices) }
23
+ end # Service
24
+
25
+ it 'allows access to amount attribute within price' do
26
+ help = Service.create
27
+ help.prices.create(amount: 10)
28
+ expect(help.prices.first.amount).to eq(10)
29
+ end
30
+
31
+ it 'distinguishes charges and surcharges' do
32
+ product = Product.create
33
+ charge = product.charges.create(amount: 11, name: 'first')
34
+ surcharge = product.surcharges.create(amount: 12, name: 'second')
35
+
36
+ expect(product.charges(true))
37
+ #expect(myProduct.charges.length).to eq(1)
38
+ #expect(myProduct.surcharges.length).to eq(1)
39
+
40
+ expect(product.charges).to contain_exactly(charge)
41
+ expect(product.surcharges).to contain_exactly(surcharge)
42
+ end
43
+
44
+ #it ''
45
+
46
+
47
+ end # ActiveRecord::Base
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ # Specs
4
+ describe ActsAsPriceableOn::Price do
5
+ let(:price) { ActsAsPriceableOn::Price.create! }
6
+
7
+ it { is_expected.to respond_to(:amount) }
8
+ it { is_expected.to respond_to(:amount_cents) }
9
+
10
+ it 'converts money to currency' do
11
+ expect(price.amount).to respond_to(:currency)
12
+ end
13
+
14
+ it 'creates a price' do
15
+ price = ActsAsPriceableOn::Price.create(amount: 10)
16
+ expect(price.amount).to eq(10)
17
+ end
18
+ end # ActsAsPriceableOn::Price
@@ -0,0 +1,38 @@
1
+ # Dependencies
2
+ require 'rails'
3
+ require 'money-rails'
4
+ require 'active_record'
5
+ require 'sqlite3'
6
+
7
+ puts "ActiveRecord version #{ActiveSupport::VERSION::STRING}"
8
+
9
+ MoneyRails::Hooks.init
10
+
11
+ # Library
12
+ require 'acts_as_priceable_on'
13
+ require 'acts_as_priceable_on/active_record/priceable'
14
+
15
+ # Setup
16
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ":memory:"
17
+
18
+ ActiveRecord::Schema.define(version: 1) do
19
+ create_table :prices do |t|
20
+ t.string :type
21
+
22
+ t.string :name
23
+ t.money :amount
24
+
25
+ t.references :priceable, polymorphic: true
26
+ end
27
+
28
+ create_table :products do |t|
29
+ t.string :name
30
+ end
31
+
32
+ create_table :services do |t|
33
+ t.string :name
34
+ end
35
+ end
36
+
37
+ # Spec Environment
38
+ Dir['./spec/support/**/*.rb'].sort.each { |file| require file }
@@ -0,0 +1,6 @@
1
+ class Product < ActiveRecord::Base
2
+ # Extensions
3
+ acts_as_priceable # equivalent to `acts_as_priceable_on :prices`
4
+ acts_as_priceable_on :charges, :surcharges, :taxes, :fees
5
+
6
+ end # Product
metadata CHANGED
@@ -1,25 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_priceable_on
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Crop
8
+ - Chris Massey
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-08-20 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Tell whether an object has the ability to have a price
14
- email: kylecrop@utexas.edu
12
+ date: 2014-08-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: money-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.6'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.6'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rails
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec-rails
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 3.0.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 3.0.0
84
+ - !ruby/object:Gem::Dependency
85
+ name: sqlite3
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: Allows methods and attributes of priceability also employing money rails
99
+ email:
100
+ - kylecrop@utexas.edu
15
101
  executables: []
16
102
  extensions: []
17
103
  extra_rdoc_files: []
18
104
  files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - acts_as_priceable_on.gemspec
19
111
  - lib/acts_as_priceable_on.rb
20
- homepage: http://rubygems.org/gems/acts_as_priceable_on
112
+ - lib/acts_as_priceable_on/active_record/priceable.rb
113
+ - lib/acts_as_priceable_on/price.rb
114
+ - lib/acts_as_priceable_on/railtie.rb
115
+ - lib/acts_as_priceable_on/version.rb
116
+ - spec/active_record_spec.rb
117
+ - spec/price_spec.rb
118
+ - spec/spec_helper.rb
119
+ - spec/support/app/models/product.rb
120
+ homepage: ''
21
121
  licenses:
22
- - "????"
122
+ - MIT
23
123
  metadata: {}
24
124
  post_install_message:
25
125
  rdoc_options: []
@@ -40,5 +140,9 @@ rubyforge_project:
40
140
  rubygems_version: 2.2.2
41
141
  signing_key:
42
142
  specification_version: 4
43
- summary: Tells priceability of an object
44
- test_files: []
143
+ summary: Add price attribute to your classes
144
+ test_files:
145
+ - spec/active_record_spec.rb
146
+ - spec/price_spec.rb
147
+ - spec/spec_helper.rb
148
+ - spec/support/app/models/product.rb