Class: RailsDbViews::DatabaseSymbol
- Inherits:
-
Object
- Object
- RailsDbViews::DatabaseSymbol
- Defined in:
- lib/rails_db_views/database_symbol.rb
Defined Under Namespace
Modules: Status Classes: CircularReferenceError, SymbolNotFound
Instance Attribute Summary collapse
-
#inverse_of_required ⇒ Object
Returns the value of attribute inverse_of_required.
-
#marked_as_deleted ⇒ Object
(also: #marked_as_deleted?)
Returns the value of attribute marked_as_deleted.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#required ⇒ Object
Returns the value of attribute required.
-
#sql_content ⇒ Object
Returns the value of attribute sql_content.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #create! ⇒ Object
- #create_sql ⇒ Object
- #drop! ⇒ Object
-
#drop_sql ⇒ Object
Theses methods should be implemented in children objects.
- #handle_error_on_drop ⇒ Object
- #in_progress? ⇒ Boolean
-
#initialize(file_path) ⇒ DatabaseSymbol
constructor
A new instance of DatabaseSymbol.
- #loaded? ⇒ Boolean
- #mark_as_delete! ⇒ Object
- #process_inverse_of_required! ⇒ Object
- #unloaded? ⇒ Boolean
Constructor Details
#initialize(file_path) ⇒ DatabaseSymbol
Returns a new instance of DatabaseSymbol.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rails_db_views/database_symbol.rb', line 14 def initialize file_path @path = file_path @name = File.basename(file_path, ".*") @status = :none @required = [] @marked_as_deleted = false @sql_content = File.read(@path) @inverse_of_required = [] load_directives end |
Instance Attribute Details
#inverse_of_required ⇒ Object
Returns the value of attribute inverse_of_required.
5 6 7 |
# File 'lib/rails_db_views/database_symbol.rb', line 5 def inverse_of_required @inverse_of_required end |
#marked_as_deleted ⇒ Object Also known as: marked_as_deleted?
Returns the value of attribute marked_as_deleted.
5 6 7 |
# File 'lib/rails_db_views/database_symbol.rb', line 5 def marked_as_deleted @marked_as_deleted end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/rails_db_views/database_symbol.rb', line 5 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/rails_db_views/database_symbol.rb', line 5 def path @path end |
#required ⇒ Object
Returns the value of attribute required.
5 6 7 |
# File 'lib/rails_db_views/database_symbol.rb', line 5 def required @required end |
#sql_content ⇒ Object
Returns the value of attribute sql_content.
5 6 7 |
# File 'lib/rails_db_views/database_symbol.rb', line 5 def sql_content @sql_content end |
#status ⇒ Object
Returns the value of attribute status.
5 6 7 |
# File 'lib/rails_db_views/database_symbol.rb', line 5 def status @status end |
Instance Method Details
#create! ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rails_db_views/database_symbol.rb', line 51 def create! return if marked_as_deleted? || loaded? circular_reference_error if in_progress? self.status = Status::IN_PROGRESS required.each do |symbol_name| symbol = RailsDbViews::Factory.get(self.class, symbol_name) not_found_error(symbol_name) if symbol.nil? symbol.create! end ActiveRecord::Base.connection.execute(create_sql) self.status = Status::LOADED end |
#create_sql ⇒ Object
97 98 99 |
# File 'lib/rails_db_views/database_symbol.rb', line 97 def create_sql raise NotImplementedError, "DatabaseSymbol should not be instanciated" end |
#drop! ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rails_db_views/database_symbol.rb', line 69 def drop! return if loaded? circular_reference_error if in_progress? self.status = Status::IN_PROGRESS # We start by the required one to delete first. inverse_of_required.each do |symbol_name| symbol = RailsDbViews::Factory.get(self.class, symbol_name) not_found_error(symbol_name) if symbol.nil? symbol.drop! end begin ActiveRecord::Base.connection.execute(drop_sql) #rescue ActiveRecord::ActiveRecordError => e #Probably because the symbol doesn't exists yet. # handle_error_on_drop end self.status = Status::LOADED end |
#drop_sql ⇒ Object
Theses methods should be implemented in children objects.
93 94 95 |
# File 'lib/rails_db_views/database_symbol.rb', line 93 def drop_sql raise NotImplementedError, "DatabaseSymbol should not be instanciated" end |
#handle_error_on_drop ⇒ Object
101 102 103 |
# File 'lib/rails_db_views/database_symbol.rb', line 101 def handle_error_on_drop raise NotImplementedError, "DatabaseSymbol should not be instanciated" end |
#in_progress? ⇒ Boolean
43 44 45 |
# File 'lib/rails_db_views/database_symbol.rb', line 43 def in_progress? status == Status::IN_PROGRESS end |
#loaded? ⇒ Boolean
39 40 41 |
# File 'lib/rails_db_views/database_symbol.rb', line 39 def loaded? status == Status::LOADED end |
#mark_as_delete! ⇒ Object
35 36 37 |
# File 'lib/rails_db_views/database_symbol.rb', line 35 def mark_as_delete! @marked_as_deleted = true end |
#process_inverse_of_required! ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/rails_db_views/database_symbol.rb', line 27 def process_inverse_of_required! @required.each do |name| required = RailsDbViews::Factory.get(self.class, name) not_found_error if required.nil? required.inverse_of_required << self.name end end |