Class: Lazylead::Opts

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/lazylead/opts.rb

Overview

Default options for all lazylead tasks.

Author

Yurii Dubinka ([email protected])

Copyright

Copyright © 2019-2020 Yurii Dubinka

License

MIT

Instance Method Summary collapse

Constructor Details

#initialize(origin = {}) ⇒ Opts

Returns a new instance of Opts.



39
40
41
# File 'lib/lazylead/opts.rb', line 39

def initialize(origin = {})
  @origin = origin
end

Instance Method Details

#blank?(key) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/lazylead/opts.rb', line 48

def blank?(key)
  to_h[key].nil? || @origin[key].blank?
end

#decrypt(key, sid) ⇒ Object

Decrypt particular option using cryptography salt

Parameters:

  • key

    option to be decrypted

  • sid

    the name of the salt to be used for the description

See Also:



73
74
75
76
77
78
# File 'lib/lazylead/opts.rb', line 73

def decrypt(key, sid)
  text = to_h[key]
  return text if text.blank? || text.nil?
  return Salt.new(sid).decrypt(text) if ENV.key? sid
  text
end

#jira_defaultsObject

Default Jira options to use during search for all Jira-based tasks.



57
58
59
60
61
62
# File 'lib/lazylead/opts.rb', line 57

def jira_defaults
  {
    max_results: fetch("max_results", 50),
    fields: jira_fields
  }
end

#jira_fieldsObject

Default fields which to fetch within the Jira issue



65
66
67
# File 'lib/lazylead/opts.rb', line 65

def jira_fields
  to_h.fetch("fields", "").split(",").map(&:to_sym)
end

#slice(key, delim) ⇒ Object

Split text value by delimiter, trim all spaces and reject blank items



44
45
46
# File 'lib/lazylead/opts.rb', line 44

def slice(key, delim)
  to_h[key].split(delim).map(&:chomp).map(&:strip).reject(&:blank?)
end

#to_hObject



52
53
54
# File 'lib/lazylead/opts.rb', line 52

def to_h
  @origin
end