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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validator

#__identify, #__validate

Constructor Details

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

Returns a new instance of User.



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

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

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'lib/gratan/dsl/context/user.rb', line 4

def result
  @result
end

Instance Method Details

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



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gratan/dsl/context/user.rb', line 14

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

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