Module: Trailblazer::Macro::IdFor

Defined in:
lib/trailblazer/macro.rb

Class Method Summary collapse

Class Method Details

.call(user_proc, macro:, hint: nil, id: from_callable(user_proc, hint: hint)) ⇒ Object



58
59
60
# File 'lib/trailblazer/macro.rb', line 58

def call(user_proc, macro:, hint: nil, id: from_callable(user_proc, hint: hint))
  [macro, id].join("/")
end

.from_callable(user_proc, hint: nil) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/trailblazer/macro.rb', line 62

def from_callable(user_proc, hint: nil)
  if user_proc.is_a?(Class)
    user_proc.to_s
  elsif user_proc.instance_of?(Method)
    "method(:#{user_proc.name})"
  else
    hint || rand(4)
  end
end