Sha256: 45eaf1f1b39c4c4df68851a6388f86235f64e380cd45a2674365bac18e828d23

Contents?: true

Size: 680 Bytes

Versions: 13

Compression:

Stored size: 680 Bytes

Contents

# frozen_string_literal: true

module Milestoner
  module Syndication
    # Provides shared functionality for refinements.
    module Shared
      def merge(**attributes) = attributes.each { |key, value| public_send :"#{key}=", value }

      def build_for(collection, **)
        collection.each { |attributes| build(**attributes.transform_keys(**)) }
      end

      def build(**attributes)
        node = public_send :"new_#{kind}"
        attributes.each { |key, value| node.public_send :"#{key}=", value }
      end

      private

      def kind
        self.class.name.downcase.split("::").last.sub("categories", "category").delete_suffix("s")
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
milestoner-18.11.0 lib/milestoner/syndication/shared.rb
milestoner-18.10.0 lib/milestoner/syndication/shared.rb
milestoner-18.9.0 lib/milestoner/syndication/shared.rb
milestoner-18.8.0 lib/milestoner/syndication/shared.rb
milestoner-18.7.0 lib/milestoner/syndication/shared.rb
milestoner-18.6.0 lib/milestoner/syndication/shared.rb
milestoner-18.5.0 lib/milestoner/syndication/shared.rb
milestoner-18.4.0 lib/milestoner/syndication/shared.rb
milestoner-18.3.0 lib/milestoner/syndication/shared.rb
milestoner-18.2.0 lib/milestoner/syndication/shared.rb
milestoner-18.1.0 lib/milestoner/syndication/shared.rb
milestoner-18.0.1 lib/milestoner/syndication/shared.rb
milestoner-18.0.0 lib/milestoner/syndication/shared.rb