sdn_test_simple_car_repository 0.1.0 → 0.2.1
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4021d729ce417b6ba742100c32e43c24eee66bfdec345765739a8c9525ac21ae
|
|
4
|
+
data.tar.gz: d2d6b40b45f659e5ea688a12029fd155fabea3efe157b8e584c82e17bbc42bf3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b5592af1e3ace226346df4c3b26bd5b207dd8b771b9454d5023c1f870a118d2601cf44a5d09c7b7e1d759172da84fe347fc03559012bf8f23113573307825652
|
|
7
|
+
data.tar.gz: df63c67dddc510a35f6f29b503a34d225e557992a5291a6ecca63750be5d4a7e37114f0a5dbddb4106cf469a0923a70562f39686a2e6e5bb068033996b9126b5
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/grft_test_simple_car_repository/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "sdn_test_simple_car_repository"
|
|
7
|
+
spec.version = GrftTestSimpleCarRepository::VERSION
|
|
8
|
+
spec.authors = ["GraftCode"]
|
|
9
|
+
spec.email = ["info@graftcode.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "Simple car in-memory repository"
|
|
12
|
+
spec.description = "Provides an in-memory repository for SimpleCar objects with add/get/update/delete operations and sample seed data."
|
|
13
|
+
spec.homepage = "https://graftcode.com"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 3.1.0"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
|
|
19
|
+
gemspec = File.basename(__FILE__)
|
|
20
|
+
spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls|
|
|
21
|
+
ls.readlines("\x0", chomp: true).reject do |f|
|
|
22
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
spec.bindir = "exe"
|
|
26
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
27
|
+
spec.require_paths = ["lib"]
|
|
28
|
+
|
|
29
|
+
spec.add_dependency "sdn_test_simple_car", ">= 0.2.1"
|
|
30
|
+
end
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module GrftTestSimpleCarRepository
|
|
4
|
-
VERSION = "0.1
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GrftTestSimpleCarRepository
|
|
4
|
+
VERSION = "0.2.1"
|
|
5
5
|
end
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "grft_test_simple_car"
|
|
4
4
|
|
|
5
5
|
# An in-memory repository that stores SimpleCar instances keyed by string ID.
|
|
6
6
|
class InMemorySimpleCarRepository
|
|
7
|
+
# ── static members ──────────────────────────────────────────────
|
|
8
|
+
|
|
9
|
+
DEFAULT_CAPACITY = 100
|
|
10
|
+
|
|
11
|
+
@total_instances_created = 0
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
attr_accessor :total_instances_created
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.create_with_sample_data
|
|
18
|
+
new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# ── constructor ─────────────────────────────────────────────────
|
|
22
|
+
|
|
7
23
|
def initialize
|
|
24
|
+
self.class.instance_variable_set(:@total_instances_created, self.class.total_instances_created + 1)
|
|
8
25
|
@store = {}
|
|
9
26
|
|
|
10
27
|
samples = [
|
|
@@ -18,6 +35,8 @@ class InMemorySimpleCarRepository
|
|
|
18
35
|
samples.each { |car| add(car) }
|
|
19
36
|
end
|
|
20
37
|
|
|
38
|
+
# ── CRUD ────────────────────────────────────────────────────────
|
|
39
|
+
|
|
21
40
|
def add(car)
|
|
22
41
|
raise ArgumentError, "car cannot be nil" if car.nil?
|
|
23
42
|
raise ArgumentError, "SimpleCar with Id #{car.id} already exists." if @store.key?(car.id)
|
|
@@ -58,4 +77,42 @@ class InMemorySimpleCarRepository
|
|
|
58
77
|
@store.delete(id)
|
|
59
78
|
true
|
|
60
79
|
end
|
|
61
|
-
|
|
80
|
+
|
|
81
|
+
# ── queries returning complex types ─────────────────────────────
|
|
82
|
+
|
|
83
|
+
def find_by_make(make)
|
|
84
|
+
raise ArgumentError, "make cannot be nil or whitespace" if make.nil? || make.strip.empty?
|
|
85
|
+
|
|
86
|
+
lower_make = make.downcase
|
|
87
|
+
@store.values.select { |c| c.make.downcase == lower_make }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def find_by_year_range(min_year, max_year)
|
|
91
|
+
@store.values.select { |c| c.year >= min_year && c.year <= max_year }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# ── queries returning primitive arrays ──────────────────────────
|
|
95
|
+
|
|
96
|
+
def get_years
|
|
97
|
+
@store.values.map(&:year).uniq.sort
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def get_makes
|
|
101
|
+
@store.values.map(&:make).uniq.sort
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# ── bulk operations with primitive-array input ──────────────────
|
|
105
|
+
|
|
106
|
+
def delete_by_ids(ids)
|
|
107
|
+
raise ArgumentError, "ids cannot be nil" if ids.nil?
|
|
108
|
+
|
|
109
|
+
count = 0
|
|
110
|
+
ids.each do |id|
|
|
111
|
+
if @store.key?(id)
|
|
112
|
+
@store.delete(id)
|
|
113
|
+
count += 1
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
count
|
|
117
|
+
end
|
|
118
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sdn_test_simple_car_repository
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- GraftCode
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0.1
|
|
18
|
+
version: 0.2.1
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0.1
|
|
25
|
+
version: 0.2.1
|
|
26
26
|
description: Provides an in-memory repository for SimpleCar objects with add/get/update/delete
|
|
27
27
|
operations and sample seed data.
|
|
28
28
|
email:
|
|
@@ -36,6 +36,7 @@ files:
|
|
|
36
36
|
- LICENSE.txt
|
|
37
37
|
- README.md
|
|
38
38
|
- Rakefile
|
|
39
|
+
- grft_test_simple_car_repository.gemspec
|
|
39
40
|
- lib/grft_test_simple_car_repository/version.rb
|
|
40
41
|
- lib/in_memory_simple_car_repository.rb
|
|
41
42
|
homepage: https://graftcode.com
|