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.



34
35
36
37
38
# File 'lib/shopify-cli/form.rb', line 34

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.



32
33
34
# File 'lib/shopify-cli/form.rb', line 32

def ctx
  @ctx
end

#xargsObject

Returns the value of attribute xargs.



32
33
34
# File 'lib/shopify-cli/form.rb', line 32

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
# 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
  end
end

.flag_arguments(*args) ⇒ Object



26
27
28
29
# File 'lib/shopify-cli/form.rb', line 26

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

.positional_arguments(*args) ⇒ Object



21
22
23
24
# File 'lib/shopify-cli/form.rb', line 21

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