Class: LcpRuby::Generators::ApiTokensGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- LcpRuby::Generators::ApiTokensGenerator
show all
- Includes:
- FormatSupport, Prerequisites
- Defined in:
- lib/generators/lcp_ruby/api_tokens_generator.rb
Constant Summary
FormatSupport::VALID_FORMATS
Instance Method Summary
collapse
included, #validate_format
included, #lcp_format_missing_prereqs
Instance Method Details
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/generators/lcp_ruby/api_tokens_generator.rb', line 51
def
= File.join(destination_root, "config/lcp_ruby/menu.yml")
unless File.exist?()
say "Skipped menu append — config/lcp_ruby/menu.yml not found. Add the entry manually if desired.", :yellow
return
end
raw = YAML.safe_load(File.read(), permitted_classes: [ Symbol ]) || {}
nested = raw.key?("menu")
container = nested ? (raw["menu"] ||= {}) : raw
top = container["top_menu"] || []
url = "/my-api-tokens"
if top.any? { |entry| entry.is_a?(Hash) && entry["url"] == url }
say "Skipped menu append — entry for #{url} already present.", :yellow
return
end
top << {
"label" => "My API Tokens",
"icon" => "key",
"url" => url,
"position" => "right"
}
container["top_menu"] = top
File.write(, raw.to_yaml)
say "Appended menu entry for #{url} to config/lcp_ruby/menu.yml", :green
end
|
#copy_create_dialog_presenter ⇒ Object
31
32
33
34
35
|
# File 'lib/generators/lcp_ruby/api_tokens_generator.rb', line 31
def copy_create_dialog_presenter
copy_dsl_or_yaml "create_dialog.rb",
dsl_target: "config/lcp_ruby/presenters/my_api_tokens_create_dialog.rb",
yaml_target: "config/lcp_ruby/presenters/my_api_tokens_create_dialog.yml"
end
|
#copy_locale ⇒ Object
47
48
49
|
# File 'lib/generators/lcp_ruby/api_tokens_generator.rb', line 47
def copy_locale
template "locales.en.yml", "config/locales/lcp_ruby/api_tokens.en.yml"
end
|
#copy_model ⇒ Object
19
20
21
22
23
|
# File 'lib/generators/lcp_ruby/api_tokens_generator.rb', line 19
def copy_model
copy_dsl_or_yaml "model.rb",
dsl_target: "config/lcp_ruby/models/api_token.rb",
yaml_target: "config/lcp_ruby/models/api_token.yml"
end
|
#copy_permissions ⇒ Object
43
44
45
|
# File 'lib/generators/lcp_ruby/api_tokens_generator.rb', line 43
def copy_permissions
template "permissions.yml", "config/lcp_ruby/permissions/api_token.yml"
end
|
#copy_presenter ⇒ Object
25
26
27
28
29
|
# File 'lib/generators/lcp_ruby/api_tokens_generator.rb', line 25
def copy_presenter
copy_dsl_or_yaml "presenter.rb",
dsl_target: "config/lcp_ruby/presenters/my_api_tokens.rb",
yaml_target: "config/lcp_ruby/presenters/my_api_tokens.yml"
end
|
#copy_view_group ⇒ Object
37
38
39
40
41
|
# File 'lib/generators/lcp_ruby/api_tokens_generator.rb', line 37
def copy_view_group
copy_dsl_or_yaml "view_group.rb",
dsl_target: "config/lcp_ruby/views/my_api_tokens.rb",
yaml_target: "config/lcp_ruby/views/my_api_tokens.yml"
end
|
#show_post_install_message ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/generators/lcp_ruby/api_tokens_generator.rb', line 82
def show_post_install_message
say ""
say "LCP Ruby API tokens installed!", :green
say ""
say "Generated files:"
say " - config/lcp_ruby/models/api_token.#{format_extension}"
say " - config/lcp_ruby/presenters/my_api_tokens.#{format_extension}"
say " - config/lcp_ruby/presenters/my_api_tokens_create_dialog.#{format_extension}"
say " - config/lcp_ruby/views/my_api_tokens.#{format_extension}"
say " - config/lcp_ruby/permissions/api_token.yml"
say " - config/locales/lcp_ruby/api_tokens.en.yml"
say ""
say "Next steps:"
say " 1. bundle exec rails db:prepare # creates lcp_ruby_api_tokens table"
say " 2. Start server and visit /my-api-tokens to mint a token."
say " 3. Use the token via 'Authorization: Bearer <token>' or HTTP Basic (password = token)."
say ""
end
|