paid_up 0.13.5 → 0.13.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 771072f0a7877fd4d05487ecbf96da45af6f0b2cc40a279b45daa68eb8d5d445
4
- data.tar.gz: d6b8d8e64c3377e5e5cfb62983ac319b82cdc9d0d5640eb6d6d1d865f1226789
3
+ metadata.gz: fd4aa53725c15d418c3798c8b7d8a4dea31e0ff1f114ca425d063b67896e75d2
4
+ data.tar.gz: c10e4d754c584056c161f98a164a526c33047356b2b8f0120daa5fc8b29862e2
5
5
  SHA512:
6
- metadata.gz: 3a7129b2b0de5d27094e977f64d39273d9e41240148f37c61fb77d3e542f6b4ac5c0e1f4d29585ed8601c31121e4789b41806b32c753be6af84150b1473ef8b0
7
- data.tar.gz: 2523f6baf9b3d7eacd444d09ba04f60ab4661d688d6a64ed8a30c85ed768240cf790ebc6b1dff7adcaa957aa76aef1e6bf14851f7ee0f12cfd510596d15deb5b
6
+ metadata.gz: 3bf0feabd9990f7f6259377138cd4a6f937a07c80feba530de59bcfac12d1113353de804e9b049d88620c68444883cf07287499aa6a17d9d619653437a13206e
7
+ data.tar.gz: e2c416e17d6f7b9da15da8c00c088a9c8f96c7d6a5ea4d3a26ba716de16cd67ba2428623ad0b70008be648e0e1378538a29df6db959f4b50577c24344a899673
data/README.md CHANGED
@@ -104,11 +104,15 @@ Abilities corresponding to features you have defined will be generated automatic
104
104
 
105
105
  ## Speeding up User queries
106
106
 
107
- If you try generating a list of users for display in a directory, you may find
108
- that the Stripe checking code slows down your query.
107
+ If you try generating a list of users (such as for display in a user directory), you may find
108
+ that the Stripe checking code slows down your query significantly.
109
109
 
110
110
  To avoid this, add "select(:field_1, :field_2, :etc)" to your finder, being
111
111
  sure to *omit* the :stripe_id column.
112
+
113
+ Another option would be to create a Person model that inherits from the User model but omits the :stripe_id column
114
+ (as above) in its `default_scope`. You can use this Person object for queries related to directory or profile display,
115
+ thereby speeding up all queries not requiring plan information.
112
116
 
113
117
  ## Controller
114
118
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.13.5
1
+ 0.13.6
@@ -59,7 +59,7 @@ module PaidUp
59
59
 
60
60
  def enable_boolean(user, feature)
61
61
  slug = feature.slug
62
- can :use, slug.to_sym if user.plan.feature_setting slug
62
+ can :use, slug.to_sym if user.plan&.feature_setting slug
63
63
  end
64
64
  end
65
65
  end
@@ -11,7 +11,7 @@ module PaidUp
11
11
  )
12
12
  accepts_nested_attributes_for :plan_feature_settings
13
13
 
14
- after_initialize :load_stripe_data
14
+ after_initialize :load_stripe_data, :load_feature_settings
15
15
  after_save :expire_stripe_data
16
16
 
17
17
  attr_accessor :stripe_data
@@ -39,19 +39,35 @@ module PaidUp
39
39
  self
40
40
  end
41
41
 
42
- def feature_setting(feature_name)
43
- feature = PaidUp::Feature.find_by_slug!(feature_name)
44
- raw = plan_feature_settings.where(feature: feature_name)
45
- case feature.setting_type
42
+ def load_feature_settings
43
+ @feature_settings = {}
44
+ settings = {}
45
+
46
+ plan_feature_settings.each do |feature_setting|
47
+ settings[feature_setting.feature] = feature_setting.setting
48
+ end
49
+
50
+ PaidUp::Feature.all.each do |feature|
51
+ slug = feature.slug
52
+ @feature_settings[slug] = parse_setting_by_type(feature.setting_type, settings[slug])
53
+ end
54
+ end
55
+
56
+ def parse_setting_by_type(setting_type, setting)
57
+ case setting_type
46
58
  when 'boolean'
