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
64 65 66 67 68 69 70 71 72 |
# File 'lib/prodder/project.rb', line 64 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
87 88 89 |
# File 'lib/prodder/project.rb', line 87 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 61 62 |
# 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 # the first search path setting for constraints gets left over # in the structure, so we need to *attempt* to grab that 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
127 128 129 |
# File 'lib/prodder/project.rb', line 127 def @defn.key?('permissions') && .key?('file') end |
#excluded_schemas ⇒ Object
131 132 133 |
# File 'lib/prodder/project.rb', line 131 def excluded_schemas db_credentials['exclude_schemas'] || [] end |
#excluded_tables ⇒ Object
135 136 137 |
# File 'lib/prodder/project.rb', line 135 def excluded_tables db_credentials['exclude_tables'] || [] end |
#git_origin ⇒ Object
99 100 101 |
# File 'lib/prodder/project.rb', line 99 def git_origin @defn['git']['origin'] end |
#included_users ⇒ Object
139 140 141 |
# File 'lib/prodder/project.rb', line 139 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
95 96 97 |
# File 'lib/prodder/project.rb', line 95 def local_git_path workspace end |
#nothing_to_push? ⇒ Boolean
82 83 84 85 |
# File 'lib/prodder/project.rb', line 82 def nothing_to_push? git.remote_update git.no_new_commits? end |
#permissions ⇒ Object
91 92 93 |
# File 'lib/prodder/project.rb', line 91 def @defn['permissions'] end |
#permissions_file_name ⇒ Object
119 120 121 |
# File 'lib/prodder/project.rb', line 119 def File.join workspace, ['file'] end |
#push ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/prodder/project.rb', line 74 def push if git.fast_forward? git.push else raise Prodder::Git::NotFastForward.new(git_origin) end end |
#quality_check_file_name ⇒ Object
115 116 117 |
# File 'lib/prodder/project.rb', line 115 def quality_check_file_name File.join workspace, @defn['quality_check_file'] end |
#seed_file_name ⇒ Object
111 112 113 |
# File 'lib/prodder/project.rb', line 111 def seed_file_name File.join workspace, @defn['seed_file'] end |
#seed_tables ⇒ Object
143 144 145 146 147 148 149 150 |
# File 'lib/prodder/project.rb', line 143 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
123 124 125 |
# File 'lib/prodder/project.rb', line 123 def separate_quality_checks? @defn.key? 'quality_check_file' end |
#settings_file_name ⇒ Object
107 108 109 |
# File 'lib/prodder/project.rb', line 107 def settings_file_name File.join workspace, 'db/settings.sql' end |
#structure_file_name ⇒ Object
103 104 105 |
# File 'lib/prodder/project.rb', line 103 def structure_file_name File.join workspace, @defn['structure_file'] end |