Sha256: cb700bba3a372256b533aa7544e2a1ee22ddb664e1b1d0a0d34ab31c7b0f0d28

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

module AuthStrategist
  module StrategyInterface
    def self.included(base)
      base.class_eval do
        class << self
          def define_components(*defined_components)
            defined_components.delete_if { |c| default_components.include?(c) }
            defined_components.uniq!
            attr_accessor(*defined_components)
            @components = defined_components
          end

          def components
            [*default_components, *@components]
          end

          def default_components
            AuthStrategist.configuration.default_strategy_components.uniq
          end
        end

        attr_accessor(*components)

        def initialize(attributes = {})
          assign_component_values(attributes)
        end

        def components
          self.class.components
        end

        def authorize!
          warn("#{self.class}#authorize! was not implemented.")
        end

        private

        def assign_component_values(attributes = {})
          components.each do |c|
            instance_variable_set("@#{c}", attributes[c])
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
auth_strategist-0.5.0 lib/auth_strategist/strategy_interface.rb