Skip to content

Instantly share code, notes, and snippets.

@benbonnet
Created December 2, 2019 09:59
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 benbonnet/4fc7bb703ed3d7652d483dafc32491e5 to your computer and use it in GitHub Desktop.
Save benbonnet/4fc7bb703ed3d7652d483dafc32491e5 to your computer and use it in GitHub Desktop.
ACTIONS = %i[index get create update]
class BaseClass; end
class ObjectEngine
attr_reader :item, :schema
def initialize(item)
@item = item
# @schema = item.application.schema
end
def process
Class.new(BaseClass) do
attr_reader :record
define_method :initialize do |record|
@record = record
end
# replace ACTIONS with item.schema relation methods
ACTIONS.each do |action|
define_method "#{action}" do |filters: nil|
pp "#{action} =====> #{record}"
end
end
end
end
end
item = { ok: :cool }
klass = ObjectEngine.new(item).process
ACTIONS.each do |action|
klass.new(item).send(action)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment