Module: AgentManager::Mixin
- Included in:
- AgentCorporateEntity, AgentFamily, AgentPerson, AgentSoftware
- Defined in:
- backend/app/model/mixins/agent_manager.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (Object) before_save
Generally we won’t hit this because records are created using create_from_json.
-
- (Object) linked_agent_roles
-
- (Object) update_from_json(json, opts = {}, apply_nested_records = true)
-
- (Object) validate
Class Method Details
+ (Object) included(base)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'backend/app/model/mixins/agent_manager.rb', line 45 def self.included(base) base.extend(ClassMethods) base.set_model_scope :global base.include(Relationships) base.include() base.include(ImpliedPublication) base.include(Events) ArchivesSpaceService.loaded_hook do base.define_relationship(:name => :linked_agents, :contains_references_to_types => proc { base.relationship_dependencies[:linked_agents] }) end end |
Instance Method Details
- (Object) before_save
Generally we won’t hit this because records are created using create_from_json. But just to keep the tests happy.
81 82 83 84 85 86 87 |
# File 'backend/app/model/mixins/agent_manager.rb', line 81 def before_save if self.agent_sha1.nil? self.agent_sha1 = SecureRandom.hex end super end |
- (Object) linked_agent_roles
100 101 102 103 104 105 106 107 108 |
# File 'backend/app/model/mixins/agent_manager.rb', line 100 def linked_agent_roles role_ids = self.class.find_relationship(:linked_agents).values_for_property(self, :role_id).uniq # Hackish: we only want to return roles corresponding to linked archival # records (not events), so we filter it at this level. valid_enum = BackendEnumSource.values_for("linked_agent_role") BackendEnumSource.values_for_ids(role_ids).values.reject {|v| !valid_enum.include?(v) } end |
- (Object) update_from_json(json, opts = {}, apply_nested_records = true)
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'backend/app/model/mixins/agent_manager.rb', line 63 def update_from_json(json, opts = {}, apply_nested_records = true) self.class.(json) self.class.ensure_display_name(json) self.class.(json) # Force validation to make sure we're left with a valid record after our # changes json.to_hash # Called for the sake of updating the JSON blob sent to the realtime indexer self.class.populate_display_name(json) super(json, opts.merge(:agent_sha1 => self.class.calculate_hash(json))) end |
- (Object) validate
90 91 92 93 94 95 96 97 |
# File 'backend/app/model/mixins/agent_manager.rb', line 90 def validate super validates_unique([:agent_sha1], :message => "Agent must be unique") map_validation_to_json_property([:agent_sha1], :names) map_validation_to_json_property([:agent_sha1], :dates_of_existence) map_validation_to_json_property([:agent_sha1], :external_documents) map_validation_to_json_property([:agent_sha1], :notes) end |