Sha256: 6bd82339e22fd75ccaedfc19bdf2e0946b6fabfe91782d5afbc4744faab32fc0

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

require 'rack'

module Helios
  class Backend < Rack::Cascade
    def initialize(&block)
      @services = []

      block = lambda { |app|
        service :data, model: Dir['**/*.xcdatamodeld'].first
        service :push_notification
        service :in_app_purchase
        service :passbook
      } unless block_given?

      instance_eval(&block)
    
      super(@services)
    end

    private

    def service(identifier, options = {}, &block)
      middleware = case identifier
                   when :data
                    Helios::Backend::Data.new(options[:model]) if options[:model]
                   when :push_notification
                    Helios::Backend::PushNotification.new
                   when :in_app_purchase
                    Helios::Backend::InAppPurchase.new
                   when :passbook
                    Helios::Backend::Passbook.new
                   else
                    raise ArgumentError, "Unknown service #{identifer}"
                   end

      # middleware.set :frontend, options.fetch(:frontend, true)

      @services << middleware if middleware
    end
  end
end

require 'helios/backend/data'
require 'helios/backend/push-notification'
require 'helios/backend/in-app-purchase'
require 'helios/backend/passbook'

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
helios-0.0.5 ./lib/helios/backend.rb
helios-0.0.4 ./lib/helios/backend.rb
helios-0.0.3 ./lib/helios/backend.rb
helios-0.0.2 ./lib/helios/backend.rb