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.
@@ -2,7 +2,7 @@ class Admix::VouchersDatagrid
2
2
  include Datagrid
3
3
 
4
4
  scope do
5
- Voucher.all
5
+ Voucher
6
6
  end
7
7
  column :name, header: I18n.t('vouchers.fields.name')
8
8
 
@@ -1,22 +1,18 @@
1
- class Voucher
2
- include Mongoid::Document
3
- include Mongoid::Timestamps
4
- include Mongoid::Slug
1
+ class Voucher < ActiveRecord::Base
2
+ extend FriendlyId
5
3
 
6
- scope :actives, -> { where({:date_from.lte => Date.today, :date_to.gte => Date.today}) }
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
- slug :name, history: true do |voucher|
20
- voucher.name.parameterize
21
- end
16
+ friendly_id :name, use: :slugged
17
+
22
18
  end
@@ -1,48 +1,43 @@
1
- class VoucherUser
2
- include Mongoid::Document
3
- include Mongoid::Timestamps
4
-
5
- field :name, type: String
6
- field :email, type: String
7
- field :confirmed, type: Boolean, default: false
8
- field :confirmation_date, type: Date
9
-
10
- belongs_to :voucher
11
-
12
- attr_protected :confirmed, :confirmation_date
13
- validates_presence_of :name, :email
14
- validates :email, email: true
15
-
16
- after_create :send_confirmation_email
17
-
18
-
19
- def confirm
20
- @confirmed = true
21
- @confirmation_date = Time.now
22
- @save
23
- end
24
-
25
- # @param voucher instance of Voucher
26
- def already_required(voucher)
27
- user = VoucherUser.where({voucher_id: voucher[:_id], _id: @attributes['_id']}).first
28
- if user
29
- true
30
- else
31
- false
32
- end
33
- end
34
-
35
- def has_confirmed(voucher)
36
- user = VoucherUser.where({voucher_id: voucher[:_id], _id: @attributes['_id'], confirmed: true}).first
37
- if user
38
- true
39
- else
40
- false
41
- end
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
- storage :grid_fs
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
@@ -0,0 +1,13 @@
1
+ class CreateVoucherUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :voucher_users do |t|
4
+ t.string :name
5
+ t.string :email
6
+ t.boolean :confirmed
7
+ t.date :confirmation_date
8
+
9
+ t.references :voucher
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,4 @@
1
1
  require "mix-rails-vouchers/engine"
2
- require "carrierwave/mongoid"
3
2
 
4
3
  module MixRailsVouchers
5
4
  end
@@ -1,7 +1,7 @@
1
1
  module MixRailsVouchers
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 22
4
+ MINOR = 23
5
5
  TINY = 0
6
6
  PRE = nil
7
7
 
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.22.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-06 00:00:00.000000000 Z
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: 1388943337525574068
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: 1388943337525574068
112
+ hash: 1731212907017249748
127
113
  requirements: []
128
114
  rubyforge_project:
129
115
  rubygems_version: 1.8.24