paid_up 0.9.13 → 0.9.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -0
  3. data/Gemfile +5 -1
  4. data/Rakefile +12 -10
  5. data/VERSION +1 -1
  6. data/app/controllers/paid_up/paid_up_controller.rb +8 -3
  7. data/app/controllers/paid_up/plans_controller.rb +2 -1
  8. data/app/controllers/paid_up/subscriptions_controller.rb +19 -6
  9. data/app/helpers/paid_up/features_helper.rb +19 -6
  10. data/app/helpers/paid_up/paid_up_helper.rb +6 -3
  11. data/app/helpers/paid_up/plans_helper.rb +12 -5
  12. data/app/helpers/paid_up/subscriptions_helper.rb +10 -3
  13. data/app/models/paid_up/ability.rb +43 -44
  14. data/app/models/paid_up/plan.rb +81 -69
  15. data/app/models/paid_up/plan_feature_setting.rb +17 -9
  16. data/app/models/paid_up/unlimited.rb +15 -13
  17. data/app/views/devise/confirmations/new.html.haml +1 -1
  18. data/app/views/devise/passwords/edit.html.haml +1 -1
  19. data/app/views/devise/passwords/new.html.haml +1 -1
  20. data/app/views/devise/registrations/_new_form.html.haml +1 -1
  21. data/app/views/devise/registrations/new.html.haml +1 -1
  22. data/app/views/devise/sessions/new.html.haml +1 -1
  23. data/app/views/devise/unlocks/new.html.haml +1 -1
  24. data/app/views/layouts/mailer.html.haml +1 -1
  25. data/app/views/layouts/mailer.text.haml +1 -1
  26. data/app/views/paid_up/features/_abilities_table.html.haml +1 -1
  27. data/app/views/paid_up/plans/index.html.haml +1 -1
  28. data/app/views/paid_up/subscriptions/new.html.haml +1 -1
  29. data/config/initializers/stripe.rb +3 -3
  30. data/coverage/.last_run.json +1 -1
  31. data/coverage/.resultset.json +414 -253
  32. data/db/migrate/20150407110101_create_paid_up_plans_table.rb +3 -3
  33. data/lib/generators/paid_up/install/install_generator.rb +42 -33
  34. data/lib/generators/paid_up/install/templates/ability.rb +1 -0
  35. data/lib/generators/paid_up/install/templates/initializer.rb +16 -14
  36. data/lib/generators/paid_up/utils.rb +11 -4
  37. data/lib/paid_up/configuration.rb +13 -8
  38. data/lib/paid_up/engine.rb +4 -3
  39. data/lib/paid_up/extensions/integer.rb +8 -5
  40. data/lib/paid_up/extensions/stripe.rb +10 -9
  41. data/lib/paid_up/feature.rb +27 -17
  42. data/lib/paid_up/localization.rb +17 -18
  43. data/lib/paid_up/mixins/paid_for.rb +66 -54
  44. data/lib/paid_up/mixins/subscriber.rb +154 -161
  45. data/lib/paid_up/railtie.rb +1 -1
  46. data/lib/paid_up/validators/rolify_rows.rb +14 -6
  47. data/lib/paid_up/validators/table_rows.rb +14 -6
  48. data/lib/paid_up/version.rb +1 -1
  49. data/lib/paid_up.rb +7 -8
  50. data/paid_up.gemspec +21 -8
  51. data/spec/controllers/paid_up/plans_spec.rb +6 -6
  52. data/spec/controllers/paid_up/subscriptions_spec.rb +68 -68
  53. data/spec/dummy/Rakefile +2 -1
  54. data/spec/dummy/app/assets/stylesheets/application.css.scss +3 -16
  55. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  56. data/spec/dummy/app/models/doodad.rb +1 -1
  57. data/spec/dummy/app/models/group.rb +1 -1
  58. data/spec/dummy/app/models/role.rb +4 -4
  59. data/spec/dummy/app/models/user.rb +1 -1
  60. data/spec/dummy/app/views/layouts/application.html.haml +2 -2
  61. data/spec/dummy/app/views/pages/index.html.haml +1 -1
  62. data/spec/dummy/config/application.rb +16 -12
  63. data/spec/dummy/config/environments/development.rb +4 -3
  64. data/spec/dummy/config/environments/production.rb +10 -6
  65. data/spec/dummy/config/environments/test.rb +3 -2
  66. data/spec/dummy/config/initializers/assets.rb +2 -1
  67. data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -2
  68. data/spec/dummy/config/initializers/devise.rb +58 -42
  69. data/spec/dummy/config/initializers/high_voltage.rb +1 -1
  70. data/spec/dummy/config/initializers/mime_types.rb +1 -1
  71. data/spec/dummy/config/initializers/paid_up.rb +16 -14
  72. data/spec/dummy/config/initializers/rolify.rb +3 -2
  73. data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
  74. data/spec/dummy/config/routes.rb +2 -2
  75. data/spec/dummy/db/migrate/20150523010827_add_devise_to_users.rb +2 -2
  76. data/spec/dummy/db/migrate/20150523010837_rolify_create_roles.rb +2 -2
  77. data/spec/dummy/db/migrate/20160207184112_create_paid_up_plans_table.paid_up.rb +3 -3
  78. data/spec/dummy/db/schema.rb +53 -53
  79. data/spec/dummy/db/seeds.rb +41 -56
  80. data/spec/dummy/db/test.sqlite3 +0 -0
  81. data/spec/dummy/lib/tasks/system.rake +2 -2
  82. data/spec/factories/group.rb +1 -1
  83. data/spec/factories/plan.rb +1 -1
  84. data/spec/factories/plan_feature_setting.rb +1 -1
  85. data/spec/factories/user.rb +13 -11
  86. data/spec/models/group_spec.rb +8 -7
  87. data/spec/models/paid_up/feature_spec.rb +18 -4
  88. data/spec/models/paid_up/plan_feature_setting_spec.rb +2 -2
  89. data/spec/models/paid_up/plan_spec.rb +12 -8
  90. data/spec/models/user_spec.rb +88 -78
  91. data/spec/paid_up_spec.rb +1 -1
  92. data/spec/rails_helper.rb +5 -5
  93. data/spec/routing/paid_up/plans_spec.rb +3 -3
  94. data/spec/routing/paid_up/subscription_spec.rb +30 -7
  95. data/spec/spec_helper.rb +7 -52
  96. data/spec/support/controller_macros.rb +2 -2
  97. data/spec/support/factory_girl.rb +1 -1
  98. data/spec/support/{features.rb → loaded_site/features.rb} +2 -2
  99. data/spec/support/{groups.rb → loaded_site/groups.rb} +1 -1
  100. data/spec/support/{loaded_site.rb → loaded_site/loaded_site.rb} +1 -1
  101. data/spec/support/{plans.rb → loaded_site/plans.rb} +8 -4
  102. data/spec/support/{users.rb → loaded_site/users.rb} +1 -1
  103. data/spec/support/stripe.rb +10 -13
  104. data/spec/views/paid_up/plans_spec.rb +17 -17
  105. data/spec/views/paid_up/subscriptions_spec.rb +24 -14
  106. metadata +64 -7
@@ -8,7 +8,7 @@ class CreatePaidUpPlansTable < ActiveRecord::Migration
8
8
 
9
9
  t.timestamps
10
10
  end
11
- add_index :paid_up_plans, :title, :unique => true
12
- add_index :paid_up_plans, :stripe_id, :unique => true
11
+ add_index :paid_up_plans, :title, unique: true
12
+ add_index :paid_up_plans, :stripe_id, unique: true
13
13
  end
14
- end
14
+ end
@@ -1,66 +1,75 @@
1
1
  module PaidUp
2
+ # PaidUp Install Generator
2
3
  class InstallGenerator < Rails::Generators::Base
3
- argument :user_model_name, :type => :string, :default => "User"
4
- source_root File.expand_path("../templates", __FILE__)
4
+ argument :user_model_name, type: :string, default: 'User'
5
+ source_root File.expand_path('../templates', __FILE__)
5
6
  require File.expand_path('../../utils', __FILE__)
6
7
  include Generators::Utils
7
8
  include Rails::Generators::Migration
8
9
 
9
10
  def hello
10
- output "PaidUp Installer will now install itself", :magenta
11
+ output 'PaidUp Installer will now install itself', :magenta
11
12
  end
12
13
 
13
14
  # all public methods in here will be run in order
14
15
 
15
16
  def install_devise
16
- output "To start with, Devise is used to authenticate users. No need to install it separately, I'll do that now.", :magenta
17
- generate("devise:install")
18
- generate("devise User")
17
+ output(
18
+ 'To start with, Devise is used to authenticate users. No need to '\
19
+ "install it separately, I'll do that now.", :magenta)
20
+ generate('devise:install')
21
+ generate('devise User')
19
22
  end
20
23
 
21
24
  def install_cancan
22
- output "For authorization, PaidUp uses CanCan. Let's get you started with a customizable ability.rb file.", :magenta
23
- template "ability.rb", "app/models/ability.rb"
25
+ output(
26
+ "For authorization, PaidUp uses CanCanCan. Let's get you started "\
27
+ 'with a customizable ability.rb file.',
28
+ :magenta
29
+ )
30
+ template 'ability.rb', 'app/models/ability.rb'
24
31
  end
25
32
 
26
33
  def install_rolify
27
- output "To provide varying roles for Users, we'll use Rolify. Let's set that up now.", :magenta
28
- generate("rolify", "Role User")
34
+ output(
35
+ "To provide varying roles for Users, we'll use Rolify. Let's set that "\
36
+ 'up now.',
37
+ :magenta
38
+ )
39
+ generate('rolify', 'Role User')
29
40
  end
30
41
 
31
42
  def add_initializer
32
- output "Next, you'll need an initializer. This is where you put your configuration options.", :magenta
33
- template "initializer.rb", "config/initializers/paid_up.rb"
43
+ output(
44
+ "Next, you'll need an initializer. This is where you put your "\
45
+ 'configuration options.',
46
+ :magenta
47
+ )
48
+ template 'initializer.rb', 'config/initializers/paid_up.rb'
34
49
  end
35
50
 
36
51
  def add_migrations
37
- output "Next come migrations.", :magenta
52
+ output 'Next come migrations.', :magenta
38
53
  rake 'paid_up:install:migrations'
39
54
  end
40
55
 
41
56
  def add_to_model
42
- output "Adding PaidUp to your User model", :magenta
43
- gsub_file "app/models/user.rb", /^\n subscriber$/, ''
44
- inject_into_file "app/models/user.rb", "\n subscriber", after: "class User < ActiveRecord::Base"
57
+ output 'Adding PaidUp to your User model', :magenta
58
+ gsub_file 'app/models/user.rb', /^\n subscriber$/, ''
59
+ inject_into_file(
60
+ 'app/models/user.rb', "\n subscriber",
61
+ after: 'class User < ActiveRecord::Base'
62
+ )
45
63
  end
46
64
 
47
65
  def add_route
48
- output "Adding PaidUp to your routes.rb file", :magenta
49
- gsub_file "config/routes.rb", /mount PaidUp::Engine => '\/.*', :as => 'paid_up'/, ''
50
- route("mount PaidUp::Engine => '/', :as => 'paid_up'")
51
- end
52
-
53
- def self.next_migration_number(dirname)
54
- if ActiveRecord::Base.timestamped_migrations
55
- unless @prev_migration_nr
56
- @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
57
- else
58
- @prev_migration_nr += 1
59
- end
60
- @prev_migration_nr.to_s
61
- else
62
- "%.3d" % (current_migration_number(dirname) + 1)
63
- end
66
+ output 'Adding PaidUp to your routes.rb file', :magenta
67
+ gsub_file(
68
+ 'config/routes.rb',
69
+ %r{mount PaidUp::Engine => '/.*', as: 'paid_up'},
70
+ ''
71
+ )
72
+ route("mount PaidUp::Engine => '/', as: 'paid_up'")
64
73
  end
65
74
  end
66
- end
75
+ end
@@ -1,3 +1,4 @@
1
+ # CanCanCan Ability class
1
2
  class Ability
2
3
  include CanCan::Ability
3
4
  include PaidUp::Ability
@@ -4,22 +4,24 @@ PaidUp.configure do |config|
4
4
  config.free_plan_stripe_id = 'free-plan'
5
5
 
6
6
  PaidUp.add_feature(
7
- slug: 'ad_free',
8
- title: 'Ad Free',
9
- description: 'Are ads removed from the site with this plan?',
10
- setting_type: 'boolean'
7
+ slug: 'ad_free',
8
+ title: 'Ad Free',
9
+ description: 'Are ads removed from the site with this plan?',
10
+ setting_type: 'boolean'
11
11
  )
12
12
  PaidUp.add_feature(
13
- slug: 'groups',
14
- title: 'Groups',
15
- description: 'How many groups are allowed with this plan?',
16
- setting_type: 'table_rows' # Enables table row counting that is enabled by a positive value
17
- # for the PaidUp::PlanFeatureSetting.setting associated with this PaidUp::Feature
13
+ slug: 'groups',
14
+ title: 'Groups',
15
+ description: 'How many groups are allowed with this plan?',
16
+ # Table row counting: feature enabled by a positive value
17
+ # for the PaidUp::PlanFeatureSetting.setting associated with this
18
+ # PaidUp::Feature
19
+ setting_type: 'table_rows'
18
20
  )
19
21
  PaidUp.add_feature(
20
- slug: 'doodads',
21
- title: 'Doodads',
22
- description: 'How many doodads included with this plan?',
23
- setting_type: 'rolify_rows'
22
+ slug: 'doodads',
23
+ title: 'Doodads',
24
+ description: 'How many doodads included with this plan?',
25
+ setting_type: 'rolify_rows'
24
26
  )
25
- end
27
+ end
@@ -1,16 +1,23 @@
1
1
  module PaidUp
2
2
  module Generators
3
+ # Generator Utilities
3
4
  module Utils
4
5
  def output(output, color = :green)
5
6
  say(" - #{output}", color)
6
7
  end
7
8
 
8
9
  def ask_for(wording, default_value = nil, override_if_present_value = nil)
9
- override_if_present_value.present? ?
10
- display("Using [#{override_if_present_value}] for question '#{wording}'") && override_if_present_value :
11
- ask(" ? #{wording} Press <enter> for [#{default_value}] >", :yellow).presence || default_value
10
+ if override_if_present_value.present?
11
+ display(
12
+ "Using [#{override_if_present_value}] for question '#{wording}'"
13
+ ) && override_if_present_value
14
+ else
15
+ ask(
16
+ " ? #{wording} Press <enter> for [#{default_value}] >",
17
+ :yellow
18
+ ).presence || default_value
19
+ end
12
20
  end
13
21
  end
14
22
  end
15
23
  end
16
-
@@ -1,8 +1,7 @@
1
+ # PaidUp Module
1
2
  module PaidUp
2
3
  def self.configure(configuration = PaidUp::Configuration.new)
3
- if block_given?
4
- yield configuration
5
- end
4
+ block_given? && yield(configuration)
6
5
  @@configuration = configuration
7
6
  end
8
7
 
@@ -10,14 +9,20 @@ module PaidUp
10
9
  @@configuration ||= PaidUp::Configuration.new
11
10
  end
12
11
 
12
+ # PaidUp Configuration
13
13
  class Configuration
14
- attr_accessor :anonymous_customer_stripe_id, :anonymous_plan_stripe_id, :free_plan_stripe_id, :features
14
+ attr_accessor(
15
+ :anonymous_customer_stripe_id,
16
+ :anonymous_plan_stripe_id,
17
+ :free_plan_stripe_id,
18
+ :features
19
+ )
15
20
 
16
21
  def initialize
17
- self.anonymous_customer_stripe_id = "TODO"
18
- self.anonymous_plan_stripe_id = "TODO"
19
- self.free_plan_stripe_id = "TODO"
22
+ self.anonymous_customer_stripe_id = 'TODO'
23
+ self.anonymous_plan_stripe_id = 'TODO'
24
+ self.free_plan_stripe_id = 'TODO'
20
25
  self.features = {}
21
26
  end
22
27
  end
23
- end
28
+ end
@@ -1,7 +1,8 @@
1
1
  module PaidUp
2
+ # PaidUp Engine
2
3
  class Engine < Rails::Engine
3
4
  isolate_namespace PaidUp
4
- engine_name "paid_up"
5
+ engine_name 'paid_up'
5
6
 
6
7
  config.generators do |g|
7
8
  g.hidden_namespaces << 'test_unit' << 'erb'
@@ -18,5 +19,5 @@ module PaidUp
18
19
  def self.table_name_prefix
19
20
  'paid_up_'
20
21
  end
21
- end
22
- end
22
+ end
23
+ end
@@ -1,7 +1,10 @@
1
- module PaidUp::Extensions
2
- module Integer
3
- def to_date
4
- Time.at(self).strftime("%m/%d/%Y")
1
+ module PaidUp
2
+ module Extensions
3
+ # Integer extensions
4
+ module Integer
5
+ def to_date
6
+ Time.at(self).strftime('%m/%d/%Y')
7
+ end
5
8
  end
6
9
  end
7
- end
10
+ end
@@ -1,15 +1,16 @@
1
- module PaidUp::Extensions
2
- module Stripe
3
- extend ActiveSupport::Concern
4
- class_methods do
5
- def find_or_create_by_id(id, item)
6
- begin
7
- self.retrieve(id)
1
+ module PaidUp
2
+ module Extensions
3
+ # Stripe Extensions
4
+ module Stripe
5
+ extend ActiveSupport::Concern
6
+ class_methods do
7
+ def find_or_create_by_id(id, item)
8
+ retrieve(id)
8
9
  rescue
9
10
  item[:id] ||= id
10
- self.create(item)
11
+ create(item)
11
12
  end
12
13
  end
13
14
  end
14
15
  end
15
- end
16
+ end
@@ -1,5 +1,5 @@
1
+ # PaidUp module
1
2
  module PaidUp
2
-
3
3
  @@feature_object = {}
4
4
 
5
5
  def self.add_feature(params)
@@ -11,7 +11,7 @@ module PaidUp
11
11
  @@feature_object
12
12
  end
13
13
 
14
-
14
+ # Feature Class: Not an ActiveRecord object.
15
15
  class Feature
16
16
  include ActiveModel::Model
17
17
  include ActiveModel::AttributeMethods
@@ -19,9 +19,22 @@ module PaidUp
19
19
  attr_accessor :slug, :title, :setting_type, :description
20
20
 
21
21
  validates_presence_of :slug, :title, :setting_type
22
- validates :setting_type, inclusion: { in: %w(boolean table_rows rolify_rows) }
23
- validates_with PaidUp::Validators::TableRows, field: 'setting_type', comparison: 'table_rows', found_in: 'slug'
24
- validates_with PaidUp::Validators::RolifyRows, field: 'setting_type', comparison: 'rolify_rows', found_in: 'slug'
22
+ validates(
23
+ :setting_type,
24
+ inclusion: { in: %w(boolean table_rows rolify_rows) }
25
+ )
26
+ validates_with(
27
+ PaidUp::Validators::TableRows,
28
+ field: 'setting_type',
29
+ comparison: 'table_rows',
30
+ found_in: 'slug'
31
+ )
32
+ validates_with(
33
+ PaidUp::Validators::RolifyRows,
34
+ field: 'setting_type',
35
+ comparison: 'rolify_rows',
36
+ found_in: 'slug'
37
+ )
25
38
 
26
39
  def self.raw
27
40
  PaidUp.features
@@ -32,7 +45,7 @@ module PaidUp
32
45
  end
33
46
 
34
47
  def feature_model_name
35
- acceptable_setting_types = ['table_rows', 'rolify_rows']
48
+ acceptable_setting_types = %w( table_rows rolify_rows )
36
49
  unless acceptable_setting_types.include? setting_type
37
50
  raise :no_implicit_conversion_of_type_features.l(type: setting_type)
38
51
  end
@@ -53,16 +66,12 @@ module PaidUp
53
66
 
54
67
  def self.find_all(**conditions)
55
68
  collection = []
56
- for feature in all
69
+ all.each do |feature|
57
70
  qualifies = true
58
71
  conditions.each do |key, value|
59
- unless feature.send(key) == value
60
- qualifies = false
61
- end
62
- end
63
- if qualifies
64
- collection << feature
72
+ feature.send(key) != value && (qualifies = false)
65
73
  end
74
+ qualifies && collection << feature
66
75
  end
67
76
  collection
68
77
  end
@@ -73,11 +82,12 @@ module PaidUp
73
82
 
74
83
  # Define on self, since it's a class method
75
84
  def self.method_missing(method_sym, *arguments, &block)
76
- # the first argument is a Symbol, so you need to_s it if you want to pattern match
85
+ # the first argument is a Symbol, so you need to_s it if you want to
86
+ # pattern match
77
87
  if method_sym.to_s =~ /^find_by_(.*)$/
78
- self.find($1.to_sym => arguments.first)
88
+ find(Regexp.last_match[1].to_sym => arguments.first)
79
89
  elsif method_sym.to_s =~ /^find_all_by_(.*)$/
80
- self.find_all($1.to_sym => arguments.first)
90
+ find_all(Regexp.last_match[1].to_sym => arguments.first)
81
91
  else
82
92
  super
83
93
  end
@@ -87,4 +97,4 @@ module PaidUp
87
97
  method_name.to_s.start_with?('find_') || super
88
98
  end
89
99
  end
90
- end
100
+ end
@@ -1,31 +1,30 @@
1
+ # String Extension
1
2
  module StringExtension
2
3
  def localize(*args)
3
- if args.first.is_a? Symbol
4
- sym = args.shift
5
- else
6
- sym = underscore.tr(' ', '_').gsub(/[^a-z0-9_]+/i, '').to_sym
7
- end
8
- args << {:default => self}
9
-
4
+ sym = if args.first.is_a? Symbol
5
+ args.shift
6
+ else
7
+ underscore.tr(' ', '_').gsub(/[^a-z0-9_]+/i, '').to_sym
8
+ end
9
+ args << { default: self }
10
+
10
11
  I18n.t(sym, *args).html_safe
11
12
  end
12
- alias :l :localize
13
- end
13
+ alias l localize
14
+ end
14
15
  String.send :include, StringExtension
15
-
16
-
16
+
17
+ # Symbol Extensions
17
18
  module SymbolExtensionCustom
18
-
19
19
  def localize_with_debugging(*args)
20
20
  localized_sym = I18n.translate(self, *args)
21
21
  localized_sym.is_a?(String) ? localized_sym.html_safe : localized_sym
22
22
  end
23
- alias_method :l, :localize_with_debugging
24
-
23
+ alias l localize_with_debugging
24
+
25
25
  def l_with_args(*args)
26
- self.l(*args).html_safe
26
+ l(*args).html_safe
27
27
  end
28
-
29
28
  end
30
-
31
- Symbol.send :include, SymbolExtensionCustom
29
+
30
+ Symbol.send :include, SymbolExtensionCustom
@@ -1,76 +1,88 @@
1
- module PaidUp::Mixins
2
- module PaidFor
3
- extend ActiveSupport::Concern
4
- class_methods do
5
- def feature
6
- PaidUp::Feature.find_by_slug(table_name)
7
- end
8
- def paid_for
9
- if feature.nil?
10
- raise :feature_not_found_feature.l feature: table_name
11
- else
1
+ module PaidUp
2
+ module Mixins
3
+ # PaidFor Mixin
4
+ module PaidFor
5
+ extend ActiveSupport::Concern
6
+ class_methods do
7
+ def feature
8
+ PaidUp::Feature.find_by_slug(table_name)
9
+ end
10
+
11
+ def paid_for
12
+ feature.nil? && raise(
13
+ :feature_not_found_feature.l(feature: table_name)
14
+ )
12
15
  case feature.setting_type
13
- when 'boolean'
14
- # Nothing needs doing
15
- when 'rolify_rows'
16
- resourcify
17
- attr_accessor :owner
18
- when 'table_rows'
19
- belongs_to :user
20
- else
21
- raise :value_is_not_a_valid_setting_type.l(value: feature.setting_type)
16
+ when 'boolean'
17
+ # Nothing needs doing
18
+ when 'rolify_rows'
19
+ resourcify
20
+ attr_accessor :owner
21
+ when 'table_rows'
22
+ belongs_to :user
23
+ else
24
+ raise(
25
+ :value_is_not_a_valid_setting_type.l(
26
+ value: feature.setting_type
27
+ )
28
+ )
22
29
  end
23
- end
24
30
 
25
- send(:define_method, :owners) do
26
- User.with_role(:owner, self)
27
- end
31
+ send(:define_method, :owners) do
32
+ User.with_role(:owner, self)
33
+ end
28
34
 
29
- send(:define_method, :save_with_owner) do |owner|
30
- if save
31
- owner.add_role(:owner, self)
32
- true
33
- else
34
- false
35
+ send(:define_method, :save_with_owner) do |owner|
36
+ if save
37
+ owner.add_role(:owner, self)
38
+ self
39
+ else
40
+ false
41
+ end
35
42
  end
36
- end
37
43
 
38
- send(:define_method, :owners_enabled_count) do
39
- setting = 0
40
- for subscriber in owners
41
- setting += subscriber.plan.feature_setting(self.class.table_name)
44
+ send(:define_method, :owners_enabled_count) do
45
+ setting = 0
46
+ owners.each do |subscriber|
47
+ setting += subscriber.plan.feature_setting(self.class.table_name)
48
+ end
49
+ setting
42
50
  end
43
- setting
44
- end
45
51
 
46
- send(:define_method, :owners_records) do
47
- ids = []
48
- for subscriber in owners
49
- case self.class.feature.setting_type
52
+ send(:define_method, :owners_records) do
53
+ ids = []
54
+ owners.each do |subscriber|
55
+ case self.class.feature.setting_type
50
56
  when 'table_rows'
51
57
  ids += subscriber.send(self.class.table_name).pluck(:id)
52
58
  when 'rolify_rows'
53
59
  ids += self.class.with_role(:owner, subscriber).pluck(:id)
54
60
  else
55
- raise :no_features_associated_with_table.l(table: self.class.table_name)
61
+ raise(
62
+ :no_features_associated_with_table.l(
63
+ table: self.class.table_name
64
+ )
65
+ )
66
+ end
56
67
  end
68
+ self.class.where(id: ids)
57
69
  end
58
- self.class.where(id: ids)
59
- end
60
70
 
61
- send(:define_method, :owners_records_count) do
62
- owners_records.count
63
- end
71
+ send(:define_method, :owners_records_count) do
72
+ owners_records.count
73
+ end
64
74
 
65
- send(:define_method, :enabled) do
66
- if owners_enabled_count >= owners_records_count
67
- true
68
- else
69
- enabled_records = owners_records.order('created_at ASC').limit(owners_enabled_count)
70
- enabled_records.include? self
75
+ send(:define_method, :enabled) do
76
+ if owners_enabled_count >= owners_records_count
77
+ true
78
+ else
79
+ enabled_records = owners_records.order('created_at ASC')
80
+ .limit(owners_enabled_count)
81
+ enabled_records.include? self
82
+ end
71
83
  end
72
84
  end
73
85
  end
74
86
  end
75
87
  end
76
- end
88
+ end