Class: Specbandit::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/specbandit/publisher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key: Specbandit.configuration.key, key_ttl: Specbandit.configuration.key_ttl, queue: nil, output: $stdout) ⇒ Publisher

Returns a new instance of Publisher.



9
10
11
12
13
14
15
# File 'lib/specbandit/publisher.rb', line 9

def initialize(key: Specbandit.configuration.key, key_ttl: Specbandit.configuration.key_ttl, queue: nil,
               output: $stdout)
  @key = key
  @key_ttl = key_ttl
  @queue = queue || RedisQueue.new
  @output = output
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/specbandit/publisher.rb', line 7

def key
  @key
end

#key_ttlObject (readonly)

Returns the value of attribute key_ttl.



7
8
9
# File 'lib/specbandit/publisher.rb', line 7

def key_ttl
  @key_ttl
end

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/specbandit/publisher.rb', line 7

def output
  @output
end

#queueObject (readonly)

Returns the value of attribute queue.



7
8
9
# File 'lib/specbandit/publisher.rb', line 7

def queue
  @queue
end

Instance Method Details

#publish(files: [], pattern: nil) ⇒ Object

Resolve files from the three input sources (priority: stdin > pattern > args) and push them onto the Redis queue.

Returns the number of files enqueued.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/specbandit/publisher.rb', line 21

def publish(files: [], pattern: nil)
  resolved = resolve_files(files: files, pattern: pattern)

  if resolved.empty?
    output.puts '[specbandit] No files to enqueue.'
    return 0
  end

  queue.push(key, resolved, ttl: key_ttl)
  output.puts "[specbandit] Enqueued #{resolved.size} files onto key '#{key}' (TTL: #{key_ttl}s)."
  resolved.size
end