Class: Redata::Relation
- Inherits:
-
Object
- Object
- Redata::Relation
- Defined in:
- lib/redata/relation.rb
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#file ⇒ Object
Returns the value of attribute file.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #global_key ⇒ Object
-
#initialize(category, name, setting) ⇒ Relation
constructor
A new instance of Relation.
- #query_file ⇒ Object
- #source_name ⇒ Object
- #tmp_exec_file ⇒ Object
- #tmp_file_dir ⇒ Object
- #tmp_mkdir ⇒ Object
- #tmp_rmdir ⇒ Object
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
#category ⇒ Object
Returns the value of attribute category.
3 4 5 |
# File 'lib/redata/relation.rb', line 3 def category @category end |
#dir ⇒ Object
Returns the value of attribute dir.
3 4 5 |
# File 'lib/redata/relation.rb', line 3 def dir @dir end |
#file ⇒ Object
Returns the value of attribute file.
3 4 5 |
# File 'lib/redata/relation.rb', line 3 def file @file end |
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/redata/relation.rb', line 3 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/redata/relation.rb', line 3 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/redata/relation.rb', line 3 def type @type end |
Instance Method Details
#global_key ⇒ Object
12 13 14 |
# File 'lib/redata/relation.rb', line 12 def global_key @category == :main ? @key : "#{@category}_#{@key}".to_sym end |
#query_file ⇒ Object
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_name ⇒ Object
16 17 18 |
# File 'lib/redata/relation.rb', line 16 def source_name @category == :main ? @name : "#{@category}_#{@name}" end |
#tmp_exec_file ⇒ Object
31 32 33 |
# File 'lib/redata/relation.rb', line 31 def tmp_exec_file self.tmp_file_dir.join "exec.sql" end |
#tmp_file_dir ⇒ Object
27 28 29 |
# File 'lib/redata/relation.rb', line 27 def tmp_file_dir RED.root.join 'tmp', "#{@category}_#{@name}" end |
#tmp_mkdir ⇒ Object
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_rmdir ⇒ Object
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 |