sdn_test_simple_car_repository 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: 6b530b4d67b63c996fabeeb939421648ed6fc9505f41db71292d74c72a8b6007
4
+ data.tar.gz: 4c29fc1f35f923f6d1411859ac1f0ef1dc7a610f718e903886547dff2b95ee98
5
+ SHA512:
6
+ metadata.gz: 6819c3131d4c0ce3e08f8003585e19ad1508cca00e1269112071f3960e64fabeabb6a8e584b70cd86a0e4cd8e3d43ecad5648c6605a86228e9ce4ec7b68b1631
7
+ data.tar.gz: f509156220e1dd6b957a78da3c85b015aeda4a9fb76d4c625f7d523c777e0e8b6519161b42286995c2f7c8eb24d813f6b7d3231568c6acd5781ad9d3dec82d35
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Graftcode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Simple Car Repository
2
+
3
+ A minimal in-memory Ruby repository for `SimpleCar` entities.
4
+
5
+ ## What it provides
6
+
7
+ - Seeded in-memory store with 5 sample cars
8
+ - CRUD-style operations: `add`, `add_range`, `get`, `get_all`, `update`, `delete`
9
+ - Validation for `nil` cars and blank IDs
10
+
11
+ ## Requirements
12
+
13
+ - Ruby 3.1+
14
+ - Gem dependency: `sdn_test_simple_car`
15
+
16
+ ## Import
17
+
18
+ ```ruby
19
+ require "grft_test_simple_car_repository"
20
+ ```
21
+
22
+ or, when loading directly from the repository:
23
+
24
+ ```ruby
25
+ require_relative "lib/in_memory_simple_car_repository"
26
+ ```
27
+
28
+ ## Quick Start
29
+
30
+ ```ruby
31
+ require "grft_test_simple_car_repository"
32
+
33
+ repo = InMemorySimpleCarRepository.new
34
+ car = SimpleCar.new("BMW", "M3", 2023)
35
+ repo.add(car)
36
+
37
+ all_cars = repo.get_all
38
+ puts "Total cars: #{all_cars.length}"
39
+ ```
40
+
41
+ ## API Reference
42
+
43
+ - `InMemorySimpleCarRepository.new`
44
+ - `add(car)`
45
+ - `add_range(cars)`
46
+ - `get(id)` -> `SimpleCar | nil`
47
+ - `get_all` -> `Array<SimpleCar>`
48
+ - `update(car)` -> `true/false`
49
+ - `delete(id)` -> `true/false`
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GrftTestSimpleCarRepository
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sdn_test_simple_car"
4
+
5
+ # An in-memory repository that stores SimpleCar instances keyed by string ID.
6
+ class InMemorySimpleCarRepository
7
+ def initialize
8
+ @store = {}
9
+
10
+ samples = [
11
+ SimpleCar.new("Toyota", "Corolla", 2018, "0"),
12
+ SimpleCar.new("Tesla", "Model 3", 2021, "1"),
13
+ SimpleCar.new("Ford", "Mustang", 1967, "2"),
14
+ SimpleCar.new("Honda", "Civic", 2015, "3"),
15
+ SimpleCar.new("Chevrolet", "Camaro", 2020, "4")
16
+ ]
17
+
18
+ samples.each { |car| add(car) }
19
+ end
20
+
21
+ def add(car)
22
+ raise ArgumentError, "car cannot be nil" if car.nil?
23
+ raise ArgumentError, "SimpleCar with Id #{car.id} already exists." if @store.key?(car.id)
24
+
25
+ @store[car.id] = car
26
+ end
27
+
28
+ def add_range(cars)
29
+ raise ArgumentError, "cars cannot be nil" if cars.nil?
30
+
31
+ cars.each { |car| add(car) }
32
+ end
33
+
34
+ def get(id)
35
+ raise ArgumentError, "id cannot be nil or whitespace" if id.nil? || id.strip.empty?
36
+
37
+ @store[id]
38
+ end
39
+
40
+ def get_all
41
+ @store.values
42
+ end
43
+
44
+ def update(car)
45
+ raise ArgumentError, "car cannot be nil" if car.nil?
46
+
47
+ return false unless @store.key?(car.id)
48
+
49
+ @store[car.id] = car
50
+ true
51
+ end
52
+
53
+ def delete(id)
54
+ raise ArgumentError, "id cannot be nil or whitespace" if id.nil? || id.strip.empty?
55
+
56
+ return false unless @store.key?(id)
57
+
58
+ @store.delete(id)
59
+ true
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sdn_test_simple_car_repository
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - GraftCode
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: sdn_test_simple_car
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 0.1.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.1.0
26
+ description: Provides an in-memory repository for SimpleCar objects with add/get/update/delete
27
+ operations and sample seed data.
28
+ email:
29
+ - info@graftcode.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - lib/grft_test_simple_car_repository/version.rb
40
+ - lib/in_memory_simple_car_repository.rb
41
+ homepage: https://graftcode.com
42
+ licenses:
43
+ - MIT
44
+ metadata:
45
+ homepage_uri: https://graftcode.com
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 3.1.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.6.9
61
+ specification_version: 4
62
+ summary: Simple car in-memory repository
63
+ test_files: []