Class: Kit
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Kit
- Includes:
- ActiveRecord::Transitions, Ext::Integrations::Kit
- Defined in:
- app/models/kit.rb
Direct Known Subclasses
MailchimpKit, MembershipKit, PassesKit, RegularDonationKit, RelationshipsKit, ResellerKit, ScannableTicketsKit, SponsoredDonationKit, TicketingKit
Defined Under Namespace
Classes: DuplicateError
Class Method Summary collapse
- .activate(options) ⇒ Object
- .activation_requirements ⇒ Object
- .acts_as_kit(options = {}, &block) ⇒ Object
- .admin_approval_requirements ⇒ Object
- .admin_approve(options) ⇒ Object
- .approval_requirements ⇒ Object
- .approve(options) ⇒ Object
- .mailchimp ⇒ Object
- .pad_with_new_kits(kits = []) ⇒ Object
- .subklasses ⇒ Object
- .visible ⇒ Object
- .when_active(&block) ⇒ Object
Instance Method Summary collapse
- #abilities ⇒ Object
- #activatable? ⇒ Boolean
- #admin_approvable? ⇒ Boolean
- #alternatives ⇒ Object
- #approvable? ⇒ Boolean
- #has_alternatives? ⇒ Boolean
- #requirements_met? ⇒ Boolean
Methods included from Ext::Integrations::Kit
#record_activation, #record_approval
Class Method Details
.activate(options) ⇒ Object
42 43 44 45 |
# File 'app/models/kit.rb', line 42 def self.activate() activation_requirements[:unless] << .delete(:unless) if .has_key?(:unless) activation_requirements[:if] << .delete(:if) if .has_key?(:if) end |
.activation_requirements ⇒ Object
57 58 59 |
# File 'app/models/kit.rb', line 57 def self.activation_requirements @requirements ||= Hash.new { |h,k| h[k] = [] } end |
.acts_as_kit(options = {}, &block) ⇒ Object
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 |
# File 'app/models/kit.rb', line 14 def self.acts_as_kit( = {}, &block) self.requires_approval = .delete(:with_approval) || false self.restricted_to_admins = .delete(:admin_only) || false state_machine do state :fresh state :pending, :enter => :on_pending state :activated, :enter => :on_activation state :cancelled event(:activate, :success => :record_activation) { transitions :from => [:fresh, :pending], :to => :activated, :guard => :activatable? } event(:approve, :success => :record_approval) { transitions :from => :pending, :to => :activated, :guard => :approvable? } event(:admin_approve, :success => :record_approval) { transitions :from => :pending, :to => :activated, :guard => :admin_approvable? } event(:cancel) { transitions :from => [:activated, :pending, :rejected ], :to => :cancelled } event(:reactivate) { transitions :from => :cancelled, :to => :activated, :guard => :activatable? } event(:activate_without_pending) { transitions :from => [:fresh, :pending, :cancelled], :to => :activated } end if self.requires_approval state_machine do event(:submit_for_approval) { transitions :from => :fresh, :to => :pending } end end class_eval(&block) self end |
.admin_approval_requirements ⇒ Object
65 66 67 |
# File 'app/models/kit.rb', line 65 def self.admin_approval_requirements @admin_approval_requirements ||= Hash.new { |h,k| h[k] = [] } end |
.admin_approve(options) ⇒ Object
52 53 54 55 |
# File 'app/models/kit.rb', line 52 def self.admin_approve() admin_approval_requirements[:unless] << .delete(:unless) if .has_key?(:unless) admin_approval_requirements[:if] << .delete(:if) if .has_key?(:if) end |
.approval_requirements ⇒ Object
61 62 63 |
# File 'app/models/kit.rb', line 61 def self.approval_requirements @approval_requirements ||= Hash.new { |h,k| h[k] = [] } end |
.approve(options) ⇒ Object
47 48 49 50 |
# File 'app/models/kit.rb', line 47 def self.approve() approval_requirements[:unless] << .delete(:unless) if .has_key?(:unless) approval_requirements[:if] << .delete(:if) if .has_key?(:if) end |
.mailchimp ⇒ Object
85 86 87 |
# File 'app/models/kit.rb', line 85 def self.mailchimp find_by_type("MailchimpKit") end |
.pad_with_new_kits(kits = []) ⇒ Object
77 78 79 80 81 82 83 |
# File 'app/models/kit.rb', line 77 def self.pad_with_new_kits(kits = []) types = kits.collect(&:type) alternatives = kits.collect(&:alternatives).flatten.uniq padding = subklasses.reject{ |klass| klass.to_s == "SponsoredDonationKit" }.reject{ |klass| (types.include? klass.to_s) or (alternatives.include? klass) }.collect(&:new) kits + padding end |
.subklasses ⇒ Object
73 74 75 |
# File 'app/models/kit.rb', line 73 def self.subklasses @subklasses ||= [ TicketingKit, RegularDonationKit, SponsoredDonationKit, ResellerKit, MailchimpKit, MembershipKit, PassesKit, ScannableTicketsKit, RelationshipsKit ].freeze end |
.visible ⇒ Object
10 11 12 |
# File 'app/models/kit.rb', line 10 def self.visible where(Kit.arel_table[:state].eq("activated").or(Kit.arel_table[:state].eq('pending'))) end |
.when_active(&block) ⇒ Object
69 70 71 |
# File 'app/models/kit.rb', line 69 def self.when_active(&block) self.ability_proc = Proc.new(&block) end |
Instance Method Details
#abilities ⇒ Object
89 90 91 |
# File 'app/models/kit.rb', line 89 def abilities activated? ? self.class.ability_proc : Proc.new {} end |
#activatable? ⇒ Boolean
105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/models/kit.rb', line 105 def activatable? return false if organization.nil? if needs_approval? check_requirements submit_for_approval! return false end check_requirements end |
#admin_approvable? ⇒ Boolean
121 122 123 |
# File 'app/models/kit.rb', line 121 def admin_approvable? check_admin_approval end |
#alternatives ⇒ Object
97 98 99 |
# File 'app/models/kit.rb', line 97 def alternatives [] end |
#approvable? ⇒ Boolean
117 118 119 |
# File 'app/models/kit.rb', line 117 def approvable? check_approval end |
#has_alternatives? ⇒ Boolean
93 94 95 |
# File 'app/models/kit.rb', line 93 def has_alternatives? alternatives.any? end |
#requirements_met? ⇒ Boolean
101 102 103 |
# File 'app/models/kit.rb', line 101 def requirements_met? check_requirements end |