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.
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.
36 37 38 39 40 41 |
# File 'lib/commands/init/changelist_model.rb', line 36 def initialize @description = self.class.description @adds = self.class.adds @edits = self.class.edits @user = self.class.user end |
Instance Attribute Details
#adds ⇒ Object
Returns the value of attribute adds.
34 35 36 |
# File 'lib/commands/init/changelist_model.rb', line 34 def adds @adds end |
#description ⇒ Object
Returns the value of attribute description.
34 35 36 |
# File 'lib/commands/init/changelist_model.rb', line 34 def description @description end |
#edits ⇒ Object
Returns the value of attribute edits.
34 35 36 |
# File 'lib/commands/init/changelist_model.rb', line 34 def edits @edits end |
#user ⇒ Object
Returns the value of attribute user.
34 35 36 |
# File 'lib/commands/init/changelist_model.rb', line 34 def user @user end |
Class Method Details
.abstract ⇒ Object
Internal implementation
30 31 32 |
# File 'lib/commands/init/changelist_model.rb', line 30 def self.abstract true end |
Instance Method Details
#execute(p4, models, super_user) ⇒ Object
43 44 45 46 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 |
# File 'lib/commands/init/changelist_model.rb', line 43 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 # 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') @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 p4.run_add('-c', change_id, add_path) end @edits.each do |edit| edit_path = File.join(client_path, edit.path) p4.run_edit('-c', change_id, edit_path) 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 |