17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/generators/tokenable/install_generator.rb', line 17
def setup_strategy
unless options.strategy
say_status :skip, 'strategy (none provided)', :yellow
return
end
if options.strategy.in?(list_of_strategies)
invoke 'active_record:model', [name], migration: false unless model_exists?
strategy_class = options.strategy.classify
model_path = "app/models/#{file_name}.rb"
already_injected = File.open(File.join(destination_root, model_path)).grep(/Tokenable::Strategies/).any?
if already_injected
say_status :skip, 'a strategy is already in this model', :yellow
else
inject_into_file model_path, " include Tokenable::Strategies::#{strategy_class}\n", after: " < ApplicationRecord\n"
end
else
say_status :failure, "stargery not found (#{options.strategy}). Available: #{list_of_strategies.join(", ")}", :red
end
end
|