pathway 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4102ece25806d48a8fab8ae17baa090f3c20730
4
- data.tar.gz: 3bfbdc6fadedd29d034e682359fc565bbafc66b3
3
+ metadata.gz: 85ddbb4a7f33859093dadc9c82d66fa2be92e4d1
4
+ data.tar.gz: ebf6d815197776cb0914be7e4926817cac2ab6e0
5
5
  SHA512:
6
- metadata.gz: d77498d2506f07c345bf6267bae6eece1803e0bc2a58797979be5082f5a95d24fc26925c1eeea72196f0b88682577b7601ddd044210a4878fb4a37f62c489681
7
- data.tar.gz: 0a23e8cafac25619343c5920865d9181b8c26ccee8374b4e05a081d41e0cc878cf5284b588fc511b77a5f489128b5d0d0fc6cfffbeb0c2ecfb107bb5523b601c
6
+ metadata.gz: 3d0072356edbbc5d505af0c1a4d9e584c62c28c0ddc1678a6d4e687c9d22746b88bc4eae2cd812f92f9b63cbe978e258e4cba6ceefc6cf5b68981f2f015fffcb
7
+ data.tar.gz: 4b5eb9be35ba2b9d77aa6831219081964c34891d1c7dda79e113fbad760622c97d52bec5cc518a43683a9ab5cb7905da9ae1656a684f4e001d99b52f7a378f5a
@@ -6,7 +6,7 @@ require 'pathway/result'
6
6
 
7
7
  module Pathway
8
8
  class Operation
9
- def self.plugin(name)
9
+ def self.plugin(name, *args)
10
10
  require "pathway/plugins/#{Inflecto.underscore(name)}" if name.is_a?(Symbol)
11
11
 
12
12
  plugin = name.is_a?(Module) ? name : Plugins.const_get(Inflecto.camelize(name))
@@ -15,12 +15,12 @@ module Pathway
15
15
  self.include plugin::InstanceMethods if plugin.const_defined? :InstanceMethods
16
16
  self::DSL.include plugin::DSLMethods if plugin.const_defined? :DSLMethods
17
17
 
18
- plugin.apply(self) if plugin.respond_to?(:apply)
18
+ plugin.apply(self, *args) if plugin.respond_to?(:apply)
19
19
  end
20
20
 
21
21
  def self.inherited(subclass)
22
- subclass.const_set :DSL, Class.new(self::DSL)
23
22
  super
23
+ subclass.const_set :DSL, Class.new(self::DSL)
24
24
  end
25
25
 
26
26
  class DSL
@@ -4,7 +4,8 @@ module Pathway
4
4
  module Plugins
5
5
  module DryValidation
6
6
  module ClassMethods
7
- attr_reader :form_class
7
+ attr_reader :form_class, :form_options
8
+ attr_accessor :auto_wire_options
8
9
 
9
10
  def form(base = nil, **opts, &block)
10
11
  if block_given?
@@ -20,6 +21,7 @@ module Pathway
20
21
  def form_class= klass
21
22
  @builded_form = klass.options.empty? ? klass.new : nil
22
23
  @form_class = klass
24
+ @form_options = klass.options.keys
23
25
  end
24
26
 
25
27
  def build_form(opts = {})
@@ -29,6 +31,7 @@ module Pathway
29
31
  def inherited(subclass)
30
32
  super
31
33
  subclass.form_class = form_class
34
+ subclass.auto_wire_options = auto_wire_options
32
35
  end
33
36
 
34
37
  private
@@ -49,11 +52,14 @@ module Pathway
49
52
  module InstanceMethods
50
53
  extend Forwardable
51
54
 
52
- delegate :build_form => 'self.class'
55
+ delegate %i[build_form form_options auto_wire_options] => 'self.class'
53
56
  alias :form :build_form
54
57
 
55
- def validate(state, with: [])
56
- opts = Array(with).map { |key| [key, state[key]] }.to_h
58
+ def validate(state, with: nil)
59
+ if auto_wire_options && form_options.any?
60
+ with ||= form_options.zip(form_options).to_h
61
+ end
62
+ opts = Hash(with).map { |opt, key| [opt, state[key]] }.to_h
57
63
  validate_with(state[:input], opts)
58
64
  .then { |params| state.update(params: params) }
59
65
  end
@@ -65,8 +71,9 @@ module Pathway
65
71
  end
66
72
  end
67
73
 
68
- def self.apply(operation)
74
+ def self.apply(operation, auto_wire_options: false)
69
75
  operation.form_class = Dry::Validation::Schema::Form
76
+ operation.auto_wire_options = auto_wire_options
70
77
  end
71
78
  end
72
79
  end
@@ -1,3 +1,3 @@
1
1
  module Pathway
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Herrero
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-18 00:00:00.000000000 Z
11
+ date: 2017-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflecto