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.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -0
- data/Gemfile +5 -1
- data/Rakefile +12 -10
- data/VERSION +1 -1
- data/app/controllers/paid_up/paid_up_controller.rb +8 -3
- data/app/controllers/paid_up/plans_controller.rb +2 -1
- data/app/controllers/paid_up/subscriptions_controller.rb +19 -6
- data/app/helpers/paid_up/features_helper.rb +19 -6
- data/app/helpers/paid_up/paid_up_helper.rb +6 -3
- data/app/helpers/paid_up/plans_helper.rb +12 -5
- data/app/helpers/paid_up/subscriptions_helper.rb +10 -3
- data/app/models/paid_up/ability.rb +43 -44
- data/app/models/paid_up/plan.rb +81 -69
- data/app/models/paid_up/plan_feature_setting.rb +17 -9
- data/app/models/paid_up/unlimited.rb +15 -13
- data/app/views/devise/confirmations/new.html.haml +1 -1
- data/app/views/devise/passwords/edit.html.haml +1 -1
- data/app/views/devise/passwords/new.html.haml +1 -1
- data/app/views/devise/registrations/_new_form.html.haml +1 -1
- data/app/views/devise/registrations/new.html.haml +1 -1
- data/app/views/devise/sessions/new.html.haml +1 -1
- data/app/views/devise/unlocks/new.html.haml +1 -1
- data/app/views/layouts/mailer.html.haml +1 -1
- data/app/views/layouts/mailer.text.haml +1 -1
- data/app/views/paid_up/features/_abilities_table.html.haml +1 -1
- data/app/views/paid_up/plans/index.html.haml +1 -1
- data/app/views/paid_up/subscriptions/new.html.haml +1 -1
- data/config/initializers/stripe.rb +3 -3
- data/coverage/.last_run.json +1 -1
- data/coverage/.resultset.json +414 -253
- data/db/migrate/20150407110101_create_paid_up_plans_table.rb +3 -3
- data/lib/generators/paid_up/install/install_generator.rb +42 -33
- data/lib/generators/paid_up/install/templates/ability.rb +1 -0
- data/lib/generators/paid_up/install/templates/initializer.rb +16 -14
- data/lib/generators/paid_up/utils.rb +11 -4
- data/lib/paid_up/configuration.rb +13 -8
- data/lib/paid_up/engine.rb +4 -3
- data/lib/paid_up/extensions/integer.rb +8 -5
- data/lib/paid_up/extensions/stripe.rb +10 -9
- data/lib/paid_up/feature.rb +27 -17
- data/lib/paid_up/localization.rb +17 -18
- data/lib/paid_up/mixins/paid_for.rb +66 -54
- data/lib/paid_up/mixins/subscriber.rb +154 -161
- data/lib/paid_up/railtie.rb +1 -1
- data/lib/paid_up/validators/rolify_rows.rb +14 -6
- data/lib/paid_up/validators/table_rows.rb +14 -6
- data/lib/paid_up/version.rb +1 -1
- data/lib/paid_up.rb +7 -8
- data/paid_up.gemspec +21 -8
- data/spec/controllers/paid_up/plans_spec.rb +6 -6
- data/spec/controllers/paid_up/subscriptions_spec.rb +68 -68
- data/spec/dummy/Rakefile +2 -1
- data/spec/dummy/app/assets/stylesheets/application.css.scss +3 -16
- data/spec/dummy/app/controllers/application_controller.rb +1 -1
- data/spec/dummy/app/models/doodad.rb +1 -1
- data/spec/dummy/app/models/group.rb +1 -1
- data/spec/dummy/app/models/role.rb +4 -4
- data/spec/dummy/app/models/user.rb +1 -1
- data/spec/dummy/app/views/layouts/application.html.haml +2 -2
- data/spec/dummy/app/views/pages/index.html.haml +1 -1
- data/spec/dummy/config/application.rb +16 -12
- data/spec/dummy/config/environments/development.rb +4 -3
- data/spec/dummy/config/environments/production.rb +10 -6
- data/spec/dummy/config/environments/test.rb +3 -2
- data/spec/dummy/config/initializers/assets.rb +2 -1
- data/spec/dummy/config/initializers/backtrace_silencers.rb +4 -2
- data/spec/dummy/config/initializers/devise.rb +58 -42
- data/spec/dummy/config/initializers/high_voltage.rb +1 -1
- data/spec/dummy/config/initializers/mime_types.rb +1 -1
- data/spec/dummy/config/initializers/paid_up.rb +16 -14
- data/spec/dummy/config/initializers/rolify.rb +3 -2
- data/spec/dummy/config/initializers/wrap_parameters.rb +2 -1
- data/spec/dummy/config/routes.rb +2 -2
- data/spec/dummy/db/migrate/20150523010827_add_devise_to_users.rb +2 -2
- data/spec/dummy/db/migrate/20150523010837_rolify_create_roles.rb +2 -2
- data/spec/dummy/db/migrate/20160207184112_create_paid_up_plans_table.paid_up.rb +3 -3
- data/spec/dummy/db/schema.rb +53 -53
- data/spec/dummy/db/seeds.rb +41 -56
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/tasks/system.rake +2 -2
- data/spec/factories/group.rb +1 -1
- data/spec/factories/plan.rb +1 -1
- data/spec/factories/plan_feature_setting.rb +1 -1
- data/spec/factories/user.rb +13 -11
- data/spec/models/group_spec.rb +8 -7
- data/spec/models/paid_up/feature_spec.rb +18 -4
- data/spec/models/paid_up/plan_feature_setting_spec.rb +2 -2
- data/spec/models/paid_up/plan_spec.rb +12 -8
- data/spec/models/user_spec.rb +88 -78
- data/spec/paid_up_spec.rb +1 -1
- data/spec/rails_helper.rb +5 -5
- data/spec/routing/paid_up/plans_spec.rb +3 -3
- data/spec/routing/paid_up/subscription_spec.rb +30 -7
- data/spec/spec_helper.rb +7 -52
- data/spec/support/controller_macros.rb +2 -2
- data/spec/support/factory_girl.rb +1 -1
- data/spec/support/{features.rb → loaded_site/features.rb} +2 -2
- data/spec/support/{groups.rb → loaded_site/groups.rb} +1 -1
- data/spec/support/{loaded_site.rb → loaded_site/loaded_site.rb} +1 -1
- data/spec/support/{plans.rb → loaded_site/plans.rb} +8 -4
- data/spec/support/{users.rb → loaded_site/users.rb} +1 -1
- data/spec/support/stripe.rb +10 -13
- data/spec/views/paid_up/plans_spec.rb +17 -17
- data/spec/views/paid_up/subscriptions_spec.rb +24 -14
- 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, :
|
12
|
-
add_index :paid_up_plans, :stripe_id, :
|
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, :
|
4
|
-
source_root File.expand_path(
|
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
|
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
|
17
|
-
|
18
|
-
|
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
|
23
|
-
|
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
|
28
|
-
|
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
|
33
|
-
|
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
|
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
|
43
|
-
gsub_file
|
44
|
-
inject_into_file
|
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
|
49
|
-
gsub_file
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
@@ -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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# for the PaidUp::PlanFeatureSetting.setting associated with this
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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(
|
11
|
-
|
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
|
-
|
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
|
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 =
|
18
|
-
self.anonymous_plan_stripe_id =
|
19
|
-
self.free_plan_stripe_id =
|
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
|
data/lib/paid_up/engine.rb
CHANGED
@@ -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
|
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
|
2
|
-
module
|
3
|
-
|
4
|
-
|
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
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
-
|
11
|
+
create(item)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
15
|
-
end
|
16
|
+
end
|
data/lib/paid_up/feature.rb
CHANGED
@@ -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
|
23
|
-
|
24
|
-
|
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 =
|
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
|
-
|
69
|
+
all.each do |feature|
|
57
70
|
qualifies = true
|
58
71
|
conditions.each do |key, value|
|
59
|
-
|
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
|
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
|
-
|
88
|
+
find(Regexp.last_match[1].to_sym => arguments.first)
|
79
89
|
elsif method_sym.to_s =~ /^find_all_by_(.*)$/
|
80
|
-
|
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
|
data/lib/paid_up/localization.rb
CHANGED
@@ -1,31 +1,30 @@
|
|
1
|
+
# String Extension
|
1
2
|
module StringExtension
|
2
3
|
def localize(*args)
|
3
|
-
if args.first.is_a? Symbol
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
args << {:
|
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
|
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
|
-
|
24
|
-
|
23
|
+
alias l localize_with_debugging
|
24
|
+
|
25
25
|
def l_with_args(*args)
|
26
|
-
|
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
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
31
|
+
send(:define_method, :owners) do
|
32
|
+
User.with_role(:owner, self)
|
33
|
+
end
|
28
34
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
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
|
-
|
62
|
-
|
63
|
-
|
71
|
+
send(:define_method, :owners_records_count) do
|
72
|
+
owners_records.count
|
73
|
+
end
|
64
74
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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
|