Class: Gratan::DSL::Context::User

Inherits:
Object
  • Object
show all
Includes:
Validator, Logger::Helper, TemplateHelper
Defined in:
lib/gratan/dsl/context/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TemplateHelper

#context, #include_template

Methods included from Logger::Helper

#log

Methods included from Validator

#__identify, #__validate

Constructor Details

#initialize(context, user, host, options, &block) ⇒ User

Returns a new instance of User.



8
9
10
11
12
13
14
15
16
# File 'lib/gratan/dsl/context/user.rb', line 8

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

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/gratan/dsl/context/user.rb', line 6

def result
  @result
end

Instance Method Details

#on(name, options = {}, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gratan/dsl/context/user.rb', line 18

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