piko-tools 1.0.1 → 1.0.3

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: 707325cfcdbacb3bdc3593c85dc36fdfa8cca8022221fae40de7c61c3b03ecc9
4
- data.tar.gz: ed49ea56c64556b74dc4a8217cce3e58c50dc3422cd35e200906ee4e4b3601ff
3
+ metadata.gz: b24d94cf9680123a4cc1c2b421fe6d35db7ddc083dcf5558f8cbcf2950e115cf
4
+ data.tar.gz: 0a43ccdded4b3f0122a2a21eebd6f8a974925663c454f172ca21814bbb145727
5
5
  SHA512:
6
- metadata.gz: 84f7eb1e60b7cefba7af8f7b9d2e254876c8847e72a7c7809e49111881e2766ac5533225672c84dc46623a307b8a294cefa76e953dbde983a77560d2de230177
7
- data.tar.gz: 90b8556195e4bc810b0a3fc45f8a6715523f97be089f8c39d22fc6425071cb863871be67a58d25ef7d429eca9f70279d5ee09f756555cff1c8149fcb7725d76a
6
+ metadata.gz: 11b82066788856f87b1ece4f1b41345f8d5a10cfce114091378998bee60a057917e5a961b0456e335bee773cf4f2139575040afef6398740956a036db2ef0cda
7
+ data.tar.gz: 7be734cea5b77fb79e92da3fcce5c32d04ddff0e8292f49dc0dfdb7ecbd6368d6e83a5c775392b21b8f0dc46563bd48ad2b86e7ec5833cbf19568d26a9070b34
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.2] - 2025-09-02
4
+
5
+ ### Fixed
6
+
7
+ - Fix state check
8
+
9
+ ## [1.0.1] - 2025-09-02
10
+
11
+ ### Added
12
+
13
+ - Add exception for starting undefined keys
14
+
3
15
  ## [1.0.0] - 2025-07-07
4
16
 
5
17
  Init
@@ -8,6 +20,10 @@ Init
8
20
 
9
21
  - Init
10
22
 
23
+ [1.0.2]: https://gitlab.com/skopciewski/piko-tools/-/compare/1.0.1...1.0.2
24
+
25
+ [1.0.1]: https://gitlab.com/skopciewski/piko-tools/-/compare/1.0.0...1.0.1
26
+
11
27
  [1.0.0]: https://gitlab.com/skopciewski/piko-tools/-/compare/0.0.0...1.0.0
12
28
 
13
29
  [0.0.0]: https://gitlab.com/skopciewski/piko-tools
data/README.md CHANGED
@@ -1,23 +1,85 @@
1
- # Piko-tools
1
+ # PikoTools
2
+
3
+ Micro-framework for building applications with data-driven architecture.
2
4
 
3
5
  ## Installation
4
6
 
5
- Add this line to your application's Gemfile:
7
+ Add to your Gemfile:
6
8
 
7
- gem 'piko-tools'
9
+ ```ruby
10
+ gem "piko-tools"
11
+ ```
8
12
 
9
- And then execute:
13
+ Or install directly:
10
14
 
11
- $ bundle
15
+ ```bash
16
+ gem install piko-tools
17
+ ```
12
18
 
13
- Or install it yourself as:
19
+ ## Usage
14
20
 
15
- $ gem install piko-tools
21
+ ### State
16
22
 
17
- ## Usage
23
+ Lazy lifecycle manager with start/stop semantics.
24
+
25
+ ```ruby
26
+ state = PikoTools::State.new do |s|
27
+ s.define(:db, -> { Database.connect }, stop: ->(conn) { conn.close })
28
+ s.define(:cache, -> { Cache.new }, stop: ->(c) { c.flush })
29
+ s.define(:logger, -> { Logger.new })
30
+ end
31
+
32
+ # Lazy start — connects on first access
33
+ logger = state[:logger]
34
+
35
+ # Query state
36
+ state.started?(:db) # => false
37
+ state.start_all
38
+ state.started?(:db) # => true
39
+
40
+ # Stop with teardown callback
41
+ state.stop(:db) # calls Database#close
42
+
43
+ # Reload (stop + start)
44
+ state.reload(:cache)
45
+
46
+ # Stop all in reverse order, then clear definitions
47
+ state.clear!
48
+ ```
49
+
50
+ ### Builder
51
+
52
+ Fluent builder for composing objects with keyword arguments.
53
+
54
+ ```ruby
55
+ class Handler
56
+ def initialize(args = {})
57
+ @args = args
58
+ end
59
+ end
60
+
61
+ handler = PikoTools::Builder.new(Handler)
62
+ .set(foo: 1, bar: 2)
63
+ .build(baz: 3)
64
+
65
+ handler # => #<Handler @args={foo: 1, bar: 2, build_args: {baz: 3}}>
66
+ ```
67
+
68
+ ### Component
69
+
70
+ Mixin providing config-based private attributes via `OpenStruct`.
71
+
72
+ ```ruby
73
+ class MyComponent
74
+ include PikoTools::Component
75
+ attr_struct :host, :port
76
+ end
18
77
 
19
- ## Versioning
78
+ component = MyComponent.new(host: "localhost", port: 3000)
79
+ component.send(:host) # => "localhost"
80
+ component.send(:port) # => 3000
81
+ ```
20
82
 
21
- See [semver.org][semver]
83
+ ## Requirements
22
84
 
23
- [semver]: http://semver.org/
85
+ Ruby >= 3.2. No runtime dependencies.
@@ -1,5 +1,3 @@
1
- require "ostruct"
2
-
3
1
  module PikoTools
4
2
  module Component
5
3
  def self.included(base)
@@ -9,7 +7,7 @@ module PikoTools
9
7
 
10
8
  module PrepMethods
11
9
  def initialize(config = {})
12
- @config = OpenStruct.new(config.to_h).to_h
10
+ @config = config.to_h.transform_keys(&:to_sym)
13
11
  super if initialize_in_ancestor?
14
12
  end
15
13
 
@@ -17,14 +17,12 @@ module PikoTools
17
17
 
18
18
  def start(key)
19
19
  return @instances[key] if started?(key)
20
- # puts "[system] starting #{key}"
20
+ raise KeyError, "Key not defined: '#{key}'" unless define?(key)
21
21
  @instances[key] = @definitions[key][:start].call
22
22
  end
23
23
 
24
24
  def stop(key)
25
25
  return unless started?(key)
26
- raise KeyError, "Key not defined: '#{key}'" unless defined?(key)
27
- # puts "[system] stopping #{key}"
28
26
  @definitions[key][:stop]&.call(@instances[key])
29
27
  @instances.delete(key)
30
28
  end
@@ -37,7 +35,7 @@ module PikoTools
37
35
  @instances.key?(key)
38
36
  end
39
37
 
40
- def defined?(key)
38
+ def define?(key)
41
39
  @definitions.key?(key)
42
40
  end
43
41
 
@@ -1,3 +1,3 @@
1
1
  module PikoTools
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: piko-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Szymon Kopciewski