Class: Commands::Init::ChangelistModel
- Includes:
- P4Helpers
- Defined in:
- lib/commands/init/changelist_model.rb
Instance Attribute Summary collapse
-
#adds ⇒ Object
Returns the value of attribute adds.
-
#description ⇒ Object
Returns the value of attribute description.
-
#edits ⇒ Object
Returns the value of attribute edits.
-
#user ⇒ Object
Returns the value of attribute user.
-
#view ⇒ Object
Returns the value of attribute view.
Class Method Summary collapse
-
.abstract ⇒ Object
Internal implementation ========================================================================.
Instance Method Summary collapse
- #execute(p4, models, super_user) ⇒ Object
-
#initialize ⇒ ChangelistModel
constructor
A new instance of ChangelistModel.
Methods included from P4Helpers
Methods inherited from InitModel
inheritable_attributes, inherited, #rank, run
Constructor Details
#initialize ⇒ ChangelistModel
Returns a new instance of ChangelistModel.
39 40 41 42 43 44 45 |
# File 'lib/commands/init/changelist_model.rb', line 39 def initialize @description = self.class.description @adds = self.class.adds @edits = self.class.edits @user = self.class.user @view = self.class.view end |
Instance Attribute Details
#adds ⇒ Object
Returns the value of attribute adds.
37 38 39 |
# File 'lib/commands/init/changelist_model.rb', line 37 def adds @adds end |
#description ⇒ Object
Returns the value of attribute description.
37 38 39 |
# File 'lib/commands/init/changelist_model.rb', line 37 def description @description end |
#edits ⇒ Object
Returns the value of attribute edits.
37 38 39 |
# File 'lib/commands/init/changelist_model.rb', line 37 def edits @edits end |
#user ⇒ Object
Returns the value of attribute user.
37 38 39 |
# File 'lib/commands/init/changelist_model.rb', line 37 def user @user end |
#view ⇒ Object
Returns the value of attribute view.
37 38 39 |
# File 'lib/commands/init/changelist_model.rb', line 37 def view @view end |
Class Method Details
.abstract ⇒ Object
Internal implementation
33 34 35 |
# File 'lib/commands/init/changelist_model.rb', line 33 def self.abstract true end |
Instance Method Details
#execute(p4, models, super_user) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/commands/init/changelist_model.rb', line 47 def execute(p4, models, super_user) # Set up our options with a user context if specified by searching the # defined models. = {:p4 => p4} if user model = models.find {|m| m.class < UserModel && m.login == user } [:user] = model.login [:password] = model.password [:olduser] = super_user.login [:oldpass] = super_user.password end if view [:view] = view end # Define the logic of what the changelist model really does: make adds # and edits for the most part open_client() do |client_path, name| change_spec = p4.fetch_change change_spec._description = description results = p4.save_change(change_spec) change_id = results[0].gsub(/^Change (\d+) created./, '\1') puts "Preparing changelist #{change_id} with #{@adds.length} adds and #{@edits.length} edits" @adds.each do |add| add_path = File.join(client_path, add.path) dir = File.dirname(add_path) if dir && !dir.empty? if !Dir.exist?(dir) FileUtils.mkpath(dir) end end if add.content IO.write(add_path, add.content) elsif add.local_path FileUtils.copy(add.local_path, add_path) end results = p4.run_add('-c', change_id, add_path) puts "Added file #{add_path} to #{change_id}: #{results}" end @edits.each do |edit| edit_path = File.join(client_path, edit.path) results = p4.run_edit('-c', change_id, edit_path) puts "Editing file #{edit_path} on #{change_id}: #{results}" if edit.content IO.write(edit_path, edit.content) else FileUtils.copy(edit.local_path, edit_path) end end p4.run_submit('-c', change_id) end end |