bard 1.5.5 → 1.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e299224241e3766a31c3dfe6a95b6d4ac74d50a189b4fecd8cd79a2f1856c8ab
4
- data.tar.gz: 0b87cc9f75177aa95105924a65af0a5e67a9067b177a8824cfd3206bc3d17fe1
3
+ metadata.gz: 21d6d4352d9957502860997ea4c05c9df90cffd4eab76391041c913483892c7f
4
+ data.tar.gz: ad893862a2a2a3968f12c8c034a08c8c92d3f07aade157ba60ab676e39f10ae0
5
5
  SHA512:
6
- metadata.gz: 866ce92cbfcc95a4cd2813da2f5cf1db8f40631270ae3160ad8981ae5d71e79deb8cf20f6b41125853b9f0ba05cadd3b878d074532d1ab5cdba5bee3e7ad9921
7
- data.tar.gz: f33f6555089298fd42b361ed3d5f7c681d6df9ed0265b4027a83a4168d680ee35cb877002e8fb8d58c4e8c9e6e8e05b89d389c0e85e9de75e6861af0f70fdf39
6
+ metadata.gz: 7036c5b3d97b827c62905238d4cf66c53e56aeac82f847c29877ae7482dabeece807f6ffec6cf9bfbf9b2c4796ae33e40d2713509b906ee8754aa2f4cc1521be
7
+ data.tar.gz: 895b98dc68a3144eee0d4ad72a4a47d38bfffdbdf520d5f029a8484a356f57d80b447e7d335d2f67e49cae2e566e7e7601c4109fc2b6664be0078040b6224d35
data/lib/bard/config.rb CHANGED
@@ -65,14 +65,20 @@ module Bard
65
65
  end
66
66
  end
67
67
 
68
- def backup *args
69
- if args.length == 1
70
- @backup = args.first
71
- elsif args.length == 0
68
+ def backup(value = nil, &block)
69
+ if block_given?
70
+ @backup = BackupConfig.new(&block)
71
+ elsif value == false
72
+ @backup = false
73
+ elsif value == true
74
+ # Backward compatibility: backup true
75
+ @backup = BackupConfig.new { bard }
76
+ elsif value.nil?
77
+ # Getter
72
78
  return @backup if defined?(@backup)
73
- @backup = true
79
+ @backup = BackupConfig.new { bard } # Default
74
80
  else
75
- raise ArgumentError
81
+ raise ArgumentError, "backup accepts a block, true, or false"
76
82
  end
77
83
  end
78
84
 
@@ -98,4 +104,35 @@ module Bard
98
104
  backup false
99
105
  end
100
106
  end
107
+
108
+ class BackupConfig
109
+ attr_reader :bard_enabled, :destinations
110
+
111
+ def initialize(&block)
112
+ @bard_enabled = false
113
+ @destinations = []
114
+ instance_eval(&block) if block_given?
115
+ end
116
+
117
+ def bard
118
+ @bard_enabled = true
119
+ end
120
+
121
+ def s3(name, credentials:, path:)
122
+ @destinations << {
123
+ name: name,
124
+ type: :s3,
125
+ credentials: credentials,
126
+ path: path
127
+ }
128
+ end
129
+
130
+ def bard?
131
+ @bard_enabled
132
+ end
133
+
134
+ def self_managed?
135
+ @destinations.any?
136
+ end
137
+ end
101
138
  end
data/lib/bard/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "1.5.5"
2
+ VERSION = "1.6.0"
3
3
  end
4
4
 
@@ -29,8 +29,11 @@ describe Bard::Config do
29
29
  end
30
30
 
31
31
  describe "#backup" do
32
- it "returns true" do
33
- expect(subject.backup).to eq true
32
+ it "returns a BackupConfig with bard enabled by default" do
33
+ backup = subject.backup
34
+ expect(backup).to be_a(Bard::BackupConfig)
35
+ expect(backup.bard?).to eq true
36
+ expect(backup.destinations).to be_empty
34
37
  end
35
38
  end
36
39
  end
@@ -79,5 +82,82 @@ describe Bard::Config do
79
82
  end
80
83
  end
81
84
  end
85
+
86
+ context "with new backup block syntax" do
87
+ describe "#backup with bard directive" do
88
+ subject { described_class.new("test", source: "backup { bard }") }
89
+
90
+ it "returns a BackupConfig with bard enabled" do
91
+ backup = subject.backup
92
+ expect(backup).to be_a(Bard::BackupConfig)
93
+ expect(backup.bard?).to eq true
94
+ expect(backup.destinations).to be_empty
95
+ expect(backup.self_managed?).to eq false
96
+ end
97
+ end
98
+
99
+ describe "#backup with s3 directive" do
100
+ subject { described_class.new("test", source: "backup { s3 :primary, credentials: :backup, path: 'bucket/path' }") }
101
+
102
+ it "returns a BackupConfig with s3 destination" do
103
+ backup = subject.backup
104
+ expect(backup).to be_a(Bard::BackupConfig)
105
+ expect(backup.bard?).to eq false
106
+ expect(backup.destinations.length).to eq 1
107
+ expect(backup.self_managed?).to eq true
108
+
109
+ dest = backup.destinations.first
110
+ expect(dest[:name]).to eq :primary
111
+ expect(dest[:type]).to eq :s3
112
+ expect(dest[:credentials]).to eq :backup
113
+ expect(dest[:path]).to eq 'bucket/path'
114
+ end
115
+ end
116
+
117
+ describe "#backup with both bard and s3 directives" do
118
+ subject { described_class.new("test", source: "backup { bard; s3 :custom, credentials: :backup, path: 'bucket/path' }") }
119
+
120
+ it "returns a BackupConfig with bard and s3 destination" do
121
+ backup = subject.backup
122
+ expect(backup).to be_a(Bard::BackupConfig)
123
+ expect(backup.bard?).to eq true
124
+ expect(backup.destinations.length).to eq 1
125
+ expect(backup.self_managed?).to eq true
126
+ end
127
+ end
128
+
129
+ describe "#backup with multiple s3 destinations" do
130
+ subject do
131
+ described_class.new("test", source: <<~SOURCE)
132
+ backup do
133
+ s3 :primary, credentials: :backup1, path: 'bucket1/path'
134
+ s3 :secondary, credentials: :backup2, path: 'bucket2/path'
135
+ end
136
+ SOURCE
137
+ end
138
+
139
+ it "returns a BackupConfig with multiple destinations" do
140
+ backup = subject.backup
141
+ expect(backup).to be_a(Bard::BackupConfig)
142
+ expect(backup.bard?).to eq false
143
+ expect(backup.destinations.length).to eq 2
144
+ expect(backup.self_managed?).to eq true
145
+
146
+ expect(backup.destinations[0][:name]).to eq :primary
147
+ expect(backup.destinations[1][:name]).to eq :secondary
148
+ end
149
+ end
150
+
151
+ describe "#backup true (backward compatibility)" do
152
+ subject { described_class.new("test", source: "backup true") }
153
+
154
+ it "returns a BackupConfig with bard enabled" do
155
+ backup = subject.backup
156
+ expect(backup).to be_a(Bard::BackupConfig)
157
+ expect(backup.bard?).to eq true
158
+ expect(backup.destinations).to be_empty
159
+ end
160
+ end
161
+ end
82
162
  end
83
163
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-11-30 00:00:00.000000000 Z
10
+ date: 2025-12-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: thor