forked from houndci/hound
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Old `Plan` model become obsolete with tiered plans. `Pricing` was an odd-name because `Plan` was taken. We can now move new logic into the `Plan` model, and refactor surrounding tier logic.
- Loading branch information
Greg Lazarev
committed
May 26, 2017
1 parent
d57b4cc
commit 17f1aa9
Showing
57 changed files
with
686 additions
and
892 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class PlansController < ApplicationController | ||
def index | ||
@plans = ActiveModel::ArraySerializer.new( | ||
Plan.all, | ||
each_serializer: PlanSerializer, | ||
scope: current_user, | ||
) | ||
@repo = Repo.find(plan_params[:repo_id]) | ||
end | ||
|
||
private | ||
|
||
def plan_params | ||
params.permit(:repo_id) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,44 @@ | ||
class Plan | ||
PRICES = { | ||
bulk: 0, | ||
public: 0, | ||
private: 12 | ||
} | ||
|
||
TYPES = { | ||
bulk: "bulk", | ||
public: "public", | ||
private: "private" | ||
} | ||
|
||
def initialize(repo) | ||
@repo = repo | ||
include ActiveModel::Serialization | ||
|
||
PLANS = [ | ||
{ id: "basic", price: 0, range: 0..0, title: "Hound" }, | ||
{ id: "tier1", price: 49, range: 1..4, title: "Chihuahua" }, | ||
{ id: "tier2", price: 99, range: 5..10, title: "Labrador" }, | ||
{ id: "tier3", price: 249, range: 11..30, title: "Great Dane" }, | ||
].freeze | ||
|
||
attr_reader :id, :price, :title | ||
|
||
def initialize(id:, range:, price:, title:) | ||
@id = id | ||
@range = range | ||
@price = price | ||
@title = title | ||
end | ||
|
||
def type | ||
if @repo.bulk? | ||
TYPES[:bulk] | ||
elsif @repo.private? | ||
TYPES[:private] | ||
else | ||
TYPES[:public] | ||
end | ||
def self.all | ||
PLANS.map { |plan| new(plan) } | ||
end | ||
|
||
def price | ||
if @repo.bulk? | ||
PRICES[:bulk] | ||
elsif @repo.private? | ||
PRICES[:private] | ||
else | ||
PRICES[:public] | ||
end | ||
def self.find_by(count:) | ||
found = PLANS.detect { |plan| plan.fetch(:range).include?(count) } | ||
new(found) | ||
end | ||
|
||
def ==(other) | ||
id == other.id | ||
end | ||
|
||
def allowance | ||
range.max | ||
end | ||
|
||
def open_source? | ||
price.zero? | ||
end | ||
|
||
private | ||
|
||
attr_reader :range | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class PlanSelector | ||
BULK_ID = "bulk".freeze | ||
|
||
def initialize(user) | ||
@user = user | ||
end | ||
|
||
def current_plan | ||
find_plan(repo_count) | ||
end | ||
|
||
def next_plan | ||
find_plan(repo_count.succ) | ||
end | ||
|
||
def previous_plan | ||
find_plan(repo_count.pred) | ||
end | ||
|
||
def upgrade? | ||
current_plan != next_plan | ||
end | ||
|
||
private | ||
|
||
attr_reader :user | ||
|
||
def repo_count | ||
@_repo_count ||= repos.size | ||
end | ||
|
||
def find_plan(count) | ||
Plan.find_by(count: count) | ||
end | ||
|
||
def repos | ||
user.subscribed_repos | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.