Sha256: ccc9950285b0c94ea05e7c78d2383b4ad26fa4cfde982b7574b2c53268071145

Contents?: true

Size: 1.06 KB

Versions: 8

Compression:

Stored size: 1.06 KB

Contents

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

  attr_reader :result

  def initialize(context, user, host, options, &block)
    @object_identifier = "User `#{user}@#{host}`"
    @user = user
    @host = host
    @options = options
    @context = context.merge(:user => user, :host => host, :user_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(@context, @user, @host, name, @options, &block).result}
    grant[:with] = options[:with] if options[:with]
    @result[name] = grant
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gratan-0.3.2 lib/gratan/dsl/context/user.rb
gratan-0.3.1 lib/gratan/dsl/context/user.rb
gratan-0.3.1.beta4 lib/gratan/dsl/context/user.rb
gratan-0.3.1.beta3 lib/gratan/dsl/context/user.rb
gratan-0.3.1.beta2 lib/gratan/dsl/context/user.rb
gratan-0.3.1.beta lib/gratan/dsl/context/user.rb
gratan-0.3.0 lib/gratan/dsl/context/user.rb
gratan-0.3.0.beta lib/gratan/dsl/context/user.rb