Class: Redata::Relation

Inherits:
Object
  • Object
show all
Defined in:
lib/redata/relation.rb

Direct Known Subclasses

Table, View

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(category, name, setting) ⇒ Relation

Returns a new instance of Relation.



4
5
6
7
8
9
10
# File 'lib/redata/relation.rb', line 4

def initialize(category, name, setting)
  @category = category
  @name = name
  @key = setting[:as] || @name.to_sym
  @file = setting[:file] || @name
  @dir = setting[:dir] || (@category == :main ? nil : @category.to_s)
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



3
4
5
# File 'lib/redata/relation.rb', line 3

def category
  @category
end

#dirObject

Returns the value of attribute dir.



3
4
5
# File 'lib/redata/relation.rb', line 3

def dir
  @dir
end

#fileObject

Returns the value of attribute file.



3
4
5
# File 'lib/redata/relation.rb', line 3

def file
  @file
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/redata/relation.rb', line 3

def key
  @key
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/redata/relation.rb', line 3

def name
  @name
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/redata/relation.rb', line 3

def type
  @type
end

Instance Method Details

#global_keyObject



12
13
14
# File 'lib/redata/relation.rb', line 12

def global_key
  @category == :main ? @key : "#{@category}_#{@key}".to_sym
end

#query_fileObject



20
21
22
23
24
25
# File 'lib/redata/relation.rb', line 20

def query_file
  query_file = RED.root.join 'query', 'sources'
  query_file = query_file.join @dir if @dir
  query_file = query_file.join "#{@file}.red.sql"
  query_file
end

#source_nameObject



16
17
18
# File 'lib/redata/relation.rb', line 16

def source_name
  @category == :main ? @name : "#{@category}_#{@name}"
end

#tmp_exec_fileObject



31
32
33
# File 'lib/redata/relation.rb', line 31

def tmp_exec_file
  self.tmp_file_dir.join "exec.sql"
end

#tmp_file_dirObject



27
28
29
# File 'lib/redata/relation.rb', line 27

def tmp_file_dir
  RED.root.join 'tmp', "#{@category}_#{@name}"
end

#tmp_mkdirObject



35
36
37
# File 'lib/redata/relation.rb', line 35

def tmp_mkdir
  Dir.mkdir self.tmp_file_dir unless self.tmp_file_dir.exist?
end

#tmp_rmdirObject



39
40
41
# File 'lib/redata/relation.rb', line 39

def tmp_rmdir
  FileUtils.rm_r self.tmp_file_dir if !RED.keep_tmp? && self.tmp_file_dir.exist?
end