Class: Commands::Init::InitModel
- Inherits:
-
Object
- Object
- Commands::Init::InitModel
- Defined in:
- lib/commands/init/init_model.rb
Overview
Base class of ‘initializers’.
This actually acts more as a registry of defined classes.
Direct Known Subclasses
ChangelistModel, DepotModel, GroupModel, SystemSettingsModel, TriggerModel, UserModel
Class Attribute Summary collapse
-
.model_classes ⇒ Object
Returns the value of attribute model_classes.
Class Method Summary collapse
-
.inheritable_attributes(*args) ⇒ Object
A lot of our settings are actually class instance variables, which can be overridden.
- .inherited(subclass) ⇒ Object
- .run(p4port, auto) ⇒ Object
Instance Method Summary collapse
-
#execute(p4) ⇒ Object
It’s likely that the main child class will handle overriding this method.
-
#rank ⇒ Object
Child classes should define this number greater than one.
Class Attribute Details
.model_classes ⇒ Object
Returns the value of attribute model_classes.
27 28 29 |
# File 'lib/commands/init/init_model.rb', line 27 def model_classes @model_classes end |
Class Method Details
.inheritable_attributes(*args) ⇒ Object
A lot of our settings are actually class instance variables, which can be overridden. This allows the child classes that depend on these values to define what they are.
39 40 41 42 43 44 45 46 47 |
# File 'lib/commands/init/init_model.rb', line 39 def self.inheritable_attributes(*args) @inheritable_attributes += args args.each do |arg| class_eval %( class << self; attr_accessor :#{arg} end ) end @inheritable_attributes end |
.inherited(subclass) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/commands/init/init_model.rb', line 49 def self.inherited(subclass) # Copy 'down' any inheritable attribute to the new child class @inheritable_attributes.each do |inheritable_attribute| instance_var = "@#{inheritable_attribute}" subclass.instance_variable_set(instance_var, instance_variable_get(instance_var)) end if subclass.respond_to?(:abstract) && subclass.send(:abstract) InitModel.model_classes.push(subclass) end end |
.run(p4port, auto) ⇒ Object
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/init_model.rb', line 61 def self.run(p4port, auto) system_settings = nil super_user = nil models = [] InitModel.model_classes.each do |model| if model <= DefaultSuperUser # do nothing elsif model <= SystemSettingsModel system_settings = model.new elsif !super_user and model <= UserModel and model.super super_user = model.new else models << model.new end end if !super_user super_user = DefaultSuperUser.new end models.sort! { |a, b| a.rank <=> b.rank } # Clear out any P4 Environment variables ENV.keys.select { |x| x =~ /^P4/ }.each { |x| ENV.delete(x) } p4 = P4.new p4.port = p4port p4.connect p4.exception_level = P4::RAISE_ERRORS p4.charset = 'auto' if auto if system_settings system_settings.execute(p4, super_user) else p4.user = super_user.login p4.password = super_user.password results = p4.run_login('-p') p4.password = results.first puts "log in as super, ticket is #{p4.password}" end models.each { |m| m.execute(p4, models, super_user) } end |
Instance Method Details
#execute(p4) ⇒ Object
It’s likely that the main child class will handle overriding this method. Our default method does nothing.
17 18 |
# File 'lib/commands/init/init_model.rb', line 17 def execute(p4) end |
#rank ⇒ Object
Child classes should define this number greater than one. 0 should be reserved for a single system settings instance.
11 12 13 |
# File 'lib/commands/init/init_model.rb', line 11 def rank 1 end |