Module: ROM::LDAP::Functions Private

Extended by:
Dry::Transformer::Registry
Defined in:
lib/rom/ldap/functions.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.identify_value(val) ⇒ Mixed

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

Finish documentation

Map from

Examples:

id_value(true) => 'TRUE'
id_value('TRUE') => true
id_value('peter hamilton') => 'peter hamilton'

Parameters:

  • val (Symbol, String)

Returns:

  • (Mixed)


56
57
58
59
60
61
62
63
# File 'lib/rom/ldap/functions.rb', line 56

def self.identify_value(val)
  case val
  when ::Symbol, ::TrueClass, ::FalseClass, ::NilClass
    VALUES_MAP.fetch(val, val)
  else
    VALUES_MAP.invert.fetch(val, val)
  end
end

.map_to_base64(values) ⇒ Array<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<String>)


160
161
162
# File 'lib/rom/ldap/functions.rb', line 160

def self.map_to_base64(values)
  t(:map_array, t(:to_base64)).call(values)
end

.map_to_booleans(values) ⇒ Array<TrueClass, FalseClass>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<TrueClass, FalseClass>)


178
179
180
# File 'lib/rom/ldap/functions.rb', line 178

def self.map_to_booleans(values)
  t(:map_array, t(:to_boolean)).call(values)
end

.map_to_integers(tuples) ⇒ Array<Integer>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<Integer>)


166
167
168
# File 'lib/rom/ldap/functions.rb', line 166

def self.map_to_integers(tuples)
  t(:map_array, t(:to_integer)).call(tuples)
end

.map_to_symbols(tuples) ⇒ Array<Symbol>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<Symbol>)


172
173
174
# File 'lib/rom/ldap/functions.rb', line 172

def self.map_to_symbols(tuples)
  t(:map_array, t(:to_symbol)).call(tuples)
end

.map_to_times(values) ⇒ Array<Time>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<Time>)


184
185
186
# File 'lib/rom/ldap/functions.rb', line 184

def self.map_to_times(values)
  t(:map_array, t(:to_time)).call(values)
end

.mime_type(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compare Magic Bytes



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/rom/ldap/functions.rb', line 91

def self.mime_type(value)
  mime =
    case value[0, 2]
    when "\xFF\xD8".b
      'image/jpeg'
    when "\x89P".b
      'image/png'
    when 'BM'
      'image/bitmap'
    when 'II', 'MM'
      'image/tiff'
    when "\xFF\xFBID".b
      'audio/mpeg'
    when 'WA'
      'audio/x-wav'
    else
      'application/octet-stream'
    end
  to_base64(value).prepend("data:#{mime};base64,")
end

.reject_blank(tuple) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

remove keys with blank values nil values allow attribute to be deleted



38
39
40
# File 'lib/rom/ldap/functions.rb', line 38

def self.reject_blank(tuple)
  tuple.reject { |_k, v| v&.empty? }
end

.stringify(value) ⇒ String, NilClass

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Ensure tuple values are strings or nil

Parameters:

  • value (Mixed)

Returns:

  • (String, NilClass)


72
73
74
75
76
77
78
79
80
81
# File 'lib/rom/ldap/functions.rb', line 72

def self.stringify(value)
  case value
  when ::Numeric    then value.to_s
  when ::Enumerable then value.map(&:to_s)
  when ::Hash       then value.to_json
  when ::String     then value
  else
    value
  end
end

.to_base64(value, strict: true) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Base64 encoded string, with optional new line characters.

Returns:

  • (String)


116
117
118
119
120
121
122
123
# File 'lib/rom/ldap/functions.rb', line 116

def self.to_base64(value, strict: true)
  if strict
    Base64.strict_encode64(value).chomp
  else
    # [value].pack('m').chomp
    Base64.encode64(value).chomp
  end
end

.to_boolean(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


129
130
131
# File 'lib/rom/ldap/functions.rb', line 129

def self.to_boolean(value)
  Dry::Transformer::Coercions::BOOLEAN_MAP.fetch(value.to_s.downcase)
end

.to_method_name(value) ⇒ Object

Function applied to Directory::Entry to format incoming attribute names.



201
202
203
204
# File 'lib/rom/ldap/functions.rb', line 201

def self.to_method_name(value)
  fn = t(:to_string) >> t(:to_underscore) >> t(:to_symbol)
  fn.call(value)
end

.to_time(value) ⇒ Time

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The 18-digit Active Directory timestamps, also named ‘Windows NT time format’,‘Win32 FILETIME or SYSTEMTIME’ or ‘NTFS file time’.

These are used in Microsoft Active Directory for pwdLastSet, accountExpires, LastLogon, LastLogonTimestamp and LastPwdSet.

The number of 100-nanoseconds intervals since 12:00 A.M. January 1st, 1601 (UTC). NB:

1 nanosecond = a billionth of a second
Accurate to the nearest millisecond (7 digits)

Parameters:

  • value (String)

    time or integer

Returns:

  • (Time)

    UTC formatted

See Also:



151
152
153
154
155
156
# File 'lib/rom/ldap/functions.rb', line 151

def self.to_time(value)
  unix_epoch_time = (Integer(value) / TEN_MILLION) - SINCE_1601
  ::Time.at(unix_epoch_time).utc
rescue ArgumentError
  ::Time.parse(value).utc
end

.to_underscore(value) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert string to snake case.

Parameters:

  • value (String)

Returns:

  • (String)


194
195
196
# File 'lib/rom/ldap/functions.rb', line 194

def self.to_underscore(value)
  Inflector.underscore(value.delete('= '))
end

.tuplify(tuple, matrix) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

Directory#add will receive a hash with key :dn

Build tuple from arguments.

Translates keys into original schema names and stringify values.

Parameters:

  • tuple (Hash)

    input arguments for directory #add and #modify

Returns:

  • (Hash)


27
28
29
30
31
32
33
# File 'lib/rom/ldap/functions.rb', line 27

def self.tuplify(tuple, matrix)
  fn = t(:rename_keys, matrix) >>
       t(:map_values, t(:identify_value)) >>
       t(:map_values, t(:stringify)) >> t(:reject_blank)

  fn.call(tuple)
end