Class: UniversalID::PrepackOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/universalid/prepack_options.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PrepackOptions

Returns a new instance of PrepackOptions.



6
7
8
9
10
11
12
13
# File 'lib/universalid/prepack_options.rb', line 6

def initialize(options = {})
  options ||= {}
  @settings = UniversalID::Settings.build(**options).prepack
  @database_options = UniversalID::PrepackDatabaseOptions.new(@settings.database)
  @references = Set.new
  @excludes ||= @settings.exclude.to_h { |key| [key.to_s, true] }
  @includes ||= @settings.include.to_h { |key| [key.to_s, true] }
end

Instance Attribute Details

#database_optionsObject (readonly)

Returns the value of attribute database_options.



4
5
6
# File 'lib/universalid/prepack_options.rb', line 4

def database_options
  @database_options
end

#excludesObject (readonly)

Returns the value of attribute excludes.



4
5
6
# File 'lib/universalid/prepack_options.rb', line 4

def excludes
  @excludes
end

#includesObject (readonly)

Returns the value of attribute includes.



4
5
6
# File 'lib/universalid/prepack_options.rb', line 4

def includes
  @includes
end

Instance Method Details

#blank?(value) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/universalid/prepack_options.rb', line 57

def blank?(value)
  (value == false) ? false : value.blank?
end

#exclude_blank?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/universalid/prepack_options.rb', line 28

def exclude_blank?
  !include_blank?
end

#include_blank?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/universalid/prepack_options.rb', line 24

def include_blank?
  !!@settings.include_blank
end

#keep_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/universalid/prepack_options.rb', line 32

def keep_key?(key)
  return false if excludes[key.to_s]
  includes.none? || includes[key.to_s]
end

#keep_keypair?(key, value) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/universalid/prepack_options.rb', line 49

def keep_keypair?(key, value)
  keep_key?(key) && keep_value?(value)
end

#keep_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/universalid/prepack_options.rb', line 41

def keep_value?(value)
  include_blank? || present?(value)
end

#present?(value) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/universalid/prepack_options.rb', line 61

def present?(value)
  !blank?(value)
end

#prevent_self_reference!(object) ⇒ Object



19
20
21
22
# File 'lib/universalid/prepack_options.rb', line 19

def prevent_self_reference!(object)
  raise UniversalID::Prepacker::CircularReferenceError if @references.include?(object.object_id)
  @references << object.object_id
end

#reject_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/universalid/prepack_options.rb', line 37

def reject_key?(key)
  !!excludes[key.to_s]
end

#reject_keypair?(key, value) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/universalid/prepack_options.rb', line 53

def reject_keypair?(key, value)
  reject_key?(key) || reject_value?(value)
end

#reject_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/universalid/prepack_options.rb', line 45

def reject_value?(value)
  !keep_value?(value)
end

#to_hObject



15
16
17
# File 'lib/universalid/prepack_options.rb', line 15

def to_h
  @settings.to_h
end