Sha256: b55e0b99c629c1b36ccbeb4d33ff38e8127302456ea2d57c685c251d333d9ccb

Contents?: true

Size: 946 Bytes

Versions: 2

Compression:

Stored size: 946 Bytes

Contents

module Credentials
  module ClassMethods
    # Defines the set of credentials common to members of a class.
    def credentials(options = {}, &block)
      unless included_modules.include? Actor
        class_inheritable_reader :rulebook
        class_inheritable_reader :credential_options
        include Actor
      end
      write_inheritable_attribute :credential_options, merge_credential_options(read_inheritable_attribute(:credential_options), options)
      old_rulebook = read_inheritable_attribute(:rulebook)
      write_inheritable_attribute :rulebook, Rulebook.new(self, old_rulebook ? old_rulebook.rules : [])
      yield rulebook if block_given?
    end
    
  protected
    # Merges the set of options inherited from a parent class (if any)
    def merge_credential_options(a, b)
      a ||= {}
      b ||= {}
      a[:groups] = (Array(a[:groups]) + Array(b.delete(:groups))).uniq if b[:groups]
      a.merge(b)
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
fauxparse-credentials-1.0.1 lib/credentials/class_methods.rb
credentials-1.0.1 lib/credentials/class_methods.rb