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)


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

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:



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

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.



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

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

#jira_fieldsObject

Default fields which to fetch within the Jira issue



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

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
47
# File 'lib/lazylead/opts.rb', line 44

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

#to_hObject



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

def to_h
  @origin
end