Module: Shared::IsData::Stripper

Defined in:
app/models/concerns/shared/is_data.rb

Class Method Summary (collapse)

Class Method Details

+ (Array) add_class_list(list)

Returns of strings to be ignored

Parameters:

  • list (Array)

    of symbols to be ignored

Returns:

  • (Array)

    of strings to be ignored



172
173
174
175
176
177
178
# File 'app/models/concerns/shared/is_data.rb', line 172

def self.add_class_list(list)
  ig_list  = RESERVED_ATTRIBUTES.dup
  add_list = list.dup if list.any?
  ig_list  += add_list if add_list
  # convert ignore list from symbols to strings for subsequent include test
  return ig_list.map(&:to_s)
end

+ (Hash) strip_identical_attributes(klass, attr = {})

Parameters:

  • attr (Hash) (defaults to: {})

    is hash

Returns:

  • (Hash)


160
161
162
163
164
165
166
167
168
# File 'app/models/concerns/shared/is_data.rb', line 160

def self.strip_identical_attributes(klass, attr = {})
  begin # test to see if this class has an IGNORE_IDENTICAL constant
    ig = add_class_list(klass::IGNORE_IDENTICAL)
  rescue NameError
    ig = RESERVED_ATTRIBUTES.dup.map(&:to_s)
  end
  attr.delete_if{ |kee, _value| ig.include?(kee) }
  attr
end

+ (Hash) strip_similar_attributes(klass, attr = {})

Parameters:

  • attr (Hash) (defaults to: {})

    is hash

Returns:

  • (Hash)


148
149
150
151
152
153
154
155
156
# File 'app/models/concerns/shared/is_data.rb', line 148

def self.strip_similar_attributes(klass, attr = {})
  begin # test to see if this class has an IGNORE_SIMILAR constant
    ig = add_class_list(klass::IGNORE_SIMILAR)
  rescue NameError
    ig = RESERVED_ATTRIBUTES.dup.map(&:to_s)
  end
  attr.delete_if{|kee, _value| ig.include?(kee) }
  attr
end

+ (Array) tested_attributes(klass, compare = :identical)

Returns of symbols which represent the attributes which will be tested for a given class

Parameters:

  • klass (Class)
  • compare (Symbol, String) (defaults to: :identical)
    • one of [:identical, :similar] (optional, defaults to :identical)

Returns:

  • (Array)

    of symbols which represent the attributes which will be tested for a given class



183
184
185
186
187
188
189
190
191
192
193
194
# File 'app/models/concerns/shared/is_data.rb', line 183

def self.tested_attributes(klass, compare = :identical)
  case compare.to_s
    when 'similar'
      obj = klass.new
      obj.attributes.each_key { |kee| obj[kee] = 1 }
      strip_similar_attributes(klass, obj.attributes).collect { |kee, _val| kee.to_sym }
    # when 'identical'
    #   strip_identical_attributes(klass, klass.new.attributes).collect { |kee, _val| kee.to_sym }
    else
      strip_identical_attributes(klass, klass.new.attributes).collect { |kee, _val| kee.to_sym }
  end
end