| Module | OpenWFE::Contextual |
| In: |
lib/openwfe/contextual.rb
|
This mixin helds an application_context field and provides a lookup method for digging into that context.
| application_context | -> | ac |
| application_context | [RW] |
Returns the work directory for the OpenWFE[ru] application context (if any).
# File lib/openwfe/contextual.rb, line 92
92: def get_work_directory (context_or_dir=nil)
93:
94: dir = if context_or_dir.is_a?(String)
95: context_or_dir
96: elsif context_or_dir.respond_to?(:[])
97: context_or_dir[:work_directory]
98: else
99: @application_context[:work_directory] if @application_context
100: end
101:
102: dir = DEFAULT_WORK_DIRECTORY unless dir
103:
104: FileUtils.makedirs(dir) unless File.exist?(dir)
105:
106: dir
107: end
Use reflection to instantiate the new service,and add it to the application context The service_name can be a String or a Symbol (which will be turned into a String).
# File lib/openwfe/contextual.rb, line 76
76: def init_service (service_name, service_class)
77:
78: s = service_class.new service_name, @application_context
79:
80: unless service_name
81: s.service_name = "#{service_class.name}::#{s.object_id}"
82: @application_context[s.service_name.to_s] = s
83: end
84:
85: s
86: end
Looks up something in the application context, if the given key is a class, then the first value in the context of that class is returned.
# File lib/openwfe/contextual.rb, line 58
58: def lookup (key)
59:
60: if key.kind_of? Class
61: @application_context.each do |k, value|
62: return value if value.class == key
63: end
64: return nil
65: end
66:
67: @application_context[key]
68: end