Class: DbMeta::Oracle::Grant

Inherits:
Base
  • Object
show all
Defined in:
lib/db_meta/oracle/types/grant.rb

Constant Summary

Constants inherited from Base

Base::TYPES

Instance Attribute Summary collapse

Attributes inherited from Base

#extract_type, #name, #status, #system_object, #type

Instance Method Summary collapse

Methods inherited from Base

from_type, register_type, #system_object?

Methods included from Helper

#block, #create_folder, #pluralize, #remove_folder, #type_sequence, #write_buffer_to_file

Constructor Details

#initialize(args = {}) ⇒ Grant

Returns a new instance of Grant.



8
9
10
11
# File 'lib/db_meta/oracle/types/grant.rb', line 8

def initialize(args = {})
  super
  @extract_type = :merged
end

Instance Attribute Details

#grantableObject (readonly)

Returns the value of attribute grantable.



6
7
8
# File 'lib/db_meta/oracle/types/grant.rb', line 6

def grantable
  @grantable
end

#granteeObject (readonly)

Returns the value of attribute grantee.



6
7
8
# File 'lib/db_meta/oracle/types/grant.rb', line 6

def grantee
  @grantee
end

#grantorObject (readonly)

Returns the value of attribute grantor.



6
7
8
# File 'lib/db_meta/oracle/types/grant.rb', line 6

def grantor
  @grantor
end

#ownerObject (readonly)

Returns the value of attribute owner.



6
7
8
# File 'lib/db_meta/oracle/types/grant.rb', line 6

def owner
  @owner
end

#privilegeObject (readonly)

Returns the value of attribute privilege.



6
7
8
# File 'lib/db_meta/oracle/types/grant.rb', line 6

def privilege
  @privilege
end

#table_nameObject (readonly)

Returns the value of attribute table_name.



6
7
8
# File 'lib/db_meta/oracle/types/grant.rb', line 6

def table_name
  @table_name
end

Instance Method Details

#ddl_dropObject



29
30
31
32
33
34
35
# File 'lib/db_meta/oracle/types/grant.rb', line 29

def ddl_drop
  buffer = ""

  buffer << ("%-30s" % "-- granted via #{@grantor}: ") if external_grant?
  buffer << "REVOKE #{"%-18s" % @privilege} ON #{"%-32s" % @table_name} FROM #{@grantee};"
  buffer
end

#external_grant?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/db_meta/oracle/types/grant.rb', line 37

def external_grant?
  @external_grant
end

#extract(args = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/db_meta/oracle/types/grant.rb', line 20

def extract(args = {})
  buffer = ""
  buffer << ("%-30s" % "-- granted via #{@grantor}: ") if external_grant?
  buffer << "GRANT #{"%-18s" % @privilege} ON #{"%-32s" % @table_name} TO #{@grantee}"
  buffer << " WITH GRANT OPTION" if @grantable == "YES"
  buffer << ";"
  buffer
end

#fetch(args = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/db_meta/oracle/types/grant.rb', line 13

def fetch(args = {})
  connection_class = args[:connection_class] || Connection
  # definition is comma seperated in the name to prevent re-fetching table for every grant
  @grantee, @owner, @table_name, @grantor, @privilege, @grantable = @name.split(",")
  @external_grant = @grantor != connection_class.instance.username.upcase
end

#sort_valueObject



41
42
43
44
# File 'lib/db_meta/oracle/types/grant.rb', line 41

def sort_value
  return ["2", @grantor, @privilege, @table_name] if external_grant?
  ["1", @grantee, @privilege, @table_name]
end