vial 0.0.0 → 0.2026.1.1.0

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.
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'stringio'
4
+
5
+ module Vial
6
+ class YamlEmitter
7
+ def initialize(records)
8
+ @records = records
9
+ end
10
+
11
+ def to_yaml
12
+ buffer = StringIO.new
13
+ write_to(buffer)
14
+ buffer.string
15
+ end
16
+
17
+ def write_to(io)
18
+ @records.each do |record|
19
+ io << "#{record.fixture_label}:\n"
20
+ if record.attributes.empty?
21
+ io << " {}\n"
22
+ next
23
+ end
24
+
25
+ record.attributes.each do |key, value|
26
+ formatted = format_value(value)
27
+ if formatted.is_a?(Array)
28
+ io << " #{key}:\n"
29
+ formatted.each do |line|
30
+ io << " #{line}\n"
31
+ end
32
+ else
33
+ io << " #{key}: #{formatted}\n"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def format_value(value)
42
+ case value
43
+ in Vial::Erb(source)
44
+ source
45
+ in Time | Date | DateTime | ActiveSupport::TimeWithZone
46
+ format_time(value)
47
+ in TrueClass
48
+ 'true'
49
+ in FalseClass
50
+ 'false'
51
+ in NilClass
52
+ 'null'
53
+ in Numeric
54
+ value.to_s
55
+ in String
56
+ value.inspect
57
+ in Array => array
58
+ format_array(array)
59
+ in Hash => hash
60
+ yaml_block(hash)
61
+ else
62
+ yaml = YAML.dump(value)
63
+ block = normalize_yaml_block(yaml)
64
+ return block if block.length > 1
65
+ block.first
66
+ end
67
+ end
68
+
69
+ def yaml_block(value)
70
+ normalize_yaml_block(YAML.dump(value))
71
+ end
72
+
73
+ def format_array(array)
74
+ return yaml_block(array) unless array.all? { |item| scalar_value?(item) }
75
+
76
+ array.map { |item| "- #{format_scalar(item)}" }
77
+ end
78
+
79
+ def scalar_value?(value)
80
+ case value
81
+ in Vial::Erb
82
+ true
83
+ in Time | Date | DateTime | ActiveSupport::TimeWithZone
84
+ true
85
+ in TrueClass | FalseClass | NilClass | Numeric | String
86
+ true
87
+ else
88
+ false
89
+ end
90
+ end
91
+
92
+ def format_scalar(value)
93
+ case value
94
+ in Vial::Erb(source)
95
+ source
96
+ in Time | Date | DateTime | ActiveSupport::TimeWithZone
97
+ format_time(value)
98
+ in TrueClass
99
+ 'true'
100
+ in FalseClass
101
+ 'false'
102
+ in NilClass
103
+ 'null'
104
+ in Numeric
105
+ value.to_s
106
+ in String
107
+ value.inspect
108
+ else
109
+ YAML.dump(value).strip
110
+ end
111
+ end
112
+
113
+ def normalize_yaml_block(yaml)
114
+ lines = yaml.lines.map(&:rstrip)
115
+ if lines.first&.start_with?('--- ')
116
+ lines[0] = lines.first.sub(/\A---\s*/, '')
117
+ elsif lines.first == '---'
118
+ lines.shift
119
+ end
120
+ lines.pop if lines.last&.start_with?('...')
121
+ lines.reject!(&:empty?)
122
+ lines
123
+ end
124
+
125
+ def format_time(value)
126
+ if value.is_a?(Date) && !value.is_a?(Time)
127
+ value.iso8601
128
+ else
129
+ value.iso8601
130
+ end
131
+ end
132
+ end
133
+ end
data/lib/vial.rb CHANGED
@@ -1,9 +1,108 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'fileutils'
4
+ require 'pathname'
5
+ require 'set'
6
+ require 'yaml'
7
+ require 'zlib'
8
+ require 'time'
9
+ require 'date'
10
+ require 'active_record'
11
+ require 'active_support/inflector'
12
+ require 'active_support/test_case'
13
+ require 'active_support/time'
14
+ require 'vial/version'
15
+
16
+ unless ActiveSupport::TestCase.respond_to?(:fixture_paths)
17
+ ActiveSupport::TestCase.singleton_class.attr_accessor :fixture_paths
18
+ end
19
+
20
+ begin
21
+ require 'vial/railtie'
22
+ rescue LoadError
23
+ # Rails is optional for the core compiler; tasks load via Railtie when present.
24
+ end
25
+ require 'vial/config'
26
+ require 'vial/explicit_id'
27
+ require 'vial/erb'
28
+ require 'vial/sequence'
29
+ require 'vial/definition'
30
+ require 'vial/registry'
31
+ require 'vial/dsl'
32
+ require 'vial/loader'
33
+ require 'vial/explain_id'
34
+ require 'vial/yaml_emitter'
35
+ require 'vial/compiler'
36
+ require 'vial/validator'
37
+ require 'vial/fixture_analyzer'
38
+ require 'vial/fixture_id_standardizer'
39
+
3
40
  module Vial
4
- VERSION = "0.0.0"
5
-
6
41
  def self.version
7
42
  VERSION
8
43
  end
9
- end
44
+
45
+ def self.config
46
+ @config ||= Config.new
47
+ end
48
+
49
+ def self.configure
50
+ yield(config) if block_given?
51
+ config
52
+ end
53
+
54
+ def self.registry
55
+ @registry ||= Registry.new
56
+ end
57
+
58
+ def self.last_loaded_files
59
+ @last_loaded_files ||= []
60
+ end
61
+
62
+ def self.reset_registry!
63
+ @registry = Registry.new
64
+ end
65
+
66
+ def self.define(name, **options, &block)
67
+ registry.define(name, **options, &block)
68
+ end
69
+
70
+ def self.compile!(dry_run: false, only: nil, **options)
71
+ Compiler.new(config: config, **options).compile!(dry_run: dry_run, only: only)
72
+ end
73
+
74
+ def self.clean!(**options)
75
+ Compiler.new(config: config, **options).clean!
76
+ end
77
+
78
+ def self.build_box
79
+ box = if defined?(Ruby::Box) && ENV['RUBY_BOX'] == '1'
80
+ Ruby::Box.new
81
+ else
82
+ Module.new
83
+ end
84
+
85
+ host_vial = self
86
+ box.singleton_class.define_method(:vial) do |name, **options, &block|
87
+ host_vial.define(name, **options, &block)
88
+ end
89
+
90
+ box
91
+ end
92
+
93
+ def self.load_sources!(source_paths: config.source_paths)
94
+ reset_registry!
95
+ @last_loaded_files = []
96
+ box = build_box
97
+ Array(source_paths).each do |path|
98
+ next unless File.directory?(path)
99
+
100
+ Dir[File.join(path, '**', '*.vial.rb')].sort.each do |file|
101
+ @last_loaded_files << file
102
+ Loader.new(file, box: box).load
103
+ end
104
+ end
105
+
106
+ registry
107
+ end
108
+ end
metadata CHANGED
@@ -1,31 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.2026.1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - seuros
7
+ - Abdelkader Boudih
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: rails
13
+ name: activerecord
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '7.0'
18
+ version: '8.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: '7.0'
26
- description: Vial revolutionizes test fixtures with intelligent data management, dynamic
27
- generation, and seamless integration. This is a placeholder gem - full implementation
28
- coming soon.
25
+ version: '8.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: minitest
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rake
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ description: Vial compiles programmable fixture intent into explicit, deterministic
55
+ fixtures for Rails.
29
56
  email:
30
57
  - terminale@gmail.com
31
58
  executables: []
@@ -34,7 +61,28 @@ extra_rdoc_files: []
34
61
  files:
35
62
  - LICENSE.txt
36
63
  - README.md
64
+ - examples/admin_users.vial.rb
65
+ - examples/base_users.vial.rb
66
+ - examples/company__users.vial.rb
67
+ - examples/users.vial.rb
68
+ - lib/tasks/vial.rake
37
69
  - lib/vial.rb
70
+ - lib/vial/compiler.rb
71
+ - lib/vial/config.rb
72
+ - lib/vial/definition.rb
73
+ - lib/vial/dsl.rb
74
+ - lib/vial/erb.rb
75
+ - lib/vial/explain_id.rb
76
+ - lib/vial/explicit_id.rb
77
+ - lib/vial/fixture_analyzer.rb
78
+ - lib/vial/fixture_id_standardizer.rb
79
+ - lib/vial/loader.rb
80
+ - lib/vial/railtie.rb
81
+ - lib/vial/registry.rb
82
+ - lib/vial/sequence.rb
83
+ - lib/vial/validator.rb
84
+ - lib/vial/version.rb
85
+ - lib/vial/yaml_emitter.rb
38
86
  homepage: https://github.com/seuros/vial
39
87
  licenses:
40
88
  - MIT
@@ -49,14 +97,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
97
  requirements:
50
98
  - - ">="
51
99
  - !ruby/object:Gem::Version
52
- version: 3.0.0
100
+ version: 4.0.0
53
101
  required_rubygems_version: !ruby/object:Gem::Requirement
54
102
  requirements:
55
103
  - - ">="
56
104
  - !ruby/object:Gem::Version
57
105
  version: '0'
58
106
  requirements: []
59
- rubygems_version: 3.6.9
107
+ rubygems_version: 4.0.3
60
108
  specification_version: 4
61
109
  summary: 'Vial: Fixtures, Reinvented'
62
110
  test_files: []