cart_management 0.1.7

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: acc89ff78a1db2ecde92dec5359fcd6517aa14fe904416dfca22655c9905458a
4
+ data.tar.gz: 901609a725f4d44a65f46c996dd02b506dd6bc57905d0ca75c1011826eb0b7f7
5
+ SHA512:
6
+ metadata.gz: af1a24aacf23455e2273ccc33f44e0f1dc13c44b4b5b787d7b477451b3d46e08cf6127604fca1a68a7a525067778b516dfe7f092957b63c46a928357036a0aa0
7
+ data.tar.gz: e10874a20d8a1b89a91a8ee873f88a9d40726dfea795feae9372b70bbb5db2b6356d23503cfb26e60b7232df0cb28554cc794a2bb0ad500d0611d70cfce52845
data/lib/cart.rb ADDED
@@ -0,0 +1,17 @@
1
+ module CartManagement
2
+ class Cart
3
+
4
+ def initialize(user_id)
5
+ @user_id = user_id
6
+ end
7
+
8
+ def create_cart
9
+ @cart = Cart.new(user_id: @user_id)
10
+ if @cart.save
11
+ 'Cart Created Successfully'
12
+ else
13
+ @cart.errors.full_messages
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CartManagement
4
+ VERSION = "0.1.7"
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "cart_management/version"
4
+ require "rails/railtie"
5
+ require_relative "generators/install_generator"
6
+
7
+ module CartManagement
8
+ class Railtie < Rails::Railtie
9
+ initializer "cart_management.install_migration" do |app|
10
+ end
11
+ end
12
+ class Error < StandardError; end
13
+ end
@@ -0,0 +1,30 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module CartManagement
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ source_root File.expand_path("templates", __dir__)
9
+
10
+ def copy_migration
11
+ migration_template "create_cart.rb", "db/migrate/create_cart.rb"
12
+ migration_template "create_cart_items.rb", "db/migrate/create_cart_items.rb"
13
+ end
14
+
15
+ def copy_models
16
+ template 'cart.rb', 'app/models/cart.rb'
17
+ template 'cart_item.rb', 'app/models/cart_item.rb'
18
+ end
19
+
20
+ def self.next_migration_number(path)
21
+ if @prev_migration_nr
22
+ @prev_migration_nr += 1
23
+ else
24
+ @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
25
+ end
26
+ @prev_migration_nr.to_s
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ class Cart < ApplicationRecord
3
+ has_many :cart_items
4
+ end
@@ -0,0 +1,3 @@
1
+ class CartItem < ApplicationRecord
2
+ belongs_to :cart
3
+ end
@@ -0,0 +1,9 @@
1
+ class CreateCart < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :cart do |t|
4
+ t.references :user, null: false, foreign_key: true
5
+ t.float :total_amount, default: 0.0
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ class CreateCartItems < ActiveRecord::Migration[6.0]
2
+ def change
3
+ create_table :cart_items do |t|
4
+ t.references :cart, null: false, foreign_key: true
5
+ t.references :product, null: true, foreign_key: true
6
+ t.references :variant, null: true, foreign_key: true
7
+ t.integer :quantity
8
+ t.string :size
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ namespace :cart_management do
2
+ desc "Install CartManagement gem"
3
+ task install: :environment do
4
+ Rails::Generators.invoke("cart_management:install")
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ module CartManagement
2
+ class Cart
3
+ @cart: untyped
4
+ @user_id: untyped
5
+
6
+ def create_cart: -> String
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module CartManagement
2
+ module Generators
3
+ class InstallGenerator
4
+ @prev_migration_nr: untyped
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module CartManagement
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
@@ -0,0 +1,26 @@
1
+ # spec/generators/install_generator_spec.rb
2
+ require 'rails_helper'
3
+ require "cart_management/generators/install_generator"
4
+
5
+ RSpec.describe CartManagement::Generators::InstallGenerator, type: :generator do
6
+ destination File.expand_path('../../tmp/generators', __FILE__)
7
+
8
+ # Include the generator test case behavior
9
+ include Rails::Generators::TestCase::Behavior
10
+
11
+ before(:all) do
12
+ prepare_destination
13
+ run_generator
14
+ end
15
+
16
+ it "generates a migration file" do
17
+ expect(destination_root).to have_structure {
18
+ directory("db") do
19
+ directory("migrate") do
20
+ migration_file = file(/.*create_carts.rb/)
21
+ expect(migration_file).to exist
22
+ end
23
+ end
24
+ }
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # spec/rails_helper.rb
2
+
3
+ # Require RSpec and any other necessary testing libraries
4
+ # require "rspec/rails"
5
+ require "cart_management"
6
+
7
+ # Requires supporting ruby files with custom matchers and macros, etc,
8
+ # in spec/support/ and its subdirectories.
9
+
10
+ RSpec.configure do |config|
11
+ # If you want to run your tests within a transaction, uncomment this line
12
+ # This will make tests faster by rolling back changes after each test
13
+ # config.use_transactional_fixtures = true
14
+
15
+ # Add additional requires or configurations here
16
+ # e.g., if you are using FactoryBot for factories
17
+ config.include FactoryBot::Syntax::Methods
18
+
19
+ # Configure how your tests are run
20
+ config.fixture_path = "#{::Rails.root}/spec/fixtures" # Path for fixture files
21
+ config.infer_spec_type_from_file_location! # Automatically set test types based on file location
22
+ config.filter_rails_from_backtrace! # Filter out Rails gems from backtrace
23
+ end
@@ -0,0 +1,33 @@
1
+ # spec/spec_helper.rb
2
+
3
+ # This file is generated by the `rspec --init` command.
4
+ # It is a good idea to add `require 'rspec/expectations'` here.
5
+
6
+ RSpec.configure do |config|
7
+ # Enables the `:focus` filter, allowing you to run only focused tests.
8
+ config.filter_run_when_matching :focus
9
+
10
+ # Run all examples in random order to surface order dependencies.
11
+ config.order = :random
12
+
13
+ # Print the seed used for random ordering.
14
+ Kernel.srand config.seed
15
+
16
+ # Enable the expectation syntax for more readable tests.
17
+ config.expect_with :rspec do |c|
18
+ c.syntax = :expect
19
+ end
20
+
21
+ # Enable the mock framework.
22
+ config.mock_with :rspec do |mocks|
23
+ mocks.verify_partial_doubles = true
24
+ end
25
+
26
+ # Disable RSpec's monkey patching of Kernel and Object.
27
+ config.disable_monkey_patching!
28
+
29
+ # Enable the use of `let` and `subject` outside of `describe` blocks.
30
+ config.include RSpec::Mocks::ExampleMethods
31
+
32
+ # Additional configurations can go here.
33
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cart_management
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.7
5
+ platform: ruby
6
+ authors:
7
+ - Fahadbutt
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-10-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Cart Management
14
+ email:
15
+ - buttf5169@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/cart.rb
21
+ - lib/cart_management.rb
22
+ - lib/cart_management/version.rb
23
+ - lib/generators/install_generator.rb
24
+ - lib/generators/templates/cart.rb
25
+ - lib/generators/templates/cart_item.rb
26
+ - lib/generators/templates/create_cart.rb
27
+ - lib/generators/templates/create_cart_items.rb
28
+ - lib/tasks/cart_management.rake
29
+ - sig/cart_management.rbs
30
+ - sig/cart_management/cart.rbs
31
+ - sig/cart_management/generators/install_generator.rbs
32
+ - spec/generators/install_generator_spec.rb
33
+ - spec/rails_helper.rb
34
+ - spec/spec_helper.rb
35
+ homepage:
36
+ licenses:
37
+ - MIT
38
+ metadata: {}
39
+ post_install_message: |2
40
+ Thank you for installing CartManagement!
41
+
42
+ To complete the installation, please run:
43
+
44
+ rails cart_management:install
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.6.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.3.7
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Cart
63
+ test_files: []