piko-tools 1.0.2 → 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: 9c9ae4a74e5273b80eaf96c47b449628d39ab61150bf92bfd9e2dbda159ec90c
4
- data.tar.gz: 8907d0f6812d7ddbd609322325e285502610a034cc2c95272414090f638c00b4
3
+ metadata.gz: b24d94cf9680123a4cc1c2b421fe6d35db7ddc083dcf5558f8cbcf2950e115cf
4
+ data.tar.gz: 0a43ccdded4b3f0122a2a21eebd6f8a974925663c454f172ca21814bbb145727
5
5
  SHA512:
6
- metadata.gz: 26f14abc9c411d268ebb72413be66b5a9e7deaade3bc936c37eb1ee6d961264bc0c3161e84f577e3fdcf33d3fdb580dd80cc0590de4c2b399074f5841f852178
7
- data.tar.gz: 4de4b2b6990eb2c983c703d5be91ce190e53a7120498090f6c518fc749bb4f87425726188c1cf217b585551b0940d522e87b6dfadbecb785ef56736a75c3d486
6
+ metadata.gz: 11b82066788856f87b1ece4f1b41345f8d5a10cfce114091378998bee60a057917e5a961b0456e335bee773cf4f2139575040afef6398740956a036db2ef0cda
7
+ data.tar.gz: 7be734cea5b77fb79e92da3fcce5c32d04ddff0e8292f49dc0dfdb7ecbd6368d6e83a5c775392b21b8f0dc46563bd48ad2b86e7ec5833cbf19568d26a9070b34
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.0.2] - 2025-09-02
4
+
5
+ ### Fixed
6
+
7
+ - Fix state check
8
+
3
9
  ## [1.0.1] - 2025-09-02
4
10
 
5
11
  ### Added
@@ -14,6 +20,8 @@ Init
14
20
 
15
21
  - Init
16
22
 
23
+ [1.0.2]: https://gitlab.com/skopciewski/piko-tools/-/compare/1.0.1...1.0.2
24
+
17
25
  [1.0.1]: https://gitlab.com/skopciewski/piko-tools/-/compare/1.0.0...1.0.1
18
26
 
19
27
  [1.0.0]: https://gitlab.com/skopciewski/piko-tools/-/compare/0.0.0...1.0.0
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
 
@@ -18,13 +18,11 @@ module PikoTools
18
18
  def start(key)
19
19
  return @instances[key] if started?(key)
20
20
  raise KeyError, "Key not defined: '#{key}'" unless define?(key)
21
- # puts "[system] starting #{key}"
22
21
  @instances[key] = @definitions[key][:start].call
23
22
  end
24
23
 
25
24
  def stop(key)
26
25
  return unless started?(key)
27
- # puts "[system] stopping #{key}"
28
26
  @definitions[key][:stop]&.call(@instances[key])
29
27
  @instances.delete(key)
30
28
  end
@@ -1,3 +1,3 @@
1
1
  module PikoTools
2
- VERSION = "1.0.2"
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.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Szymon Kopciewski