Module: OasCore::Spec::Hashable
- Included in:
- Parameter, RequestBody, Response
- Defined in:
- lib/oas_core/spec/hashable.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.generate_hash(obj) ⇒ Object
16 17 18 |
# File 'lib/oas_core/spec/hashable.rb', line 16 def self.generate_hash(obj) Digest::MD5.hexdigest(hash_representation_recursive(obj).to_s) end |
.hash_representation_recursive(obj) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/oas_core/spec/hashable.rb', line 27 def self.hash_representation_recursive(obj) case obj when Hash obj.transform_values { |v| hash_representation_recursive(v) } when Array obj.map { |v| hash_representation_recursive(v) } when Hashable obj.hash_representation else obj end end |
Instance Method Details
#hash_key ⇒ Object
8 9 10 |
# File 'lib/oas_core/spec/hashable.rb', line 8 def hash_key Hashable.generate_hash(hash_representation) end |
#hash_representation ⇒ Object
12 13 14 |
# File 'lib/oas_core/spec/hashable.rb', line 12 def hash_representation public_instance_variables.sort.to_h { |var| [var, instance_variable_get(var)] } end |
#public_instance_variables ⇒ Object
20 21 22 23 24 25 |
# File 'lib/oas_core/spec/hashable.rb', line 20 def public_instance_variables instance_variables.select do |var| method_name = var.to_s.delete('@') respond_to?(method_name) || respond_to?("#{method_name}=") end end |