storm_flow 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b5960d5dc536c90efdeccdfe62dbc30c0e96c175f1fcf145450baebd81b3232b
4
+ data.tar.gz: fc2bc5969fd2c380e66827be73679d91f6e52849d5e1e8f8dfff55cbed54e868
5
+ SHA512:
6
+ metadata.gz: b4af5bee26eef94ce91aa217f2b6fb6a8ff6b979acf85d25b7859f250d7dda2cfd5c6717d28aed38cd8f0437fc3a663c2bd6e06354212d3fdb975a088603c3a8
7
+ data.tar.gz: 207f5c2e82ed1aed667f801ab46e28ffc3244b507977e6155207eae4e6a66950320ddafbdee87b9aa0802cac0c47baac89d682f9441a9132165d2bda95a45a6a
data/NOTICE ADDED
@@ -0,0 +1,16 @@
1
+ StormFlow — Notice
2
+
3
+ Crédits et composants:
4
+
5
+ - Ce projet utilise la bibliothèque « storm_meta » développée par 742Team
6
+ (MIT). Références: https://github.com/742Team/storm_meta
7
+
8
+ - StormFlow illustre les fonctionnalités de métaprogrammation, JIT et
9
+ auto‑tuning exposées par `storm_meta` (modules: JIT, Meta, AutoTune, Action).
10
+
11
+ Mentions légales:
12
+
13
+ - Les marques et noms cités appartiennent à leurs propriétaires respectifs.
14
+ - Aucune garantie: logiciel fourni « tel quel ».
15
+
16
+ Auteur: DALM1 (742Team)
data/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # StormFlow — Micro‑framework de workflows/action basé sur `storm_meta`
2
+
3
+ StormFlow est un micro‑framework Ruby minimaliste conçu pour démontrer les capacités de la gem `storm_meta`: métaprogrammation, DSL d’actions, auto‑optimisation et activation conditionnelle de YJIT.
4
+
5
+ ## Prérequis
6
+ - Ruby ≥ 3.2 recommandé pour YJIT moderne
7
+ - Dépendance: `storm_meta` (≥ 0.1.0)
8
+
9
+ ## Installation
10
+
11
+ ### Option A — Bundler (Ruby ≥ 3.2)
12
+ ```ruby
13
+ # Gemfile
14
+ source "https://rubygems.org"
15
+ gem "storm_meta", "~> 0.1.0"
16
+ ```
17
+ ```bash
18
+ bundle install
19
+ ```
20
+
21
+ ### Option B — Vendor fallback (Ruby < 3.2)
22
+ ```bash
23
+ git clone https://github.com/742Team/storm_meta vendor/storm_meta
24
+ ```
25
+ Puis charger la librairie vendored avant StormFlow:
26
+ ```ruby
27
+ $LOAD_PATH.unshift File.expand_path("vendor/storm_meta/lib", __dir__)
28
+ require "storm_meta"
29
+ require_relative "storm_flow"
30
+ ```
31
+
32
+ ## Utilisation rapide
33
+ ```ruby
34
+ require_relative "storm_flow"
35
+ require "securerandom"
36
+
37
+ class UserFlow
38
+ extend StormFlow
39
+
40
+ action :register_user do
41
+ param :name, :string
42
+ param :email, :string
43
+
44
+ step :validate
45
+ step do |ctx|
46
+ ctx[:id] = SecureRandom.uuid
47
+ end
48
+ step :persist
49
+ end
50
+
51
+ def validate
52
+ email = @ctx[:email]
53
+ raise "Invalid email" unless email.include?("@")
54
+ end
55
+
56
+ def persist
57
+ puts "User saved: #{@ctx[:id]} #{@ctx[:name]}"
58
+ end
59
+ end
60
+
61
+ result = UserFlow.register_user(name: "Alice", email: "alice@example.com")
62
+ puts result.inspect
63
+ ```
64
+
65
+ ## API
66
+
67
+ ### Module `StormFlow`
68
+ - `action(name, &block)`
69
+ - Crée une `StormMeta::Action::ActionDefinition`
70
+ - Évalue le bloc DSL via `instance_eval`
71
+ - Stocke la définition dans `@actions`
72
+ - Génère une méthode de classe `name` qui:
73
+ - active YJIT via `StormMeta::JIT.enable_yjit!`
74
+ - invoque `StormMeta::AutoTune.pick_best` pour choisir la stratégie la plus rapide
75
+ - exécute le pipeline (`definition.call(ctx_proxy)`) et retourne le `ctx` final
76
+ - `actions` — retourne le Hash des définitions
77
+
78
+ ### DSL d’action
79
+ - `param(name, type)` — typage léger (soft), non bloquant
80
+ - `step(name)` — symbole: appelle la méthode d’instance correspondante sur la classe (avec `@ctx` injecté)
81
+ - `step(&block)` — bloc: reçoit `ctx` (Hash‑like) et peut le modifier
82
+
83
+ ## Exécution et performances
84
+ - JIT: `StormMeta::JIT.enable_yjit!` activé au premier appel si disponible
85
+ - Auto‑tuning: `StormMeta::AutoTune.pick_best` benchmarke les stratégies et expose `StormMeta::AutoTune.last_choice`
86
+
87
+ ## Démo
88
+ - Fichier: `demo.rb`
89
+ - Exécuter: `ruby demo.rb`
90
+
91
+ ## Roadmap
92
+ - V0.2: validation typée, hooks, pipeline avant/après
93
+ - V0.3: parallélisation, bus d’événements
94
+ - V1.0: moteur stable, intégration STORM
95
+
96
+ ## Licence et crédits
97
+ - StormFlow — par DALM1 (742Team)
98
+ - Dépend de `storm_meta` (MIT) — https://github.com/742Team/storm_meta# storm_flow
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'fileutils'
5
+
6
+ repo = 'https://github.com/742Team/storm_meta'
7
+ dest = File.expand_path('../vendor/storm_meta', __dir__)
8
+
9
+ if Dir.exist?(dest)
10
+ Dir.chdir(dest) do
11
+ system('git pull --ff-only') || abort('Failed to pull storm_meta')
12
+ end
13
+ else
14
+ system("git clone #{repo} #{dest}") || abort('Failed to clone storm_meta')
15
+ end
16
+
17
+ git_dir = File.join(dest, '.git')
18
+ FileUtils.rm_rf(git_dir) if Dir.exist?(git_dir)
19
+
20
+ puts 'storm_meta synced into vendor/storm_meta'
data/lib/storm_flow.rb ADDED
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StormFlow
4
+ def action(name, &block)
5
+ StormMeta::JIT.enable_yjit! rescue nil
6
+
7
+ @actions ||= {}
8
+ definition = StormMeta::Action::ActionDefinition.new(name)
9
+ definition.instance_eval(&block) if block_given?
10
+ @actions[name] = definition
11
+
12
+ define_singleton_method(name) do |ctx = {}|
13
+ h = ctx
14
+ k = self
15
+
16
+ proxy = Object.new
17
+ proxy.define_singleton_method(:[]) { |key| h[key] }
18
+ proxy.define_singleton_method(:[]=) { |key, value| h[key] = value }
19
+ proxy.define_singleton_method(:respond_to?) { |m, inc = false| k.instance_methods.include?(m) || super(m, inc) }
20
+ proxy.define_singleton_method(:method_missing) do |m, *args, &blk|
21
+ if k.instance_methods.include?(m)
22
+ inst = k.new
23
+ inst.instance_variable_set(:@ctx, h)
24
+ inst.public_send(m, *args, &blk)
25
+ else
26
+ super(m, *args, &blk)
27
+ end
28
+ end
29
+
30
+ best = StormMeta::AutoTune.pick_best(
31
+ {
32
+ fast: ->(x) { definition.call(x) },
33
+ slower: ->(x) { definition.call(x) }
34
+ },
35
+ warmup_input: proxy,
36
+ iterations: 50
37
+ )
38
+ best.call(proxy)
39
+ ctx
40
+ end
41
+ end
42
+
43
+ def actions
44
+ @actions || {}
45
+ end
46
+ end
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 DALM1, 742Team
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,78 @@
1
+ # StormMeta
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
4
+
5
+ Helpers de métaprogrammation, JIT et auto-tuning pour des services Ruby haute performance.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ gem install storm_meta
11
+ ```
12
+
13
+ ou dans votre `Gemfile`:
14
+
15
+ ```ruby
16
+ gem "storm_meta", "~> 0.1.0"
17
+ ```
18
+
19
+ ## Utilisation rapide
20
+
21
+ ```ruby
22
+ require "storm_meta"
23
+
24
+ # Activer YJIT si disponible
25
+ StormMeta::JIT.enable_yjit!(verbose: true)
26
+
27
+ # Métaprogrammation
28
+ class Room
29
+ extend StormMeta::Meta
30
+
31
+ dynamic_attr :name, :owner_id
32
+ boolean_flags :archived, :locked
33
+ end
34
+
35
+ room = Room.new
36
+ room.name = "Alpha"
37
+ room.archived!
38
+ puts room.archived? # => true
39
+
40
+ # Auto-tuning
41
+ strategies = {
42
+ ruby: ->(x) { x.to_s },
43
+ alt: ->(x) { "#{x}" }
44
+ }
45
+
46
+ best = StormMeta::AutoTune.pick_best(strategies, warmup_input: 123)
47
+ puts StormMeta::AutoTune.last_choice # => :ruby ou :alt
48
+
49
+ # Actions DSL
50
+ class UserActions
51
+ extend StormMeta::Action
52
+
53
+ action :ban_user do
54
+ param :user_id, :integer
55
+ step :load_user
56
+ step :mark_banned
57
+ end
58
+ end
59
+ ```
60
+
61
+ ## Modules
62
+
63
+ - `StormMeta::JIT` — activation YJIT en toute sécurité (`supports_yjit?`, `enable_yjit!`, `with_yjit`).
64
+ - `StormMeta::Meta` — helpers pour `dynamic_attr`, `boolean_flags`, `dsl`.
65
+ - `StormMeta::AutoTune` — benchmarke des stratégies et choisit la plus rapide.
66
+ - `StormMeta::Action` — DSL léger pour décrire et exécuter des actions.
67
+
68
+ ## Exigences
69
+
70
+ - Ruby `>= 3.2.0` recommandé pour un support YJIT moderne.
71
+
72
+ ## Licence
73
+
74
+ MIT — voir `LICENSE`.
75
+
76
+ ## Notices
77
+
78
+ Voir `NOTICE.md` pour les avis et informations tiers éventuels.
@@ -0,0 +1,50 @@
1
+ module StormMeta
2
+ module Action
3
+ def actions
4
+ @actions ||= {}
5
+ end
6
+
7
+ def action(name, &block)
8
+ definition = ActionDefinition.new(name)
9
+ definition.instance_eval(&block) if block_given?
10
+ actions[name.to_sym] = definition
11
+
12
+ define_singleton_method(name) do |ctx = {}|
13
+ actions[name.to_sym].call(ctx)
14
+ end
15
+ end
16
+
17
+ class ActionDefinition
18
+ attr_reader :name, :params, :steps
19
+
20
+ def initialize(name)
21
+ @name = name
22
+ @params = []
23
+ @steps = []
24
+ end
25
+
26
+ def param(name, type = :any)
27
+ @params << [name, type]
28
+ end
29
+
30
+ def step(name = nil, &block)
31
+ @steps << (block || name.to_sym)
32
+ end
33
+
34
+ def call(ctx)
35
+ @steps.each do |s|
36
+ case s
37
+ when Symbol
38
+ if ctx.respond_to?(s)
39
+ ctx.public_send(s)
40
+ elsif ctx.is_a?(Hash) && ctx.key?(s)
41
+ ctx[s]
42
+ end
43
+ else
44
+ s.call(ctx)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,35 @@
1
+ require "benchmark"
2
+
3
+ module StormMeta
4
+ module AutoTune
5
+ @last_choice = nil
6
+
7
+ class << self
8
+ attr_reader :last_choice
9
+ end
10
+
11
+ def self.pick_best(strategies, warmup_input:, iterations: 50)
12
+ raise ArgumentError, "Need at least one strategy" if strategies.empty?
13
+
14
+ # Warmup
15
+ strategies.each_value do |fn|
16
+ 3.times { fn.call(warmup_input) }
17
+ end
18
+
19
+ timings = {}
20
+
21
+ strategies.each do |name, fn|
22
+ time = Benchmark.realtime do
23
+ iterations.times { fn.call(warmup_input) }
24
+ end
25
+
26
+ timings[name] = time
27
+ end
28
+
29
+ best_name, _ = timings.min_by { |_, t| t }
30
+ @last_choice = best_name
31
+
32
+ strategies[best_name]
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ module StormMeta
2
+ module JIT
3
+ class << self
4
+ def supports_yjit?
5
+ defined?(RubyVM::YJIT) && RubyVM::YJIT.respond_to?(:enable)
6
+ rescue StandardError
7
+ false
8
+ end
9
+
10
+ def enable_yjit!(verbose: false)
11
+ return false unless supports_yjit?
12
+
13
+ if RubyVM::YJIT.respond_to?(:enabled?)
14
+ return true if RubyVM::YJIT.enabled?
15
+ end
16
+
17
+ RubyVM::YJIT.enable
18
+ puts "[StormMeta::JIT] YJIT enabled" if verbose
19
+ true
20
+ rescue StandardError => e
21
+ warn "[StormMeta::JIT] Failed to enable YJIT: #{e.class}: #{e.message}" if verbose
22
+ false
23
+ end
24
+
25
+ def with_yjit(verbose: false)
26
+ enable_yjit!(verbose: verbose)
27
+ yield
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ module StormMeta
2
+ module Meta
3
+ def dynamic_attr(*names)
4
+ names.each do |name|
5
+ define_method(name) do
6
+ instance_variable_get("@#{name}")
7
+ end
8
+
9
+ define_method("#{name}=") do |value|
10
+ instance_variable_set("@#{name}", value)
11
+ end
12
+ end
13
+ end
14
+
15
+ def boolean_flags(*names)
16
+ names.each do |name|
17
+ define_method("#{name}?") do
18
+ !!instance_variable_get("@#{name}")
19
+ end
20
+
21
+ define_method("#{name}!") do
22
+ instance_variable_set("@#{name}", true)
23
+ end
24
+
25
+ define_method("not_#{name}!") do
26
+ instance_variable_set("@#{name}", false)
27
+ end
28
+ end
29
+ end
30
+
31
+ def dsl(&block)
32
+ class_eval(&block)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module StormMeta
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "storm_meta/version"
2
+ require_relative "storm_meta/jit"
3
+ require_relative "storm_meta/meta"
4
+ require_relative "storm_meta/auto_tune"
5
+ require_relative "storm_meta/action"
6
+
7
+ module StormMeta
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "storm_meta"
3
+ spec.version = "0.1.0"
4
+ spec.summary = "Metaprogramming & JIT helpers for high-performance Ruby services"
5
+ spec.description = "Helpers for YJIT, metaprogramming patterns, and auto-tuning strategies used by STORM and other microservices."
6
+ spec.authors = ["DALM1"]
7
+ spec.email = ["dimitri.almon@gmail.com"]
8
+
9
+ spec.files = Dir["lib/**/*"] + ["LICENSE", "README.md", "NOTICE", "NOTICE.md"]
10
+ spec.require_paths = ["lib"]
11
+ spec.required_ruby_version = ">= 3.2.0"
12
+
13
+ spec.homepage = "https://github.com/742Team/storm_meta"
14
+ spec.license = "MIT"
15
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: storm_flow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - DALM1
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-11-19 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: StormFlow démontre le DSL d’actions, l’auto-tuning et YJIT via storm_meta.
14
+ email:
15
+ - contact@example.com
16
+ executables:
17
+ - sync_storm_meta
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - NOTICE
22
+ - README.md
23
+ - bin/sync_storm_meta
24
+ - lib/storm_flow.rb
25
+ - vendor/storm_meta/LICENSE
26
+ - vendor/storm_meta/README.md
27
+ - vendor/storm_meta/lib/storm_meta.rb
28
+ - vendor/storm_meta/lib/storm_meta/action.rb
29
+ - vendor/storm_meta/lib/storm_meta/auto_tune.rb
30
+ - vendor/storm_meta/lib/storm_meta/jit.rb
31
+ - vendor/storm_meta/lib/storm_meta/meta.rb
32
+ - vendor/storm_meta/lib/storm_meta/version.rb
33
+ - vendor/storm_meta/storm_meta.gemspec
34
+ homepage: https://github.com/742Team/storm_flow
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ source_code_uri: https://github.com/742Team/storm_flow
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ - vendor/storm_meta/lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '3.2'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.3.7
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Micro-framework de workflows basé sur storm_meta
59
+ test_files: []