Class: Whoosh::CLI::ClientGenerator
- Inherits:
-
Object
- Object
- Whoosh::CLI::ClientGenerator
- Defined in:
- lib/whoosh/cli/client_generator.rb
Constant Summary collapse
- CLIENT_TYPES =
%i[react_spa expo ios flutter htmx telegram_bot telegram_mini_app].freeze
Instance Attribute Summary collapse
-
#oauth ⇒ Object
readonly
Returns the value of attribute oauth.
-
#output_dir ⇒ Object
readonly
Returns the value of attribute output_dir.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #check_dependencies! ⇒ Object
- #default_output_dir ⇒ Object
-
#initialize(type:, oauth:, dir:, root: Dir.pwd) ⇒ ClientGenerator
constructor
A new instance of ClientGenerator.
- #introspect_or_fallback ⇒ Object
- #run ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(type:, oauth:, dir:, root: Dir.pwd) ⇒ ClientGenerator
Returns a new instance of ClientGenerator.
24 25 26 27 28 29 |
# File 'lib/whoosh/cli/client_generator.rb', line 24 def initialize(type:, oauth:, dir:, root: Dir.pwd) @type = type.to_sym @oauth = oauth @output_dir = dir || default_output_dir @root = root end |
Instance Attribute Details
#oauth ⇒ Object (readonly)
Returns the value of attribute oauth.
18 19 20 |
# File 'lib/whoosh/cli/client_generator.rb', line 18 def oauth @oauth end |
#output_dir ⇒ Object (readonly)
Returns the value of attribute output_dir.
18 19 20 |
# File 'lib/whoosh/cli/client_generator.rb', line 18 def output_dir @output_dir end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
18 19 20 |
# File 'lib/whoosh/cli/client_generator.rb', line 18 def type @type end |
Class Method Details
.client_types ⇒ Object
20 21 22 |
# File 'lib/whoosh/cli/client_generator.rb', line 20 def self.client_types CLIENT_TYPES end |
Instance Method Details
#check_dependencies! ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/whoosh/cli/client_generator.rb', line 61 def check_dependencies! result = ClientGen::DependencyChecker.check(@type) return if result[:ok] puts "\n⚠️ Missing dependencies for #{@type}:" result[:missing].each do |dep| msg = " - #{dep[:cmd]} (check: #{dep[:check]})" msg += " — found v#{dep[:found_version]}, need v#{dep[:min_version]}+" if dep[:found_version] puts msg end puts "\nInstall the missing dependencies and try again." exit 1 end |
#default_output_dir ⇒ Object
57 58 59 |
# File 'lib/whoosh/cli/client_generator.rb', line 57 def default_output_dir "clients/#{@type}" end |
#introspect_or_fallback ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/whoosh/cli/client_generator.rb', line 75 def introspect_or_fallback app = load_app if app introspector = ClientGen::Introspector.new(app, base_url: detect_base_url(app)) ir = introspector.introspect if ir.has_resources? || ir.has_auth? { mode: :introspected, ir: ir } else { mode: :fallback } end else { mode: :fallback } end end |
#run ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/whoosh/cli/client_generator.rb', line 31 def run validate! check_dependencies! result = introspect_or_fallback case result[:mode] when :introspected display_found(result[:ir]) ir = confirm_selection(result[:ir]) generate_client(ir) when :fallback display_fallback_prompt generate_fallback_backend ir = build_fallback_ir generate_client(ir) end display_success end |
#validate! ⇒ Object
51 52 53 54 55 |
# File 'lib/whoosh/cli/client_generator.rb', line 51 def validate! unless CLIENT_TYPES.include?(@type) raise ClientGen::Error, "Unknown client type: #{@type}. Supported: #{CLIENT_TYPES.join(", ")}" end end |