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 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,4 @@
1
+ module Submane
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Submane
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Submane
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Submane
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -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
@@ -0,0 +1,12 @@
1
+ module Submane
2
+ module Models
3
+ extend ActiveSupport::Concern
4
+
5
+ class_methods do
6
+ def setup_submane
7
+ has_many :subscriptions, class_name: "Submane::Subscription", foreign_key: "client_id"
8
+ include Submane::ModelAttributes
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Submane
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module Submane
2
+ class Plan < ApplicationRecord
3
+ has_many :subscriptions
4
+ validates :name, :price, :visual_order, presence: true
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Submane
2
+ class Subscription < ApplicationRecord
3
+ belongs_to :plan
4
+ belongs_to :client, class_name: Submane.account_class if Submane.account_class
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Submane</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag "submane/application", media: "all" %>
9
+ </head>
10
+ <body>
11
+
12
+ <%= yield %>
13
+
14
+ </body>
15
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Submane::Engine.routes.draw do
2
+ end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Creates migration and initializer config files for Submane
3
+
4
+ Example:
5
+ bin/rails generate submane:install
6
+
7
+ This will create:
8
+ config/initializers/submane.rb
9
+ db/migrate/{timestamp}_install_submane.rb
@@ -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
@@ -0,0 +1,5 @@
1
+ module Submane
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Submane
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Submane
2
+ VERSION = "0.1.0".freeze
3
+ 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
@@ -0,0 +1,9 @@
1
+ # desc "Explaining what the task does"
2
+ # task :submane do
3
+ # # Task goes here
4
+ # end
5
+
6
+ desc "Open irb with library in load path"
7
+ task :console do
8
+ exec "irb -r mygem -I ./lib"
9
+ 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: []