47
- raw&.first&.setting == 1
59
+ setting == 1
48
60
  when 'table_rows', 'rolify_rows'
49
- raw&.first&.setting || 0
61
+ setting || 0
50
62
  else
51
63
  raise :error_handling_feature_setting.l feature: feature
52
64
  end
53
65
  end
54
66
 
67
+ def feature_setting(feature_name)
68
+ @feature_settings[feature_name]
69
+ end
70
+
55
71
  def feature_unlimited?(feature_name)
56
72
  feature_setting(feature_name) == PaidUp::Unlimited.to_i
57
73
  end
data/paid_up.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: paid_up 0.13.5 ruby lib
5
+ # stub: paid_up 0.13.6 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "paid_up".freeze
9
- s.version = "0.13.5"
9
+ s.version = "0.13.6"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Karen Lundgren".freeze]
14
- s.date = "2018-05-31"
14
+ s.date = "2018-09-09"
15
15
  s.description = "Allows a model of your choosing (such as users) to subscribe to a plan, which enables features.".freeze
16
16
  s.email = "karen.e.lundgren@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -177,7 +177,7 @@ Gem::Specification.new do |s|
177
177
  ]
178
178
  s.homepage = "http://www.gemvein.com/museum/cases/paid_up".freeze
179
179
  s.licenses = ["MIT".freeze]
180
- s.rubygems_version = "2.7.6".freeze
180
+ s.rubygems_version = "2.7.7".freeze
181
181
  s.summary = "Allows a model of your choosing to subscribe to a plan, which enables features.".freeze
182
182
 
183
183
  if s.respond_to? :specification_version then
Binary file
@@ -2,7 +2,7 @@
2
2
 
3
3
  FactoryBot.define do
4
4
  factory :doodad do
5
- name 'Test Name'
5
+ name { 'Test Name'}
6
6
  user { User.order('RANDOM()').first }
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  FactoryBot.define do
4
4
  factory :group do
5
- title 'Test Title'
5
+ title { 'Test Title' }
6
6
  transient do
7
7
  owner { User.order('RANDOM()').first }
8
8
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  FactoryBot.define do
4
4
  factory :plan, class: 'PaidUp::Plan' do
5
- title 'Plan Title'
6
- description 'This is the description'
7
- sort_order 0
5
+ title { 'Plan Title' }
6
+ description { 'This is the description' }
7
+ sort_order { 0 }
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  FactoryBot.define do
4
4
  factory :plan_feature_setting, class: 'PaidUp::PlanFeatureSetting' do
5
- feature nil
6
- plan nil
7
- setting 1
5
+ feature { nil }
6
+ plan { nil }
7
+ setting { 1 }
8
8
  end
9
9
  end
@@ -2,8 +2,8 @@
2
2
 
3
3
  FactoryBot.define do
4
4
  factory :post do
5
- title 'Test Title'
5
+ title { 'Test Title' }
6
6
  user { User.order('RANDOM()').first }
7
- active true
7
+ active { true }
8
8
  end
9
9
  end
@@ -5,11 +5,11 @@ FactoryBot.define do
5
5
  sequence :email do |n|
6
6
  "#{name.tr(' ', '.').downcase}#{n}@example.com"
7
7
  end
8
- password 'password'
9
- password_confirmation 'password'
8
+ password { 'password' }
9
+ password_confirmation { 'password' }
10
10
  transient do
11
11
  plan { PaidUp::Plan.all.sample }
12
- past_due false
12
+ past_due { false }
13
13
  end
14
14
  # the after(:create) yields two values; the user instance itself and the
15
15
  # evaluator, which stores all values from the factory, including transient
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paid_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.5
4
+ version: 0.13.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Karen Lundgren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-31 00:00:00.000000000 Z
11
+ date: 2018-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml-rails
@@ -664,7 +664,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
664
664
  version: '0'
665
665
  requirements: []
666
666
  rubyforge_project:
667
- rubygems_version: 2.7.6
667
+ rubygems_version: 2.7.7
668
668
  signing_key:
669
669
  specification_version: 4
670
670
  summary: Allows a model of your choosing to subscribe to a plan, which enables features.