Skip to content

Commit 5717665

Browse files
committed
chore: remove "open" method
1 parent 84c8b43 commit 5717665

4 files changed

Lines changed: 37 additions & 102 deletions

File tree

README.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,6 @@ engine = LingoDotDev::Engine.new(api_key: 'your-api-key')
4444
# Localize text
4545
result = engine.localize_text('Hello world', target_locale: 'es')
4646
puts result # => "Hola mundo"
47-
48-
# Clean up when done
49-
engine.close
50-
```
51-
52-
For automatic resource management, use the block form:
53-
54-
```ruby
55-
LingoDotDev::Engine.open(api_key: 'your-api-key') do |engine|
56-
result = engine.localize_text('Hello world', target_locale: 'es')
57-
puts result
58-
end
5947
```
6048

6149
## Usage
@@ -354,19 +342,8 @@ Returns information about the authenticated user.
354342

355343
- **Returns:** Hash with `:email` and `:id` keys, or `nil` if authentication fails
356344

357-
#### `close`
358-
359-
Closes the engine and cleans up resources.
360-
361345
### Class methods
362346

363-
#### `Engine.open(api_key:, **options, &block)`
364-
365-
Creates an engine instance with automatic resource cleanup.
366-
367-
- **Parameters:** Same as `Engine.new`
368-
- **Returns:** Engine instance (or yields to block and returns block result)
369-
370347
#### `Engine.quick_translate(content, api_key:, target_locale:, source_locale: nil, fast: true, api_url: 'https://engine.lingo.dev')`
371348

372349
One-off translation without managing engine lifecycle.

examples/ruby-on-rails/app/controllers/translate_controller.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ class TranslateController < ApplicationController
66
def translate
77
api_key = ENV['LINGODOTDEV_API_KEY'] || 'your-api-key-here'
88

9-
translated = LingoDotDev::Engine.open(api_key: api_key) do |engine|
10-
engine.localize_text('Hello world', target_locale: 'es')
11-
end
9+
engine = LingoDotDev::Engine.new(api_key: api_key)
10+
translated = engine.localize_text('Hello world', target_locale: 'es')
1211

1312
render json: {
1413
original: 'Hello world',

lib/lingodotdev.rb

Lines changed: 35 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,6 @@ def initialize(api_key:, api_url: 'https://engine.lingo.dev', batch_size: 25, id
9090
@config.send(:validate!)
9191
end
9292

93-
def self.open(api_key:, **options)
94-
engine = new(api_key: api_key, **options)
95-
return engine unless block_given?
96-
97-
begin
98-
yield engine
99-
ensure
100-
engine.close
101-
end
102-
end
103-
104-
def close
105-
@client = nil
106-
end
107-
10893
def localize_text(text, target_locale:, source_locale: nil, fast: nil, reference: nil, on_progress: nil, concurrent: false, &block)
10994
raise ValidationError, 'Target locale is required' if target_locale.nil? || target_locale.empty?
11095
raise ValidationError, 'Text cannot be nil' if text.nil?
@@ -272,53 +257,51 @@ def whoami
272257
end
273258

274259
def self.quick_translate(content, api_key:, target_locale:, source_locale: nil, fast: true, api_url: 'https://engine.lingo.dev')
275-
open(api_key: api_key, api_url: api_url) do |engine|
276-
case content
277-
when String
278-
engine.localize_text(
279-
content,
280-
target_locale: target_locale,
281-
source_locale: source_locale,
282-
fast: fast
283-
)
284-
when Hash
285-
engine.localize_object(
286-
content,
287-
target_locale: target_locale,
288-
source_locale: source_locale,
289-
fast: fast,
290-
concurrent: true
291-
)
292-
else
293-
raise ValidationError, 'Content must be a String or Hash'
294-
end
260+
engine = new(api_key: api_key, api_url: api_url)
261+
case content
262+
when String
263+
engine.localize_text(
264+
content,
265+
target_locale: target_locale,
266+
source_locale: source_locale,
267+
fast: fast
268+
)
269+
when Hash
270+
engine.localize_object(
271+
content,
272+
target_locale: target_locale,
273+
source_locale: source_locale,
274+
fast: fast,
275+
concurrent: true
276+
)
277+
else
278+
raise ValidationError, 'Content must be a String or Hash'
295279
end
296280
end
297281

298282
def self.quick_batch_translate(content, api_key:, target_locales:, source_locale: nil, fast: true, api_url: 'https://engine.lingo.dev')
299-
open(api_key: api_key, api_url: api_url) do |engine|
300-
case content
301-
when String
302-
engine.batch_localize_text(
283+
engine = new(api_key: api_key, api_url: api_url)
284+
case content
285+
when String
286+
engine.batch_localize_text(
287+
content,
288+
target_locales: target_locales,
289+
source_locale: source_locale,
290+
fast: fast,
291+
concurrent: true
292+
)
293+
when Hash
294+
target_locales.map do |target_locale|
295+
engine.localize_object(
303296
content,
304-
target_locales: target_locales,
297+
target_locale: target_locale,
305298
source_locale: source_locale,
306299
fast: fast,
307300
concurrent: true
308301
)
309-
when Hash
310-
target_locales.map do |target_locale|
311-
engine.localize_object(
312-
content,
313-
target_locale: target_locale,
314-
source_locale: source_locale,
315-
fast: fast,
316-
concurrent: true
317-
)
318-
end
319-
else
320-
raise ValidationError, 'Content must be a String or Hash'
321302
end
303+
else
304+
raise ValidationError, 'Content must be a String or Hash'
322305
end
323306
end
324307

spec/lingo_dot_dev/engine_spec.rb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,6 @@
3434
end
3535
end
3636

37-
describe '.open' do
38-
it 'returns an engine without a block' do
39-
engine = described_class.open(api_key: api_key)
40-
expect(engine).to be_a(described_class)
41-
end
42-
43-
it 'yields engine to block and closes after' do
44-
result = nil
45-
described_class.open(api_key: api_key) do |engine|
46-
expect(engine).to be_a(described_class)
47-
result = engine
48-
end
49-
expect(result.instance_variable_get(:@client)).to be_nil
50-
end
51-
end
52-
53-
describe '#close' do
54-
it 'clears the http client' do
55-
engine = described_class.new(api_key: api_key)
56-
engine.close
57-
expect(engine.instance_variable_get(:@client)).to be_nil
58-
end
59-
end
60-
6137
describe '#localize_text' do
6238
it 'localizes text to target locale' do
6339
engine = described_class.new(api_key: api_key)

0 commit comments

Comments
 (0)