Last active
September 17, 2015 17:47
-
-
Save josephbridgwaterrowe/a620a502a9614c37e17c to your computer and use it in GitHub Desktop.
Diplomat Classes WIP
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
# /app/models/interface/interface_factory.rb | |
module Interface | |
class InterfaceFactory | |
class << self | |
def build(context) | |
new(context).build | |
end | |
end | |
def initialize(context) | |
@context = context | |
end | |
def build | |
return IgnoreOldVersion.new(@context) if old? | |
interface_class.new(@context) | |
end | |
def old? | |
!new? && @context.adhesive.version > @context.object._v | |
end | |
def interface_class | |
[ | |
@context.organization.integration.interface_namespace, | |
@context.object.class.name, | |
action.to_s | |
].join('::').constantize | |
end | |
def action | |
new? ? :Insert : :Update | |
end | |
def new? | |
@context.adhesive.nil? | |
end | |
end | |
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
# /app/models/interface/entity/request.rb | |
module Interface | |
module Entity | |
class Request | |
def initialize(context, interface = nil) | |
@context = context | |
@interface = interface || build_interface | |
end | |
def call | |
@interface.call(payload) | |
end | |
protected | |
def build_interface | |
Interface::InterfaceFactory.build(@context) | |
end | |
def payload | |
@payload ||= build_payload | |
end | |
def build_payload | |
nil # TODO | |
end | |
end | |
end | |
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
# /app/models/interface/entity/upsert.rb | |
module Interface | |
module Entity | |
class Upsert | |
def initialize(entity, organization, request = nil) | |
@context = Interface::ObjectContext.new(entity, organization) | |
@request = request || build_request | |
end | |
def call | |
@request.call | |
# persist! | |
end | |
protected | |
def build_request | |
EntityRequest.new(context) | |
end | |
# def persist! | |
# @context.object.save! | |
# end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment