PikoTools

Micro-framework for building applications with data-driven architecture.

Installation

Add to your Gemfile:

gem "piko-tools"

Or install directly:

gem install piko-tools

Usage

State

Lazy lifecycle manager with start/stop semantics.

state = PikoTools::State.new do |s|
  s.define(:db,     -> { Database.connect },     stop: ->(conn) { conn.close })
  s.define(:cache,  -> { Cache.new },             stop: ->(c)    { c.flush })
  s.define(:logger, -> { Logger.new })
end

# Lazy start — connects on first access
logger = state[:logger]

# Query state
state.started?(:db)     # => false
state.start_all
state.started?(:db)     # => true

# Stop with teardown callback
state.stop(:db)         # calls Database#close

# Reload (stop + start)
state.reload(:cache)

# Stop all in reverse order, then clear definitions
state.clear!

Builder

Fluent builder for composing objects with keyword arguments.

class Handler
  def initialize(args = {})
    @args = args
  end
end

handler = PikoTools::Builder.new(Handler)
  .set(foo: 1, bar: 2)
  .build(baz: 3)

handler    # => #<Handler @args={foo: 1, bar: 2, build_args: {baz: 3}}>

Component

Mixin providing config-based private attributes via OpenStruct.

class MyComponent
  include PikoTools::Component
  attr_struct :host, :port
end

component = MyComponent.new(host: "localhost", port: 3000)
component.send(:host)  # => "localhost"
component.send(:port)  # => 3000

Requirements

Ruby >= 3.2. No runtime dependencies.