Skip to content

Instantly share code, notes, and snippets.

@yoshie902a
Last active May 23, 2019 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoshie902a/627845570d0ea88fe0911a3d619b0c58 to your computer and use it in GitHub Desktop.
Save yoshie902a/627845570d0ea88fe0911a3d619b0c58 to your computer and use it in GitHub Desktop.
YAML Model
require 'yaml'
class Product
def self.all
@all ||= YAML
.load_file(Rails.root/"config"/"products.yml")
.fetch(Rails.env)
.map { |id, attrs| [id.intern, new(id: id, **attrs.symbolize_keys)] }
.to_h
end
def self.[](id, &if_dne)
all.fetch id&.intern, &if_dne
end
def self.one_membership
self[__method__]
end
def self.two_membership
self[__method__]
end
def self.three_membership
self[__method__]
end
def initialize(id:, name:, amount:, stripe_plan_id:)
@id = id.intern
@name = name.freeze
@amount = amount
@square_plan_id = square_plan_id&.freeze
end
attr_reader :id, :name, :amount, :square_plan_id
def subscription?
!!square_plan_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment