Module: RogIQ::Helpers
- Defined in:
- lib/rogiq/helpers.rb
Constant Summary collapse
- UUID_RE =
/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i
Class Method Summary collapse
- .fmt_from_options(options) ⇒ Object
- .resolve_account(identifier) ⇒ Object
- .resolve_client(identifier) ⇒ Object
- .uuid?(value) ⇒ Boolean
- .with_saved_argv(new_argv) ⇒ Object
Class Method Details
.fmt_from_options(options) ⇒ Object
41 42 43 |
# File 'lib/rogiq/helpers.rb', line 41 def () RogIQ::Formatters.new(format: [:format] || ["format"], quiet: [:quiet] || ["quiet"]) end |
.resolve_account(identifier) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rogiq/helpers.rb', line 27 def resolve_account(identifier) RogIQ.load_rails! s = identifier.to_s.strip return nil if s.blank? if uuid?(s) ::Account.find_by(id: s) else ::Account.find_by("LOWER(slug) = ?", s.downcase) || ::Account.find_by("LOWER(name) = ?", s.downcase) || ::Account.find_by(id: s) end end |
.resolve_client(identifier) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rogiq/helpers.rb', line 13 def resolve_client(identifier) RogIQ.load_rails! s = identifier.to_s.strip return nil if s.blank? if uuid?(s) ::Client.find_by(id: s) else ::Client.find_by("LOWER(name) = ?", s.downcase) || ::Client.joins(:account).find_by("LOWER(accounts.slug) = ?", s.downcase) || ::Client.find_by(id: s) end end |
.uuid?(value) ⇒ Boolean
9 10 11 |
# File 'lib/rogiq/helpers.rb', line 9 def uuid?(value) value.to_s.match?(UUID_RE) end |
.with_saved_argv(new_argv) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/rogiq/helpers.rb', line 45 def with_saved_argv(new_argv) old = ARGV.dup ARGV.replace(new_argv) yield ensure ARGV.replace(old) end |