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
61 62 63 64 65 66 67 68 69 |
# File 'lib/prodder/project.rb', line 61 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
84 85 86 |
# File 'lib/prodder/project.rb', line 84 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 |
# 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 File.open(quality_check_file_name, 'w') { |f| f.write(quality.join) } 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
124 125 126 |
# File 'lib/prodder/project.rb', line 124 def @defn.key?('permissions') && .key?('file') end |
#excluded_schemas ⇒ Object
128 129 130 |
# File 'lib/prodder/project.rb', line 128 def excluded_schemas db_credentials['exclude_schemas'] || [] end |
#excluded_tables ⇒ Object
132 133 134 |
# File 'lib/prodder/project.rb', line 132 def excluded_tables db_credentials['exclude_tables'] || [] end |
#git_origin ⇒ Object
96 97 98 |
# File 'lib/prodder/project.rb', line 96 def git_origin @defn['git']['origin'] end |
#included_users ⇒ Object
136 137 138 |
# File 'lib/prodder/project.rb', line 136 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
92 93 94 |
# File 'lib/prodder/project.rb', line 92 def local_git_path workspace end |
#nothing_to_push? ⇒ Boolean
79 80 81 82 |
# File 'lib/prodder/project.rb', line 79 def nothing_to_push? git.remote_update git.no_new_commits? end |
#permissions ⇒ Object
88 89 90 |
# File 'lib/prodder/project.rb', line 88 def @defn['permissions'] end |
#permissions_file_name ⇒ Object
116 117 118 |
# File 'lib/prodder/project.rb', line 116 def File.join workspace, ['file'] end |
#push ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/prodder/project.rb', line 71 def push if git.fast_forward? git.push else raise Prodder::Git::NotFastForward.new(git_origin) end end |
#quality_check_file_name ⇒ Object
112 113 114 |
# File 'lib/prodder/project.rb', line 112 def quality_check_file_name File.join workspace, @defn['quality_check_file'] end |
#seed_file_name ⇒ Object
108 109 110 |
# File 'lib/prodder/project.rb', line 108 def seed_file_name File.join workspace, @defn['seed_file'] end |
#seed_tables ⇒ Object
140 141 142 143 144 145 146 147 |
# File 'lib/prodder/project.rb', line 140 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
120 121 122 |
# File 'lib/prodder/project.rb', line 120 def separate_quality_checks? @defn.key? 'quality_check_file' end |
#settings_file_name ⇒ Object
104 105 106 |
# File 'lib/prodder/project.rb', line 104 def settings_file_name File.join workspace, 'db/settings.sql' end |
#structure_file_name ⇒ Object
100 101 102 |
# File 'lib/prodder/project.rb', line 100 def structure_file_name File.join workspace, @defn['structure_file'] end |