Module: Musashi::Retriever::Strategist

Included in:
VisitorStrategist
Defined in:
lib/musashi/retriever.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.define(receiver, name = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/musashi/retriever.rb', line 58

def self.define(receiver,name=nil)
  raise "Undefined receiver" if receiver.nil?
  if name.nil?
    Strategist.define_by_behavior receiver
  else
    retriever = Strategist.retrievers_by_name[name]
    if retriever.nil?
      Strategist.define_by_behavior receiver
    else
      receiver.extend retriever
    end
  end
end

.define_by_behavior(receiver) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/musashi/retriever.rb', line 33

def self.define_by_behavior(receiver)
  @@retrievers_by_behavior.each do |retriever|
    if retriever.extend?(receiver)
      receiver.extend(retriever)
      break
    end
  end
end

.define_by_name(receiver, name) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/musashi/retriever.rb', line 50

def self.define_by_name(receiver,name)
  raise "Undefined receiver" if receiver.nil?
  raise "Undefined name for #{receiver}" if name.nil?
  retriever = @@retrievers_by_name[name]
  raise "Undefined retriever for #{receiver} with name=#{name}" if retriever.nil?
  receiver.extend retriever
end

.extend_object(receiver) ⇒ Object



21
22
23
# File 'lib/musashi/retriever.rb', line 21

def self.extend_object(receiver)
  self.define_by_behavior(receiver)
end

.retrievers_by_behaviorObject



25
26
27
# File 'lib/musashi/retriever.rb', line 25

def self.retrievers_by_behavior
  @@retrievers_by_behavior ||= {}
end

.retrievers_by_behavior=(retrievers) ⇒ Object



29
30
31
# File 'lib/musashi/retriever.rb', line 29

def self.retrievers_by_behavior=(retrievers)
  @@retrievers_by_behavior = retrievers
end

.retrievers_by_nameObject



42
43
44
# File 'lib/musashi/retriever.rb', line 42

def self.retrievers_by_name
  @@retrievers_by_name ||= {}
end

.retrievers_by_name=(retrievers) ⇒ Object



46
47
48
# File 'lib/musashi/retriever.rb', line 46

def self.retrievers_by_name=(retrievers)
  @@retrievers_by_name = retrievers
end

Instance Method Details

#define(receiver, name = nil) ⇒ Object



72
73
74
# File 'lib/musashi/retriever.rb', line 72

def define(receiver,name=nil)
  Strategist.define(receiver,name)
end

#follow?(method) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/musashi/retriever.rb', line 80

def follow?(method)
  not (method.nil? || no_follow.include?(method.to_s) || no_follow.include?(method))
end

#no_followObject



76
77
78
# File 'lib/musashi/retriever.rb', line 76

def no_follow
  @no_follow ||= []
end