redline 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -19,3 +19,4 @@ rdoc
19
19
  pkg
20
20
 
21
21
  ## PROJECT::SPECIFIC
22
+ spec/db/test.sqlite3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -0,0 +1,36 @@
1
+ module RedLine
2
+ module Customer
3
+ def self.included(base)
4
+ base.class_eval do
5
+ send :extend, ActiveSupport::Memoizable
6
+ send :include, InstanceMethods
7
+ memoize :customer
8
+ before_create :create_customer
9
+ before_update :update_customer
10
+ before_destroy :delete_customer
11
+ cattr_accessor :braintree_customer
12
+ end
13
+ end
14
+ module InstanceMethods
15
+ def braintree_customer_attributes
16
+ wanted_attributes = Braintree::Customer._create_signature.reject{|a| a.is_a? Hash}.reject{|a| a == :id}
17
+ attributes.symbolize_keys.inject({}) do |rewritten_hash, (original_key, value)|
18
+ rewritten_hash[self.class.braintree_customer.fetch(original_key, original_key)] = value
19
+ rewritten_hash
20
+ end.reject{|key, value| !wanted_attributes.include?(key)}
21
+ end
22
+ def customer
23
+ Braintree::Customer.find(customer_id) if customer_id
24
+ end
25
+ def create_customer
26
+ self.customer_id = Braintree::Customer.create!(braintree_customer_attributes).id
27
+ end
28
+ def update_customer
29
+ Braintree::Customer.update!(customer_id, braintree_customer_attributes) && flush_cache(:customer) if customer_id
30
+ end
31
+ def delete_customer
32
+ Braintree::Customer.delete(customer_id) if customer_id
33
+ end
34
+ end
35
+ end
36
+ end
data/lib/redline.rb CHANGED
@@ -2,44 +2,14 @@ require 'rubygems'
2
2
  require 'active_record'
3
3
 
4
4
  module RedLine
5
+
6
+ autoload :Customer, 'redline/customer'
7
+
5
8
  def acts_as_braintree_customer(attribute_rewriting = {})
6
9
  send :include, RedLine::Customer
7
10
  send 'braintree_customer=', attribute_rewriting
8
11
  end
9
- module Customer
10
- def self.included(base)
11
- base.class_eval do
12
- send :extend, ActiveSupport::Memoizable
13
- send :include, InstanceMethods
14
- memoize :customer
15
- before_create :create_customer
16
- before_update :update_customer
17
- before_destroy :delete_customer
18
- cattr_accessor :braintree_customer
19
- end
20
- end
21
- module InstanceMethods
22
- def braintree_customer_attributes
23
- wanted_attributes = Braintree::Customer._create_signature.reject{|a| a.is_a? Hash}.reject{|a| a == :id}
24
- attributes.symbolize_keys.inject({}) do |rewritten_hash, (original_key, value)|
25
- rewritten_hash[self.class.braintree_customer.fetch(original_key, original_key)] = value
26
- rewritten_hash
27
- end.reject{|key, value| !wanted_attributes.include?(key)}
28
- end
29
- def customer
30
- Braintree::Customer.find(customer_id)
31
- end
32
- def create_customer
33
- self.customer_id = Braintree::Customer.create!(braintree_customer_attributes).id
34
- end
35
- def update_customer
36
- Braintree::Customer.update!(customer_id, braintree_customer_attributes) && flush_cache(:customer)
37
- end
38
- def delete_customer
39
- Braintree::Customer.delete(customer_id)
40
- end
41
- end
42
- end
12
+
43
13
  end
44
14
 
45
15
  ActiveRecord::Base.extend RedLine
data/redline.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{redline}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Daniels"]
12
- s.date = %q{2010-01-19}
12
+ s.date = %q{2010-02-03}
13
13
  s.description = %q{Manual subscriptions via the Braintree gem}
14
14
  s.email = %q{james@marginleft.com}
15
15
  s.extra_rdoc_files = [
@@ -24,11 +24,11 @@ Gem::Specification.new do |s|
24
24
  "Rakefile",
25
25
  "VERSION",
26
26
  "lib/redline.rb",
27
+ "lib/redline/customer.rb",
27
28
  "redline.gemspec",
28
29
  "spec/db/database.yml",
29
30
  "spec/db/models.rb",
30
31
  "spec/db/schema.rb",
31
- "spec/db/test.sqlite3",
32
32
  "spec/redline_spec.rb",
33
33
  "spec/spec.opts",
34
34
  "spec/spec_helper.rb"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Daniels
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-19 00:00:00 -05:00
12
+ date: 2010-02-03 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -69,11 +69,11 @@ files:
69
69
  - Rakefile
70
70
  - VERSION
71
71
  - lib/redline.rb
72
+ - lib/redline/customer.rb
72
73
  - redline.gemspec
73
74
  - spec/db/database.yml
74
75
  - spec/db/models.rb
75
76
  - spec/db/schema.rb
76
- - spec/db/test.sqlite3
77
77
  - spec/redline_spec.rb
78
78
  - spec/spec.opts
79
79
  - spec/spec_helper.rb
data/spec/db/test.sqlite3 DELETED
Binary file