Module: ActiveFedora::ServiceDefinitions

Defined in:
lib/active_fedora/service_definitions.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_fedora/service_definitions.rb', line 3

def self.included(mod)
  # check that it's an AF base
  if mod.ancestors.include? ActiveFedora::Base
    mod.extend(ClassMethods)
    model_uri = mod.to_class_uri
  # load ContentModel, pull Sdef pointers
    begin
      cmodel = ActiveFedora::ContentModel.find(mod.to_class_uri)
      sdef_pids = cmodel.ids_for_outbound(:has_service).collect { |uri|
        uri.split('/')[-1]
      }
    rescue
      sdef_pids = []
    end
    unless sdef_pids.include? "fedora-system:3"
      sdef_pids << "fedora-system:3"
    end
    sdef_pids.each { |sdef_pid| mod.has_service_definition sdef_pid }
  end
end

.lookup_method(sdef_uri, method_name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_fedora/service_definitions.rb', line 34

def self.lookup_method(sdef_uri, method_name)
  sdef_pid = sdef_uri.split('/')[-1]
  begin
    sdef = sdef_config[sdef_pid]
    return nil unless sdef
    result = nil
    sdef.each { |key, value| result = key if method_name == value }
  rescue
    return nil
  end
  return result
end

.sdef_configObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/active_fedora/service_definitions.rb', line 23

def self.sdef_config
  @@methods ||= begin
    if defined? Rails
      config_path = Rails.root.join('config','service_mappings.yml')
    else
      config_path = 'config/service_mappings.yml'
    end
    YAML::load(File.open(config_path))[:service_mapping]
  end
  @@methods
end