Sha256: 8e671392a91c3547ccb23832939f206b763797a6d6fef1e7b52cf2b52a959792

Contents?: true

Size: 945 Bytes

Versions: 18

Compression:

Stored size: 945 Bytes

Contents

class Gratan::DSL::Context::User
  include Gratan::DSL::Validator
  include Gratan::Logger::Helper

  attr_reader :result

  def initialize(user, host, options, &block)
    @object_identifier = "User `#{user}@#{host}`"
    @user = user
    @host = host
    @options = options
    @result = {}
    instance_eval(&block)
  end

  def on(name, options = {}, &block)
    name = name.kind_of?(Regexp) ? name : name.to_s

    __validate("Object `#{name}` is already defined") do
      not @result.has_key?(name)
    end

    if @options[:enable_expired] and (expired = options.delete(:expired))
      expired = Time.parse(expired)

      if Time.new >= expired
        log(:warn, "Object `#{name}` has expired", :color => :yellow)
        return
      end
    end

    grant = {:privs => Gratan::DSL::Context::On.new(@user, @host, name, @options, &block).result}
    grant[:with] = options[:with] if options[:with]
    @result[name] = grant
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
gratan-0.2.9 lib/gratan/dsl/context/user.rb
gratan-0.2.9.beta3 lib/gratan/dsl/context/user.rb
gratan-0.2.9.beta2 lib/gratan/dsl/context/user.rb
gratan-0.2.9.beta lib/gratan/dsl/context/user.rb
gratan-0.2.8 lib/gratan/dsl/context/user.rb
gratan-0.2.8.beta3 lib/gratan/dsl/context/user.rb
gratan-0.2.8.beta2 lib/gratan/dsl/context/user.rb
gratan-0.2.8.beta lib/gratan/dsl/context/user.rb
gratan-0.2.7 lib/gratan/dsl/context/user.rb
gratan-0.2.6 lib/gratan/dsl/context/user.rb
gratan-0.2.5 lib/gratan/dsl/context/user.rb
gratan-0.2.4 lib/gratan/dsl/context/user.rb
gratan-0.2.3 lib/gratan/dsl/context/user.rb
gratan-0.2.2 lib/gratan/dsl/context/user.rb
gratan-0.2.1 lib/gratan/dsl/context/user.rb
gratan-0.2.0 lib/gratan/dsl/context/user.rb
gratan-0.1.9 lib/gratan/dsl/context/user.rb
gratan-0.1.8 lib/gratan/dsl/context/user.rb