./lib/helios/backend.rb in helios-0.0.5 vs ./lib/helios/backend.rb in helios-0.1.1

- old
+ new

@@ -18,29 +18,39 @@ 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 + if identifier.is_a?(Class) + middleware = identifier + else + begin + middleware = Helios::Backend.const_get(constantize(identifier)) + rescue NameError + raise LoadError, "Could not find matching service for #{identifier.inspect}. You may need to install an additional gem (such as helios-#{identifier})." + end + end - # middleware.set :frontend, options.fetch(:frontend, true) + middleware.instance_eval{ include Helios::Administerable } if options.fetch(:frontend, true) - @services << middleware if middleware + @services << middleware.new(self, options, &block) if middleware end + + def constantize(identifier) + identifier.to_s.split(/([[:alpha:]]*)/).select{|c| /[[:alpha:]]/ === c}.map(&:capitalize).join("") + end end + + module Administerable + attr_accessor :admin + + def admin? + !!@admin + end + end end +require 'helios/backend/accounts' require 'helios/backend/data' require 'helios/backend/push-notification' require 'helios/backend/in-app-purchase' -require 'helios/backend/passbook' \ No newline at end of file +require 'helios/backend/passbook'