Skip to content

Commit

Permalink
Laid out operations modules to implement plugins easier
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloh committed Jun 8, 2017
1 parent 160bb4c commit a733a1a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 35 deletions.
25 changes: 14 additions & 11 deletions lib/pathway/operation/authorization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ def authorization(&block)
end
end

def self.included(klass)
klass.extend ClassMethods
end
module InstanceMethods
def authorize(state)
authorize_with(state.result).then { state }
end

def authorize(state)
authorize_with(state.result).then { state }
end
def authorize_with(*objs)
objs = objs.first if objs.size <= 1
authorized?(*objs) ? wrap(objs) : error(:forbidden)
end

def authorize_with(*objs)
objs = objs.first if objs.size <= 1
authorized?(*objs) ? wrap(objs) : error(:forbidden)
def authorized?(*_)
true
end
end

def authorized?(*_)
true
def self.included(klass)
klass.extend ClassMethods
klass.include InstanceMethods
end
end
end
Expand Down
13 changes: 9 additions & 4 deletions lib/pathway/operation/flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@ def inherited(subclass)
end
end

extend Forwardable
module InstanceMethods
def result_key
self.class.result_key
end

delegate :result_key => 'self.class'
def sequence(&bl)
# TODO: Implement
end
end

def self.included(klass)
klass.extend ClassMethods
klass.include InstanceMethods
klass.result_key = :value
end

def sequence(&bl)
end
end
end
end
15 changes: 9 additions & 6 deletions lib/pathway/operation/scoped.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ def scope(*attrs)
end
end

def self.included(klass)
klass.extend ClassMethods
end
module InstanceMethods
def initialize(*)
end

def initialize(*)
def context
@context || {}
end
end

def context
@context || {}
def self.included(klass)
klass.extend ClassMethods
klass.include InstanceMethods
end
end
end
Expand Down
31 changes: 17 additions & 14 deletions lib/pathway/operation/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,28 @@ def _opts(opts = {})
end
end

extend Forwardable
module InstanceMethods
extend Forwardable

def self.included(klass)
klass.extend ClassMethods
klass.form_class = Pathway::Form
end
delegate :build_form => 'self.class'
alias :form :build_form

delegate :build_form => 'self.class'
alias :form :build_form
def validate(state)
validate_with(state[:input])
.then { |params| state.update(params: params) }
end

def validate(state)
validate_with(state[:input])
.then { |params| state.update(params: params) }
end
def validate_with(params, opts = {})
val = form(opts).call(params)

def validate_with(params, opts = {})
val = form(opts).call(params)
val.success? ? wrap(val.output) : error(:validation, details: val.messages)
end
end

val.success? ? wrap(val.output) : error(:validation, details: val.messages)
def self.included(klass)
klass.extend ClassMethods
klass.include InstanceMethods
klass.form_class = Pathway::Form
end
end
end
Expand Down

0 comments on commit a733a1a

Please sign in to comment.