Class: IshManager::IroPursesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/ish_manager/iro_purses_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#basic_auth, #home, #tinymce

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/ish_manager/iro_purses_controller.rb', line 6

def create
  @iro_purse = Iro::Purse.new({
    profile_id: current_profile.id,
  })
  authorize! :create, @iro_purse

  if @iro_purse.update params[:iro_purse].permit!
    flash[:notice] = 'Successfully created iro_purse.'
    redirect_to action: :show, id: @iro_purse.id
  else
    flash[:alert] = "Cannot create iro_purse: #{@iro_purse.errors.full_messages.join(', ')}."
    render action: 'edit'
  end
end

#editObject



21
22
23
24
# File 'app/controllers/ish_manager/iro_purses_controller.rb', line 21

def edit
  @iro_purse = Iro::Purse.find params[:id]
  authorize! :edit, @iro_purse
end

#indexObject



26
27
28
29
# File 'app/controllers/ish_manager/iro_purses_controller.rb', line 26

def index
  @iro_purses = Iro::Purse.all
  authorize! :index, Iro::Purse
end

#newObject



31
32
33
34
# File 'app/controllers/ish_manager/iro_purses_controller.rb', line 31

def new
  @iro_purse = Iro::Purse.new
  authorize! :new, @iro_purse
end

#showObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/ish_manager/iro_purses_controller.rb', line 36

def show
  @purse = Iro::Purse.find params[:id]
  authorize! :my, @purse

  @strategies = Iro::CoveredCallStrategy.all
  underlyings = Tda::Stock.get_quotes( @strategies.map(&:ticker).compact.uniq.join(",") )
  # json_puts! underlyings, 'out'
  underlyings.each do |ticker, v|
    # puts! v[:mark], 'ze mark'
    Iro::CoveredCallStrategy.where( ticker: ticker ).update( current_underlying_strike: v[:mark] )
  end

  @positions = @purse.positions.order({ expires_on: :asc, strike: :asc })
  @positions.map &:refresh

  render @purse.parsed_config[:kind] || params[:kind] || 'show'
end

#updateObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/ish_manager/iro_purses_controller.rb', line 54

def update
  @iro_purse = Iro::Purse.find params[:id]
  authorize! :update, @iro_purse

  if @iro_purse.update params[:iro_purse].permit!
    flash[:notice] = 'Successfully updated iro_purse.'
    redirect_to action: :show, id: @iro_purse.id
  else
    flash[:alert] = "Cannot update iro_purse: #{@iro_purse.errors.full_messages.join(', ')}."
    render action: 'edit'
  end
end