Sha256: cff3cbb79489f33fd6074cf63408ce4f3a5df6d94f5dcbb2b71df3cebb157a33

Contents?: true

Size: 1.78 KB

Versions: 17

Compression:

Stored size: 1.78 KB

Contents

class ::IshManager::IroPursesController < IshManager::ApplicationController

  before_action :set_lists

  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

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

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

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

  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

  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

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ish_manager-0.1.8.450 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.449 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.448 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.447 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.446 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.445 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.444 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.443 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.442 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.441 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.440 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.439 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.438 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.437 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.436 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.435 app/controllers/ish_manager/iro_purses_controller.rb
ish_manager-0.1.8.434 app/controllers/ish_manager/iro_purses_controller.rb