Module: ModeratorHelper

Defined in:
/var/apps/qpixel/app/helpers/moderator_helper.rb

Overview

Provides helper methods for use by views under ModeratorController.

Instance Method Summary collapse

Instance Method Details

#split_hash_ip(ip, salting_user) ⇒ [String, [String?]]

Split an IP address into an array of hashed octets (well, hexadecets for IPv6). must use the same user for each IP address you wish to compare, even if sourced from a different user.

Parameters:

  • ip (String)

    The IP address to process.

  • salting_user (User)

    A user from which to source a salt for hashing. For hashes to be directly comparable, you

Returns:

  • ([String, [String?]])

    The IP address family, and an array of hashed octets.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File '/var/apps/qpixel/app/helpers/moderator_helper.rb', line 26

def split_hash_ip(ip, salting_user)
  begin
    addr = IPAddress.parse(ip)
  rescue ArgumentError
    return ['', []]
  end
  splat = if addr.ipv6?
            addr.hexs
          else
            addr.octets
          end
  salt = BCrypt::Password.new(salting_user.encrypted_password).salt
  splat = splat.map { |p| Digest::SHA2.hexdigest(salt + p.to_s) }
  [
    addr.ipv6? ? 'IPv6' : 'IPv4',
    splat
  ]
end

#text_bg(cls, content = nil, **opts) {|context| ... } ⇒ ActiveSupport::SafeBuffer

Display text on a specified background color. For instance, if the background color is dark, consider passing a class for a light text color.

Parameters:

  • cls (String)

    The background color class.

  • content (String) (defaults to: nil)

    The text to display. For uses beyond simple text, pass a block instead.

  • opts (Hash)

    a customizable set of options

Options Hash (**opts):

  • :class (String)

    Additional classes to add to the element.

Yield Parameters:

  • context (ActionView::Helpers::TagHelper::TagBuilder)

Yield Returns:

  • (ActiveSupport::SafeBuffer, String)

Returns:

  • (ActiveSupport::SafeBuffer)


12
13
14
15
16
17
18
# File '/var/apps/qpixel/app/helpers/moderator_helper.rb', line 12

def text_bg(cls, content = nil, **opts, &block)
  if block_given?
    tag.span class: ["has-background-color-#{cls}", opts[:class]].join(' '), &block
  else
    tag.span content, class: ["has-background-color-#{cls}", opts[:class]].join(' ')
  end
end