Class: IshManager::IroPursesController
Instance Method Summary
collapse
#basic_auth, #home, #tinymce
Instance Method Details
#create ⇒ Object
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
|
#edit ⇒ Object
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
|
#index ⇒ Object
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
|
#new ⇒ Object
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
|
#roll_prep ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/controllers/ish_manager/iro_purses_controller.rb', line 58
def roll_prep
@strategies = Iro::CoveredCallStrategy.all
@position = Iro::Position.find params[:id]
@positions = [ @position ]
@purse = @position.purse
@strategy = @position.strategy
authorize! :roll_prep, @position
@next_positions = []
next_date = @position.expires_on + 7.days
[ -0.5, 0, 0.5, 1, 1.5 ].each do |price_step|
next_position = Iro::CoveredCall.new({
expires_on: next_date,
strike: @position.strike + price_step,
ticker: @strategy.ticker,
opened_price: @position.current_price, })
@next_positions.push( next_position )
end
@next_positions.map &:refresh
@next_positions.map do |p|
current_price = p.current_price
p.opened_price = p.current_price
current_price = current_price - @position.current_price p.current_price = p.opened_price - current_price
end
@next_positions.each do |p|
puts! p, 'nexxt'
end
render params[:kind] || @purse.parsed_config[:kind] || 'show'
end
|
#show ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'app/controllers/ish_manager/iro_purses_controller.rb', line 37
def show
@purse = Iro::Purse.find params[:id]
authorize! :my, @purse
@strategies = Iro::CoveredCallStrategy.all
if params[:statuses]
@positions = @purse.positions.where( :status.in => params[:statuses].split(',') )
else
@positions = @purse.positions
end
@positions = @positions.order({ expires_on: :asc, strike: :asc })
render params[:kind] || @purse.parsed_config[:kind] || 'show'
end
|
#update ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'app/controllers/ish_manager/iro_purses_controller.rb', line 95
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
|