Sha256: 747eae8cbbc9222a1fb1ec50195584d1019ad01693f7af400e44705e2297c5f2

Contents?: true

Size: 822 Bytes

Versions: 9

Compression:

Stored size: 822 Bytes

Contents

module SslSupport

  def self.included(base)
    base.class.send(:attr_accessor, :use_ssl)
    base.send(:include, InstanceMethods)
    base.send(:extend, ClassMethods)
  end

  module InstanceMethods

  end

  module ClassMethods
    ##
    # Default use_ssl to ssl_recommend?
    # @return [Boolean]
    def use_ssl?
      @use_ssl ||= ssl_recommended?
    end

    # @return [String]
    def url_protocol_prefix
      (use_ssl?)? "https://" : "http://"
    end

    # Returns true if ssl is recommended according to environment.
    #
    # - production, staging -> true
    # - other -> false
    #
    # @return [Boolean]
    def ssl_recommended?
      ssl_recommended_environments = %W(production staging)
      ssl_recommended_environments.include?(defined?(Rails)? Rails.env : ENV['RACK_ENV'] )
    end
  end


end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
logical_model-0.4.10 lib/ssl_support.rb
logical_model-0.4.8 lib/ssl_support.rb
logical_model-0.4.7 lib/ssl_support.rb
logical_model-0.4.6 lib/ssl_support.rb
logical_model-0.4.5 lib/ssl_support.rb
logical_model-0.4.4 lib/ssl_support.rb
logical_model-0.4.3 lib/ssl_support.rb
logical_model-0.4.1 lib/ssl_support.rb
logical_model-0.4.0 lib/ssl_support.rb