Class: SugarCube::ActionSheetDelegate

Inherits:
Object
  • Object
show all
Defined in:
lib/sugarcube-factories/uiactionsheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#buttonsObject

Returns the value of attribute buttons.



128
129
130
# File 'lib/sugarcube-factories/uiactionsheet.rb', line 128

def buttons
  @buttons
end

#on_cancelObject

Returns the value of attribute on_cancel.



130
131
132
# File 'lib/sugarcube-factories/uiactionsheet.rb', line 130

def on_cancel
  @on_cancel
end

#on_defaultObject

Returns the value of attribute on_default.



129
130
131
# File 'lib/sugarcube-factories/uiactionsheet.rb', line 129

def on_default
  @on_default
end

#on_destructiveObject

Returns the value of attribute on_destructive.



131
132
133
# File 'lib/sugarcube-factories/uiactionsheet.rb', line 131

def on_destructive
  @on_destructive
end

#on_successObject

Returns the value of attribute on_success.



132
133
134
# File 'lib/sugarcube-factories/uiactionsheet.rb', line 132

def on_success
  @on_success
end

Instance Method Details

#actionSheet(alert, didDismissWithButtonIndex: index) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/sugarcube-factories/uiactionsheet.rb', line 134

def actionSheet(alert, didDismissWithButtonIndex:index)
  handler = nil
  if index == alert.destructiveButtonIndex && on_destructive
    handler = on_destructive || on_default
  elsif index == alert.cancelButtonIndex && on_cancel
    handler = on_cancel || on_default
  else
    handler = on_success || on_default
  end

  if handler
    if handler.arity == 0
      handler.call
    elsif handler.arity == 1
      button = buttons[index]
      handler.call(button)
    else
      button = buttons[index]
      handler.call(button, index)
    end
  end

  self.send(:autorelease)
end