Created
December 2, 2019 09:59
-
-
Save benbonnet/4fc7bb703ed3d7652d483dafc32491e5 to your computer and use it in GitHub Desktop.
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
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