/
learner.rb
40 lines (30 loc) · 968 Bytes
/
learner.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# encoding: UTF-8
module Watchmaker
module Learner
extend ActiveSupport::Concern
module ClassMethods
# Learn a profile by taking explicit dependencies.
#
def learn(name, dependencies = {}, &block)
if name.is_a?(Hash)
# Convert the hash into a profile name and a list of
# dependencies that's either a hash of nested classes or
# array.
#
name, dependencies =
name_and_dependencies_from_dependency_hash(name)
# Specifically store these as abstract dependencies.
#
dependencies = { :abstract => dependencies }
end
Configuration.learn(name, dependencies, &block)
end
# Get the profile name out of a dependency hash.
#
def name_and_dependencies_from_dependency_hash(dependencies)
name = dependencies.keys.first
[name, dependencies[name]]
end
end
end
end