Class: UniversalID::PrepackOptions
- Inherits:
-
Object
- Object
- UniversalID::PrepackOptions
- Defined in:
- lib/universalid/prepack_options.rb
Instance Attribute Summary collapse
-
#database_options ⇒ Object
readonly
Returns the value of attribute database_options.
-
#excludes ⇒ Object
readonly
Returns the value of attribute excludes.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
Instance Method Summary collapse
- #blank?(value) ⇒ Boolean
- #exclude_blank? ⇒ Boolean
- #include_blank? ⇒ Boolean
-
#initialize(options = {}) ⇒ PrepackOptions
constructor
A new instance of PrepackOptions.
- #keep_key?(key) ⇒ Boolean
- #keep_keypair?(key, value) ⇒ Boolean
- #keep_value?(value) ⇒ Boolean
- #present?(value) ⇒ Boolean
- #prevent_self_reference!(object) ⇒ Object
- #reject_key?(key) ⇒ Boolean
- #reject_keypair?(key, value) ⇒ Boolean
- #reject_value?(value) ⇒ Boolean
- #to_h ⇒ Object
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( = {}) ||= {} @settings = UniversalID::Settings.build(**).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_options ⇒ Object (readonly)
Returns the value of attribute database_options.
4 5 6 |
# File 'lib/universalid/prepack_options.rb', line 4 def @database_options end |
#excludes ⇒ Object (readonly)
Returns the value of attribute excludes.
4 5 6 |
# File 'lib/universalid/prepack_options.rb', line 4 def excludes @excludes end |
#includes ⇒ Object (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
57 58 59 |
# File 'lib/universalid/prepack_options.rb', line 57 def blank?(value) (value == false) ? false : value.blank? end |
#exclude_blank? ⇒ Boolean
28 29 30 |
# File 'lib/universalid/prepack_options.rb', line 28 def exclude_blank? !include_blank? end |
#include_blank? ⇒ Boolean
24 25 26 |
# File 'lib/universalid/prepack_options.rb', line 24 def include_blank? !!@settings.include_blank end |
#keep_key?(key) ⇒ 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
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
41 42 43 |
# File 'lib/universalid/prepack_options.rb', line 41 def keep_value?(value) include_blank? || present?(value) end |
#present?(value) ⇒ 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
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
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
45 46 47 |
# File 'lib/universalid/prepack_options.rb', line 45 def reject_value?(value) !keep_value?(value) end |
#to_h ⇒ Object
15 16 17 |
# File 'lib/universalid/prepack_options.rb', line 15 def to_h @settings.to_h end |