mix-rails-vouchers 0.22.0 → 0.23.0
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.
- data/app/models/admix/vouchers_datagrid.rb +1 -1
- data/app/models/voucher.rb +10 -14
- data/app/models/voucher_user.rb +41 -46
- data/app/uploaders/vouchers/photo_uploader.rb +2 -2
- data/db/migrate/20130208143458_create_vouchers.rb +15 -0
- data/db/migrate/20130208143613_create_voucher_users.rb +13 -0
- data/lib/mix-rails-vouchers.rb +0 -1
- data/lib/mix-rails-vouchers/version.rb +1 -1
- metadata +6 -20
data/app/models/voucher.rb
CHANGED
@@ -1,22 +1,18 @@
|
|
1
|
-
class Voucher
|
2
|
-
|
3
|
-
include Mongoid::Timestamps
|
4
|
-
include Mongoid::Slug
|
1
|
+
class Voucher < ActiveRecord::Base
|
2
|
+
extend FriendlyId
|
5
3
|
|
6
|
-
|
4
|
+
attr_accessible :date_from, :date_to, :name, :partner_photo, :photo, :rules
|
5
|
+
attr_accessible :photo_cache, :partner_photo_cache
|
6
|
+
|
7
|
+
scope :actives, -> { where("date_from <= ? and date_to >= ?", Date.today, Date.today) }
|
8
|
+
|
9
|
+
has_many :users, class_name: 'VoucherUser', dependent: :delete_all
|
7
10
|
|
8
|
-
field :name, type: String
|
9
|
-
field :rules, type: Array
|
10
|
-
field :date_from, type: Date
|
11
|
-
field :date_to, type: Date
|
12
11
|
mount_uploader :photo, Vouchers::PhotoUploader
|
13
12
|
mount_uploader :partner_photo, Vouchers::PhotoUploader
|
14
13
|
|
15
|
-
has_many :users, class_name: 'VoucherUser', dependent: :delete
|
16
|
-
|
17
14
|
validates_presence_of :name, :rules, :photo
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
end
|
16
|
+
friendly_id :name, use: :slugged
|
17
|
+
|
22
18
|
end
|
data/app/models/voucher_user.rb
CHANGED
@@ -1,48 +1,43 @@
|
|
1
|
-
class VoucherUser
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
def send_confirmation_email
|
45
|
-
VoucherMailer.send_confirmation_link(self).deliver
|
46
|
-
end
|
1
|
+
class VoucherUser < ActiveRecord::Base
|
2
|
+
attr_accessible :confirmation_date, :confirmed, :email, :name
|
3
|
+
|
4
|
+
belongs_to :voucher
|
5
|
+
|
6
|
+
attr_protected :confirmed, :confirmation_date
|
7
|
+
validates_presence_of :name, :email
|
8
|
+
validates :email, email: true
|
9
|
+
|
10
|
+
after_create :send_confirmation_email
|
11
|
+
|
12
|
+
|
13
|
+
def confirm
|
14
|
+
@confirmed = true
|
15
|
+
@confirmation_date = Time.now
|
16
|
+
@save
|
17
|
+
end
|
18
|
+
|
19
|
+
# @param voucher instance of Voucher
|
20
|
+
def already_required(voucher)
|
21
|
+
user = VoucherUser.where({voucher_id: voucher[:id], id: @attributes['id']}).first
|
22
|
+
if user
|
23
|
+
true
|
24
|
+
else
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_confirmed(voucher)
|
30
|
+
user = VoucherUser.where({voucher_id: voucher[:id], id: @attributes['id'], confirmed: true}).first
|
31
|
+
if user
|
32
|
+
true
|
33
|
+
else
|
34
|
+
false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def send_confirmation_email
|
39
|
+
VoucherMailer.send_confirmation_link(self).deliver
|
40
|
+
end
|
41
|
+
|
47
42
|
|
48
43
|
end
|
@@ -15,13 +15,13 @@ class Vouchers::PhotoUploader < CarrierWave::Uploader::Base
|
|
15
15
|
# include Sprockets::Helpers::IsolatedHelper
|
16
16
|
|
17
17
|
# Choose what kind of storage to use for this uploader:
|
18
|
-
|
18
|
+
|
19
19
|
# storage :fog
|
20
20
|
|
21
21
|
# Override the directory where uploaded files will be stored.
|
22
22
|
# This is a sensible default for uploaders that are meant to be mounted:
|
23
23
|
def store_dir
|
24
|
-
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
24
|
+
"system/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
25
25
|
end
|
26
26
|
|
27
27
|
def cache_dir
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateVouchers < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :vouchers do |t|
|
4
|
+
t.string :name
|
5
|
+
t.text :rules
|
6
|
+
t.date :date_from
|
7
|
+
t.date :date_to
|
8
|
+
t.string :photo
|
9
|
+
t.string :partner_photo
|
10
|
+
t.string :slug
|
11
|
+
|
12
|
+
t.timestamps
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/mix-rails-vouchers.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mix-rails-vouchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.23.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-02-
|
13
|
+
date: 2013-02-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mail_form
|
@@ -44,22 +44,6 @@ dependencies:
|
|
44
44
|
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: 3.2.9
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: carrierwave-mongoid
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.3.0
|
55
|
-
type: :runtime
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
|
-
requirements:
|
60
|
-
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
version: 0.3.0
|
63
47
|
description: Vouchers module for mix-rails
|
64
48
|
email:
|
65
49
|
- rafbgarcia@gmail.com
|
@@ -93,6 +77,8 @@ files:
|
|
93
77
|
- app/views/voucher_mailer/send_confirmation_link.text.erb
|
94
78
|
- config/locales/vouchers.pt-BR.yml
|
95
79
|
- config/routes.rb
|
80
|
+
- db/migrate/20130208143458_create_vouchers.rb
|
81
|
+
- db/migrate/20130208143613_create_voucher_users.rb
|
96
82
|
- lib/mix-rails-vouchers/version.rb
|
97
83
|
- lib/mix-rails-vouchers/engine.rb
|
98
84
|
- lib/tasks/mix-vouchers_tasks.rake
|
@@ -114,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
100
|
version: '0'
|
115
101
|
segments:
|
116
102
|
- 0
|
117
|
-
hash:
|
103
|
+
hash: 1731212907017249748
|
118
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
105
|
none: false
|
120
106
|
requirements:
|
@@ -123,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
109
|
version: '0'
|
124
110
|
segments:
|
125
111
|
- 0
|
126
|
-
hash:
|
112
|
+
hash: 1731212907017249748
|
127
113
|
requirements: []
|
128
114
|
rubyforge_project:
|
129
115
|
rubygems_version: 1.8.24
|