submane 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 +73 -0
- data/Rakefile +14 -0
- data/app/assets/config/submane_manifest.js +1 -0
- data/app/assets/stylesheets/submane/application.css +15 -0
- data/app/controllers/submane/application_controller.rb +4 -0
- data/app/helpers/submane/application_helper.rb +4 -0
- data/app/jobs/submane/application_job.rb +4 -0
- data/app/mailers/submane/application_mailer.rb +6 -0
- data/app/models/concerns/submane/model_attributes.rb +23 -0
- data/app/models/concerns/submane/models.rb +12 -0
- data/app/models/submane/application_record.rb +5 -0
- data/app/models/submane/plan.rb +6 -0
- data/app/models/submane/subscription.rb +6 -0
- data/app/views/layouts/submane/application.html.erb +15 -0
- data/config/routes.rb +2 -0
- data/lib/generators/submane/USAGE +9 -0
- data/lib/generators/submane/install_generator.rb +24 -0
- data/lib/generators/submane/templates/config.yml.tt +1 -0
- data/lib/generators/submane/templates/migration.rb.tt +19 -0
- data/lib/submane/attributes.rb +15 -0
- data/lib/submane/engine.rb +5 -0
- data/lib/submane/version.rb +3 -0
- data/lib/submane.rb +32 -0
- data/lib/tasks/submane_tasks.rake +9 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b09740d20fd78c7d2aeb12bbb9d36292d1ef304ebb5a0a58179303c3a2348b9c
|
4
|
+
data.tar.gz: 9536d399660a0b62e1f90bc81e7ae7efb5e449e9c6be0155cf71f63f0ca48164
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b962045c706f57e02371d447985ac47fd061b13e76441903a240e7334b8e494528f7b74bf7470cff71de578949c06f0287421737348de15181aa1bab0f28614
|
7
|
+
data.tar.gz: 7e5b89443c941f3645b9b425ab9ebc60d5c1c9102dddea2275dec394359fde9c67c180fde17e2d3146a45537ab660450355293e0d2eec16c4471ed8eb547475b
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright kingsley-people-box
|
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,73 @@
|
|
1
|
+
# Submane
|
2
|
+
A rails gem for subscription management.
|
3
|
+
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem "submane"
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
```bash
|
14
|
+
$ bundle
|
15
|
+
```
|
16
|
+
|
17
|
+
Or install it with bundle install:
|
18
|
+
```bash
|
19
|
+
$ bundle install submane
|
20
|
+
```
|
21
|
+
|
22
|
+
We then run the following command to add migrations and config yml file
|
23
|
+
```bash
|
24
|
+
$ bin/rails generate submane:install
|
25
|
+
```
|
26
|
+
|
27
|
+
Finally, we can add the class that subscriptions will be attached to.
|
28
|
+
Assuming "Account" class will hold the subscriptions, then we set is as the following string in `config/submane.yml`
|
29
|
+
```ruby
|
30
|
+
account_class: Account
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
With the "Account" instance, let assume it is "account"
|
35
|
+
```ruby
|
36
|
+
account = Account.new(...)
|
37
|
+
```
|
38
|
+
### Active plan
|
39
|
+
Get the active plan
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
account.active_plan
|
43
|
+
```
|
44
|
+
|
45
|
+
Check if account has active plan
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
account.has_active_plan?
|
49
|
+
```
|
50
|
+
Create Plans
|
51
|
+
```ruby
|
52
|
+
Submane.create_plan(name: "", price: "", visual_order: 1)
|
53
|
+
```
|
54
|
+
|
55
|
+
### Subscription
|
56
|
+
Get all subscriptions
|
57
|
+
```ruby
|
58
|
+
account.subscriptions
|
59
|
+
```
|
60
|
+
Get all active Subscriptions for a plan
|
61
|
+
```ruby
|
62
|
+
Submane.plan_active_subscriptions({plan_id})
|
63
|
+
```
|
64
|
+
Get active subscription
|
65
|
+
```ruby
|
66
|
+
account.active_subscription
|
67
|
+
```
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
Contribution directions go here.
|
71
|
+
|
72
|
+
## License
|
73
|
+
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,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
|
3
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
4
|
+
load "rails/tasks/engine.rake"
|
5
|
+
|
6
|
+
load "rails/tasks/statistics.rake"
|
7
|
+
|
8
|
+
require "bundler/gem_tasks"
|
9
|
+
|
10
|
+
require "rubocop/rake_task"
|
11
|
+
|
12
|
+
RuboCop::RakeTask.new
|
13
|
+
|
14
|
+
task default: %i[rubocop app:db:migrate app:test]
|
@@ -0,0 +1 @@
|
|
1
|
+
//= link_directory ../stylesheets/submane .css
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Submane
|
2
|
+
module ModelAttributes
|
3
|
+
def create_subscription; end
|
4
|
+
|
5
|
+
def active_subcriptions
|
6
|
+
subscriptions.where("end_date > ?", Time.now).order(:end_date)
|
7
|
+
end
|
8
|
+
|
9
|
+
def active_plan
|
10
|
+
subscriptions.where("end_date > ?", Time.now).order(:end_date).last.submane_plan
|
11
|
+
end
|
12
|
+
|
13
|
+
def active_plan?
|
14
|
+
subscriptions.where("end_date > ?", Time.now).exists?
|
15
|
+
end
|
16
|
+
|
17
|
+
def active_subscription
|
18
|
+
subscriptions.where("end_date > ?", Time.now).order(:end_date).last
|
19
|
+
end
|
20
|
+
|
21
|
+
alias subcribed? active_plan?
|
22
|
+
end
|
23
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rails/generators/active_record"
|
2
|
+
|
3
|
+
module Submane
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
include ActiveRecord::Generators::Migration
|
7
|
+
source_root File.expand_path("templates", __dir__)
|
8
|
+
|
9
|
+
def copy_migration
|
10
|
+
migration_template "migration.rb", "db/migrate/install_submane.rb", migration_version: migration_version
|
11
|
+
end
|
12
|
+
|
13
|
+
def copy_config
|
14
|
+
template "config.yml", "config/submane.yml"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def migration_version
|
20
|
+
"[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
account_class: User
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :submane_plans do |t|
|
4
|
+
t.string :name
|
5
|
+
t.integer :price
|
6
|
+
t.integer :visual_order, index: { unique: true }
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table :submane_subscriptions do |t|
|
12
|
+
t.references :plan
|
13
|
+
t.references :client
|
14
|
+
t.datetime :end_date, null: false
|
15
|
+
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Submane
|
2
|
+
module Attributes
|
3
|
+
def plan_active_subscriptions(plan_id)
|
4
|
+
Submane::Subscription.where("plan_id = ? AND end_date > ?", plan_id, Time.now)
|
5
|
+
end
|
6
|
+
|
7
|
+
def create_plan!(plan)
|
8
|
+
Submane::Plan.create!(plan)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_plan(plan)
|
12
|
+
Submane::Plan.create(plan)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/submane.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require "submane/version"
|
2
|
+
require "submane/engine"
|
3
|
+
require "submane/attributes"
|
4
|
+
|
5
|
+
module Submane
|
6
|
+
extend Attributes
|
7
|
+
|
8
|
+
# config_accessor :account_class
|
9
|
+
|
10
|
+
def self.config
|
11
|
+
@config ||= begin
|
12
|
+
path = Rails.root.join("config", "submane.yml").to_s
|
13
|
+
if File.exist?(path)
|
14
|
+
YAML.safe_load(ERB.new(File.read(path)).result, aliases: true)
|
15
|
+
else
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.account_class
|
22
|
+
unless defined?(@account_class)
|
23
|
+
@account_class = config["account_class"]
|
24
|
+
@account_class = (Account.name rescue nil) if @account_class.nil? # rubocop:disable Style/RescueModifier
|
25
|
+
end
|
26
|
+
@account_class
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
ActiveSupport.on_load(:active_record) do
|
31
|
+
include Submane::Models
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: submane
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Unegbu Kingsley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-01-30 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.1.3.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.1.3.4
|
27
|
+
description: Subscription management gem for rails.
|
28
|
+
email:
|
29
|
+
- kingsobino@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- MIT-LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- app/assets/config/submane_manifest.js
|
38
|
+
- app/assets/stylesheets/submane/application.css
|
39
|
+
- app/controllers/submane/application_controller.rb
|
40
|
+
- app/helpers/submane/application_helper.rb
|
41
|
+
- app/jobs/submane/application_job.rb
|
42
|
+
- app/mailers/submane/application_mailer.rb
|
43
|
+
- app/models/concerns/submane/model_attributes.rb
|
44
|
+
- app/models/concerns/submane/models.rb
|
45
|
+
- app/models/submane/application_record.rb
|
46
|
+
- app/models/submane/plan.rb
|
47
|
+
- app/models/submane/subscription.rb
|
48
|
+
- app/views/layouts/submane/application.html.erb
|
49
|
+
- config/routes.rb
|
50
|
+
- lib/generators/submane/USAGE
|
51
|
+
- lib/generators/submane/install_generator.rb
|
52
|
+
- lib/generators/submane/templates/config.yml.tt
|
53
|
+
- lib/generators/submane/templates/migration.rb.tt
|
54
|
+
- lib/submane.rb
|
55
|
+
- lib/submane/attributes.rb
|
56
|
+
- lib/submane/engine.rb
|
57
|
+
- lib/submane/version.rb
|
58
|
+
- lib/tasks/submane_tasks.rake
|
59
|
+
homepage: https://github.com/Urchmaney/submane
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata:
|
63
|
+
homepage_uri: https://github.com/Urchmaney/submane
|
64
|
+
source_code_uri: https://github.com/Urchmaney/submane
|
65
|
+
changelog_uri: https://github.com/Urchmaney/submane
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 3.0.0
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.5.11
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Subscription management gem for rails.
|
85
|
+
test_files: []
|