class Apigen::Migration
Migration
is the base class for API definition migrations.
Public Class Methods
new(api)
click to toggle source
# File lib/apigen/migration.rb, line 7 def initialize(api) @api = api end
Public Instance Methods
add_endpoint(name, &block)
click to toggle source
# File lib/apigen/migration.rb, line 15 def add_endpoint(name, &block) raise 'You must pass a block when calling `add_endpoint`.' unless block_given? @api.endpoint(name, &block) end
add_model(name, &block)
click to toggle source
# File lib/apigen/migration.rb, line 40 def add_model(name, &block) @api.model(name, &block) end
remove_endpoint(*names)
click to toggle source
# File lib/apigen/migration.rb, line 31 def remove_endpoint(*names) endpoints = @api.endpoints # This is not algorithmically optimal. We won't do it millions of times though. names.each do |name| raise "No such endpoint :#{name}." unless endpoints.find { |e| e.name == name } end endpoints.reject! { |e| names.include?(e.name) } end
remove_model(*names)
click to toggle source
# File lib/apigen/migration.rb, line 55 def remove_model(*names) models = @api.models names.each do |name| raise "No such model :#{name}." unless models.key? name end names.each { |model_name| models.delete(model_name) } end
up()
click to toggle source
# File lib/apigen/migration.rb, line 11 def up raise 'Migration subclasses must implement #up.' end
update_endpoint(name, &block)
click to toggle source
# File lib/apigen/migration.rb, line 20 def update_endpoint(name, &block) endpoint = @api.endpoints.find { |e| e.name == name } error = if !endpoint "No such endpoint #{name}." elsif !block_given? 'You must pass a block when calling `update_endpoint`.' end raise error unless error.nil? endpoint.instance_eval(&block) end
update_model(name, &block)
click to toggle source
# File lib/apigen/migration.rb, line 44 def update_model(name, &block) model = @api.models[name] error = if !model "No such model :#{name}." elsif !block_given? 'You must pass a block when calling `update_model`.' end raise error unless error.nil? model.instance_eval(&block) end