Class: PaidUp::Plan
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- PaidUp::Plan
- Defined in:
- app/models/paid_up/plan.rb
Overview
PaidUp Plan model
Instance Attribute Summary collapse
-
#stripe_data ⇒ Object
Returns the value of attribute stripe_data.
Instance Method Summary collapse
- #amount ⇒ Object
- #charge ⇒ Object
- #currency ⇒ Object
- #feature_setting(feature_name) ⇒ Object
- #feature_unlimited?(feature_name) ⇒ Boolean
- #interval ⇒ Object
- #interval_count ⇒ Object
- #money ⇒ Object
- #reload(*args, &blk) ⇒ Object
Instance Attribute Details
#stripe_data ⇒ Object
Returns the value of attribute stripe_data.
15 16 17 |
# File 'app/models/paid_up/plan.rb', line 15 def stripe_data @stripe_data end |
Instance Method Details
#amount ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/models/paid_up/plan.rb', line 74 def amount if stripe_data.present? stripe_data.amount else 0 end end |
#charge ⇒ Object
86 87 88 |
# File 'app/models/paid_up/plan.rb', line 86 def charge money.amount end |
#currency ⇒ Object
90 91 92 93 94 95 96 |
# File 'app/models/paid_up/plan.rb', line 90 def currency if stripe_data.present? stripe_data.currency.upcase else :default_currency.l.upcase end end |
#feature_setting(feature_name) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/paid_up/plan.rb', line 32 def feature_setting(feature_name) feature = PaidUp::Feature.find_by_slug(feature_name) || raise(:feature_not_found.l) raw = plan_feature_settings.where(feature: feature_name) case feature.setting_type when 'boolean' if raw.empty? false else raw.first.setting != 0 end when 'table_rows', 'rolify_rows' if raw.empty? 0 else raw.first.setting end else raise :error_handling_feature_setting.l feature: feature end end |
#feature_unlimited?(feature_name) ⇒ Boolean
54 55 56 |
# File 'app/models/paid_up/plan.rb', line 54 def feature_unlimited?(feature_name) feature_setting(feature_name) == PaidUp::Unlimited.to_i end |
#interval ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/models/paid_up/plan.rb', line 58 def interval if stripe_data.present? stripe_data.interval else :default_interval.l end end |
#interval_count ⇒ Object
66 67 68 69 70 71 72 |
# File 'app/models/paid_up/plan.rb', line 66 def interval_count if stripe_data.present? stripe_data.interval_count else 1 end end |
#money ⇒ Object
82 83 84 |
# File 'app/models/paid_up/plan.rb', line 82 def money Money.new(amount, currency) end |
#reload(*args, &blk) ⇒ Object
26 27 28 29 30 |
# File 'app/models/paid_up/plan.rb', line 26 def reload(*args, &blk) super(*args, &blk) load_stripe_data self end |