Class: Posgra::DSL::Grants::Role::Schema

Inherits:
Object
  • Object
show all
Includes:
Logger::Helper, TemplateHelper, Utils::Helper
Defined in:
lib/posgra/dsl/grants/role/schema.rb

Defined Under Namespace

Classes: On

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Helper

#matched?

Methods included from TemplateHelper

#context, #include_template

Methods included from Logger::Helper

#log

Constructor Details

#initialize(context, schema, options, &block) ⇒ Schema

Returns a new instance of Schema.



8
9
10
11
12
13
14
# File 'lib/posgra/dsl/grants/role/schema.rb', line 8

def initialize(context, schema, options, &block)
  @schema = schema
  @options = options
  @context = context.merge(:schema => schema)
  @result = {}
  instance_eval(&block)
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/posgra/dsl/grants/role/schema.rb', line 6

def result
  @result
end

Instance Method Details

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/posgra/dsl/grants/role/schema.rb', line 16

def on(name, options = {}, &block)
  unless name.is_a?(Regexp)
    name = name.to_s
    return unless matched?(name, @options[:include_object], @options[:exclude_object])
  end

  if options[:expired]
    expired = Time.parse(options[:expired])

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

  @result[name] = Posgra::DSL::Grants::Role::Schema::On.new(@context, name, @options, &block).result
end