Class: Prodder::Project
- Inherits:
-
Object
- Object
- Prodder::Project
- Defined in:
- lib/prodder/project.rb
Constant Summary collapse
- SeedConfigFileMissing =
Class.new(StandardError) do attr_reader :filename def initialize(filename); @filename = filename; end end
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
Instance Method Summary collapse
- #commit ⇒ Object
- #db_credentials ⇒ Object
- #dump ⇒ Object
- #dump_permissions? ⇒ Boolean
- #excluded_schemas ⇒ Object
- #excluded_tables ⇒ Object
- #git_origin ⇒ Object
- #included_users ⇒ Object
- #init ⇒ Object
-
#initialize(name, workspace, definition) ⇒ Project
constructor
A new instance of Project.
- #local_git_path ⇒ Object
- #nothing_to_push? ⇒ Boolean
- #permissions ⇒ Object
- #permissions_file_name ⇒ Object
- #push ⇒ Object
- #quality_check_file_name ⇒ Object
- #seed_file_name ⇒ Object
- #seed_tables ⇒ Object
- #separate_quality_checks? ⇒ Boolean
- #settings_file_name ⇒ Object
- #structure_file_name ⇒ Object
Constructor Details
#initialize(name, workspace, definition) ⇒ Project
Returns a new instance of Project.
19 20 21 22 23 |
# File 'lib/prodder/project.rb', line 19 def initialize(name, workspace, definition) @name = name @workspace = workspace @defn = definition end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/prodder/project.rb', line 17 def name @name end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
17 18 19 |
# File 'lib/prodder/project.rb', line 17 def workspace @workspace end |
Instance Method Details
#commit ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/prodder/project.rb', line 62 def commit return unless git.dirty? git.add structure_file_name git.add seed_file_name git.add quality_check_file_name if separate_quality_checks? git.add if git.add settings_file_name git.commit "Auto-commit by prodder", @defn['git']['author'] end |
#db_credentials ⇒ Object
85 86 87 |
# File 'lib/prodder/project.rb', line 85 def db_credentials @defn['db'] end |
#dump ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/prodder/project.rb', line 29 def dump FileUtils.mkdir_p File.dirname(structure_file_name) pg.dump_structure db_credentials['name'], structure_file_name, exclude_tables: excluded_tables, exclude_schemas: excluded_schemas FileUtils.mkdir_p File.dirname(settings_file_name) pg.dump_settings db_credentials['name'], settings_file_name FileUtils.mkdir_p File.dirname(seed_file_name) pg.dump_tables db_credentials['name'], seed_tables, seed_file_name # must split the structure file to allow data to be loaded after tables # being created but before triggers and foreign keys are created. this # facilitates validation during loading, yet avoids extra overhead and # false errors if separate_quality_checks? contents = File.readlines(structure_file_name) rgx = /^\-\- .* Type: INDEX; |^\-\- .* Type: TRIGGER; |^\-\- .* Type: FK CONSTRAINT; / structure, *quality = contents.slice_before(rgx).to_a quality_checks = structure.grep(/SET search_path/).last + quality.join File.open(quality_check_file_name, 'w') { |f| f.write(quality_checks) } File.open(structure_file_name, 'w') { |f| f.write(structure.join) } end if FileUtils.mkdir_p File.dirname() pg. db_credentials['name'], , included_users: included_users, exclude_tables: excluded_tables, exclude_schemas: excluded_schemas end end |
#dump_permissions? ⇒ Boolean
125 126 127 |
# File 'lib/prodder/project.rb', line 125 def @defn.key?('permissions') && .key?('file') end |
#excluded_schemas ⇒ Object
129 130 131 |
# File 'lib/prodder/project.rb', line 129 def excluded_schemas db_credentials['exclude_schemas'] || [] end |
#excluded_tables ⇒ Object
133 134 135 |
# File 'lib/prodder/project.rb', line 133 def excluded_tables db_credentials['exclude_tables'] || [] end |
#git_origin ⇒ Object
97 98 99 |
# File 'lib/prodder/project.rb', line 97 def git_origin @defn['git']['origin'] end |
#included_users ⇒ Object
137 138 139 |
# File 'lib/prodder/project.rb', line 137 def included_users ['included_users'] || [] end |
#init ⇒ Object
25 26 27 |
# File 'lib/prodder/project.rb', line 25 def init git.clone_or_remote_update end |
#local_git_path ⇒ Object
93 94 95 |
# File 'lib/prodder/project.rb', line 93 def local_git_path workspace end |
#nothing_to_push? ⇒ Boolean
80 81 82 83 |
# File 'lib/prodder/project.rb', line 80 def nothing_to_push? git.remote_update git.no_new_commits? end |
#permissions ⇒ Object
89 90 91 |
# File 'lib/prodder/project.rb', line 89 def @defn['permissions'] end |
#permissions_file_name ⇒ Object
117 118 119 |
# File 'lib/prodder/project.rb', line 117 def File.join workspace, ['file'] end |
#push ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/prodder/project.rb', line 72 def push if git.fast_forward? git.push else raise Prodder::Git::NotFastForward.new(git_origin) end end |
#quality_check_file_name ⇒ Object
113 114 115 |
# File 'lib/prodder/project.rb', line 113 def quality_check_file_name File.join workspace, @defn['quality_check_file'] end |
#seed_file_name ⇒ Object
109 110 111 |
# File 'lib/prodder/project.rb', line 109 def seed_file_name File.join workspace, @defn['seed_file'] end |
#seed_tables ⇒ Object
141 142 143 144 145 146 147 148 |
# File 'lib/prodder/project.rb', line 141 def seed_tables value = db_credentials['tables'] return value unless value.is_a?(String) path = File.join(workspace, value) raise SeedConfigFileMissing.new(File.join(name, value)) unless File.exist?(path) YAML.load IO.read(path) end |
#separate_quality_checks? ⇒ Boolean
121 122 123 |
# File 'lib/prodder/project.rb', line 121 def separate_quality_checks? @defn.key? 'quality_check_file' end |
#settings_file_name ⇒ Object
105 106 107 |
# File 'lib/prodder/project.rb', line 105 def settings_file_name File.join workspace, 'db/settings.sql' end |
#structure_file_name ⇒ Object
101 102 103 |
# File 'lib/prodder/project.rb', line 101 def structure_file_name File.join workspace, @defn['structure_file'] end |