lib/mangadex/internal/with_attributes.rb in mangadex-5.3.2 vs lib/mangadex/internal/with_attributes.rb in mangadex-5.3.3

- old
+ new

@@ -9,11 +9,12 @@ attr_accessor \ :id, :type, :attributes, - :relationships + :relationships, + :related_type class_methods do USING_ATTRIBUTES = {} def has_attributes(*attributes) @@ -28,11 +29,11 @@ def type self.name.split('::').last.underscore end - def from_data(data) + def from_data(data, related_type: nil) base_class_name = self.name.gsub('::', '_') klass_name = self.name target_attributes_class_name = "#{base_class_name}_Attributes" klass = if const_defined?(target_attributes_class_name) @@ -63,10 +64,11 @@ initialize_hash = { id: data['id'], type: data['type'] || self.type, attributes: attributes, + related_type: related_type, } initialize_hash.merge!({relationships: relationships}) if relationships.present? new(**initialize_hash) @@ -108,9 +110,16 @@ elsif is_looking_for_many [] else super end + elsif !related_type.nil? + return super unless method_name.end_with?("?") + + looking_for_related = method_name.to_s.split("?").first + return super unless Mangadex::Relationship::RELATED_VALUES.include?(looking_for_related) + + related_type == looking_for_related else super end end end