Class: ShopifyCLI::Form

Inherits:
Object
  • Object
show all
Defined in:
lib/shopify_cli/form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx, xargs, attributes) ⇒ Form

Returns a new instance of Form.



36
37
38
39
40
# File 'lib/shopify_cli/form.rb', line 36

def initialize(ctx, xargs, attributes)
  @ctx = ctx
  @xargs = xargs
  attributes.each { |k, v| send("#{k}=", v) unless v.nil? }
end

Instance Attribute Details

#ctxObject

Returns the value of attribute ctx.



34
35
36
# File 'lib/shopify_cli/form.rb', line 34

def ctx
  @ctx
end

#xargsObject

Returns the value of attribute xargs.



34
35
36
# File 'lib/shopify_cli/form.rb', line 34

def xargs
  @xargs
end

Class Method Details

.ask(ctx, args, flags) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/shopify_cli/form.rb', line 6

def ask(ctx, args, flags)
  attrs = {}
  (@positional_arguments || []).each { |name| attrs[name] = args.shift }
  return nil if attrs.any? { |_k, v| v.nil? }
  (@flag_arguments || []).each { |arg| attrs[arg] = flags[arg] }
  form = new(ctx, args, attrs)
  begin
    form.ask
    form
  rescue ShopifyCLI::Abort => err
    ctx.puts(err.message)
    nil
  rescue ShopifyCLI::AbortSilent
    nil
  end
end

.flag_arguments(*args) ⇒ Object



28
29
30
31
# File 'lib/shopify_cli/form.rb', line 28

def flag_arguments(*args)
  @flag_arguments = args
  attr_accessor(*args)
end

.positional_arguments(*args) ⇒ Object



23
24
25
26
# File 'lib/shopify_cli/form.rb', line 23

def positional_arguments(*args)
  @positional_arguments = args
  attr_accessor(*args)
end