Sha256: 5d15787bf37c1685d566b17d7ee67c118a938f720de06c5481e234e8a29809b8

Contents?: true

Size: 1.23 KB

Versions: 4

Compression:

Stored size: 1.23 KB

Contents

class SiteHub
  class CandidateRoutes
    module ClassMethods
      extend CollectionMethods

      # TODO: support nested routes, i.e. support rule name being passed in
      def from_hash(hash, sitehub_cookie_name)
        new(sitehub_cookie_name: sitehub_cookie_name,
            sitehub_cookie_path: hash[:sitehub_cookie_path],
            mapped_path: hash[:path], calling_scope: self) do
          handle_routes(hash, self)
          default url: hash[:default] if hash[:default]
        end
      end

      private

      def handle_routes(hash, routes)
        extract_splits(hash, routes)
        extract_routes(hash, routes)
      end

      def extract_routes(hash, routes)
        collection(hash, :routes).each do |route|
          routes.route(url: route[:url], label: route[:label])
        end
      end

      def extract_splits(hash, routes)
        collection(hash, :splits).each do |split|
          if split[:splits] || split[:routes]
            routes.split(percentage: split[:percentage], label: split[:label]) do
              handle_routes(split, self)
            end
          else
            routes.split(percentage: split[:percentage], label: split[:label], url: split[:url])
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sitehub-0.5.0.alpha10 lib/sitehub/candidate_routes/class_methods.rb
sitehub-0.5.0.alpha8 lib/sitehub/candidate_routes/class_methods.rb
sitehub-0.5.0.alpha7 lib/sitehub/candidate_routes/class_methods.rb
sitehub-0.5.0.alpha6 lib/sitehub/candidate_routes/class_methods.rb