plan_features 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +3 -0
- data/lib/plan_features/configuration.rb +9 -0
- data/lib/plan_features/feature.rb +9 -0
- data/lib/plan_features/pricing.rb +120 -0
- data/lib/plan_features/railtie.rb +4 -0
- data/lib/plan_features/version.rb +3 -0
- data/lib/plan_features.rb +15 -0
- data/lib/tasks/plan_features_tasks.rake +4 -0
- metadata +68 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0f6d3f70ba4ccec42364f9cd047fc528fd65359f672a8d4ab432814db65d6130
|
|
4
|
+
data.tar.gz: 9de014c4f152137a0263ad2287916f2d53579c5b1d0d1fb23bb177b5b3277186
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5d8b556b708ff38f4604742a2ba679e4569a373211d9b772fc43d991b3f009eb68bf8becbde16dfc2b8b677224298345b12ffaa0644306110e620c77300d632a
|
|
7
|
+
data.tar.gz: d40d30f4b668650bf7bb5effa19096292fb7adf1c8d64e4f1be5a3780b4467310c2fc8b920b4d5abe2a9e35503cad3ede1a2cbdc0b7a401e0cc1383d9f01d8b2
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright Jesper Christiansen
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# PlanFeatures
|
|
2
|
+
Short description and motivation.
|
|
3
|
+
|
|
4
|
+
## Usage
|
|
5
|
+
How to use my plugin.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem "plan_features"
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
```bash
|
|
16
|
+
$ bundle
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
```bash
|
|
21
|
+
$ gem install plan_features
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Contributing
|
|
25
|
+
Contribution directions go here.
|
|
26
|
+
|
|
27
|
+
## License
|
|
28
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
require_relative "feature"
|
|
2
|
+
|
|
3
|
+
module PlanFeatures
|
|
4
|
+
class Pricing
|
|
5
|
+
attr_accessor :name, :plan_identifier, :interval, :stripe_id, :features, :prices, :previous, :popular
|
|
6
|
+
|
|
7
|
+
include ActiveModel::Model
|
|
8
|
+
|
|
9
|
+
def self.boosts
|
|
10
|
+
@boosts ||= begin
|
|
11
|
+
if File.exist?(Rails.root.join("config", "account_boosts.yml"))
|
|
12
|
+
YAML.load_file(Rails.root.join("config", "account_boosts.yml"))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.find_by_identifier(id)
|
|
18
|
+
plan = Pricing.all_plans.find { |plan| plan.plan_identifier == id.to_s }
|
|
19
|
+
raise "Plan not found" if plan.nil?
|
|
20
|
+
|
|
21
|
+
plan
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.find_by_pricing_id(id, interval: "monthly")
|
|
25
|
+
Pricing.all_plans.find do |plan|
|
|
26
|
+
!plan.free? && plan.prices && plan.prices[interval]["product"] == id
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.all_plans
|
|
31
|
+
@all_plans ||= YAML.load_file(::PlanFeatures.configuration.plans_file_path).map do |plan, attributes|
|
|
32
|
+
Pricing.new(
|
|
33
|
+
plan_identifier: plan,
|
|
34
|
+
popular: attributes["popular"],
|
|
35
|
+
name: attributes["name"],
|
|
36
|
+
features: attributes["features"],
|
|
37
|
+
prices: attributes["prices"],
|
|
38
|
+
previous: attributes["previous"]
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def self.free_plan
|
|
44
|
+
Pricing.all_plans.find { |plan| plan.free? }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def current_and_previous_features
|
|
48
|
+
features.merge(previous_features)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def has_feature?(feature, id: nil)
|
|
52
|
+
return true if Pricing.boosts&.[](id)&.include?(feature.to_s)
|
|
53
|
+
|
|
54
|
+
current_and_previous_features.find { |f| f[0] == feature.to_s }.present?
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def previous_features
|
|
58
|
+
previous_plan&.current_and_previous_features || {}
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def previous_plan
|
|
62
|
+
Pricing.all_plans.find do |plan|
|
|
63
|
+
plan.plan_identifier == previous
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def amount_for(feature)
|
|
68
|
+
features.dig(feature.to_s, "amount")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def free?
|
|
72
|
+
prices.nil?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def paid?
|
|
76
|
+
prices&.any?
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def pricing_id(interval = "monthly")
|
|
80
|
+
if interval == "monthly"
|
|
81
|
+
monthly_pricing_id
|
|
82
|
+
else
|
|
83
|
+
yearly_pricing_id
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def pricing_id(name: :monthly)
|
|
88
|
+
return nil if prices.nil?
|
|
89
|
+
prices[name.to_s]["product"]
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def monthly_pricing_id
|
|
93
|
+
pricing_id(name: :monthly)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def yearly_pricing_id
|
|
97
|
+
pricing_id(name: :yearly)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def price(name: :monthly)
|
|
101
|
+
return nil if prices.nil?
|
|
102
|
+
prices[name.to_s]["amount"] / 100
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def yearly_price_monthly
|
|
106
|
+
return nil if prices.nil?
|
|
107
|
+
(prices["yearly"]["amount"].to_f / 100 / 12).round(2)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def display_features
|
|
111
|
+
features.map do |identifier, attributes|
|
|
112
|
+
PricingFeatures::Feature.new(
|
|
113
|
+
description: attributes["description"],
|
|
114
|
+
amount: attributes["amount"],
|
|
115
|
+
hidden: attributes["hidden"],
|
|
116
|
+
)
|
|
117
|
+
end.compact.filter{|f| !f.hidden? }
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "plan_features/version"
|
|
2
|
+
require "plan_features/railtie"
|
|
3
|
+
require "plan_features/pricing"
|
|
4
|
+
require "plan_features/configuration"
|
|
5
|
+
|
|
6
|
+
module PlanFeatures
|
|
7
|
+
class << self
|
|
8
|
+
attr_accessor :configuration
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.configure
|
|
12
|
+
self.configuration ||= Configuration.new
|
|
13
|
+
yield(configuration)
|
|
14
|
+
end
|
|
15
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: plan_features
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jesper Christiansen
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2023-11-10 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '7'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '7'
|
|
27
|
+
description: Define plans and their features in a YAML file and use them in your Rails
|
|
28
|
+
app
|
|
29
|
+
email:
|
|
30
|
+
- hi@jespr.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- MIT-LICENSE
|
|
36
|
+
- README.md
|
|
37
|
+
- Rakefile
|
|
38
|
+
- lib/plan_features.rb
|
|
39
|
+
- lib/plan_features/configuration.rb
|
|
40
|
+
- lib/plan_features/feature.rb
|
|
41
|
+
- lib/plan_features/pricing.rb
|
|
42
|
+
- lib/plan_features/railtie.rb
|
|
43
|
+
- lib/plan_features/version.rb
|
|
44
|
+
- lib/tasks/plan_features_tasks.rake
|
|
45
|
+
homepage:
|
|
46
|
+
licenses:
|
|
47
|
+
- MIT
|
|
48
|
+
metadata: {}
|
|
49
|
+
post_install_message:
|
|
50
|
+
rdoc_options: []
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: '0'
|
|
63
|
+
requirements: []
|
|
64
|
+
rubygems_version: 3.2.32
|
|
65
|
+
signing_key:
|
|
66
|
+
specification_version: 4
|
|
67
|
+
summary: Add Plan feature configuration to your Rails app
|
|
68
|
+
test_files: []
|