rom-changeset 1.0.0.beta2 → 1.0.0.beta3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bf7b154ea5fdf816ecac29171738cdd8511296b
4
- data.tar.gz: 00b0f1be4b5192e212eac8c01a9565ba393809bc
3
+ metadata.gz: 3e974c1c36fcff82e3b23b9f2a3cfea2e6b8de4a
4
+ data.tar.gz: c87a7913578f4091f9496b9b7676ebb8d797963e
5
5
  SHA512:
6
- metadata.gz: 7d86686d0cfc452654422dc2b79d9c14a042653347ad1c72fd83508c8faaefec8ba3241a47832c53a966111fec99be1b095b5e3298b871f64b5825dcc6939816
7
- data.tar.gz: 3b778dd54cf853b93cb8e36f423b12bad522031595575ce4e52b62f5c430c6acf8a5d655c1d7f5d42422726291414f452cfd9171d92f55730e36c4a6e450d7f1
6
+ metadata.gz: 63d0b84a39845c77a5ca20a2806cb736b010867549290d8a41a132f16703278d02e4d9ed75bf34c30c9dca7510e920cbfc9371ab6b2d62211a3f8d0a33ebb18f
7
+ data.tar.gz: dd10e1c4f3b82c80b576aa77c46b122e2355e7979df82a69e70f9b29518a6b060ed0d69f50e07f2b52f28731d1808e986a5cc372cac47889040f4acba46a728b
@@ -1,5 +1,3 @@
1
- require 'rom/changeset/restricted'
2
-
3
1
  module ROM
4
2
  class Changeset
5
3
  # Changeset specialization for delete commands
@@ -9,8 +7,6 @@ module ROM
9
7
  #
10
8
  # @api public
11
9
  class Delete < Changeset
12
- include Restricted
13
-
14
10
  command_type :delete
15
11
  end
16
12
  end
@@ -76,16 +76,8 @@ module ROM
76
76
  end
77
77
  end
78
78
 
79
- def with(opts)
80
- if opts.empty?
81
- self
82
- else
83
- Pipe.new(processor, options.merge(opts))
84
- end
85
- end
86
-
87
79
  def new(processor, opts = EMPTY_HASH)
88
- Pipe.new(processor, options.merge(opts))
80
+ Pipe.new(processor, opts.empty? ? options : options.merge(opts))
89
81
  end
90
82
  end
91
83
  end
@@ -92,13 +92,14 @@ module ROM
92
92
  def self.inherited(klass)
93
93
  return if klass == ROM::Changeset
94
94
  super
95
- klass.instance_variable_set(:@__pipes__, pipes ? pipes.dup : EMPTY_ARRAY)
95
+ klass.instance_variable_set(:@__pipes__, pipes.dup)
96
96
  end
97
97
 
98
98
  # @api private
99
99
  def self.pipes
100
100
  @__pipes__
101
101
  end
102
+ @__pipes__ = EMPTY_ARRAY
102
103
 
103
104
  # Pipe changeset's data using custom steps define on the pipe
104
105
  #
@@ -1,5 +1,3 @@
1
- require 'rom/changeset/restricted'
2
-
3
1
  module ROM
4
2
  class Changeset
5
3
  # Changeset specialization for update commands
@@ -15,8 +13,6 @@ module ROM
15
13
  #
16
14
  # @api public
17
15
  class Update < Stateful
18
- include Restricted
19
-
20
16
  command_type :update
21
17
 
22
18
  # Commit update changeset if there's a diff
@@ -1,5 +1,5 @@
1
1
  module ROM
2
2
  class Changeset
3
- VERSION = '1.0.0.beta2'.freeze
3
+ VERSION = '1.0.0.beta3'.freeze
4
4
  end
5
5
  end
data/lib/rom/changeset.rb CHANGED
@@ -71,24 +71,6 @@ module ROM
71
71
  }
72
72
  end
73
73
 
74
- # Return a new changeset with updated options
75
- #
76
- # @example
77
- # class NewUser < ROM::Changeset::Create[:users]
78
- # option :token_generator
79
- # end
80
- #
81
- # changeset = user_repo.changeset(NewUser).with(token_generator: my_token_gen)
82
- #
83
- # @param [Hash] new_options The new options
84
- #
85
- # @return [Changeset]
86
- #
87
- # @api public
88
- def with(new_options)
89
- self.class.new(relation, options.merge(new_options))
90
- end
91
-
92
74
  # Return a new changeset with provided relation
93
75
  #
94
76
  # New options can be provided too
@@ -24,7 +24,51 @@ module ROM
24
24
 
25
25
  # Create a changeset for a relation
26
26
  #
27
- # @return [Changeset]
27
+ # @overload changeset(type, data)
28
+ # Create a changeset of one of predefined types
29
+ #
30
+ # @example creating a record
31
+ # users.
32
+ # changeset(:create, name: 'Jane').
33
+ # commit
34
+ # # => #<ROM::Struct::User id=1 name="Jane">
35
+ #
36
+ # @example updating a record
37
+ # users.
38
+ # by_pk(1).
39
+ # changeset(:update, name: 'Jack').
40
+ # commit
41
+ # # => #<ROM::Struct::User id=1 name="Jane">
42
+ #
43
+ # @example providing data as a separate step
44
+ # changeset = users.changeset(:create)
45
+ # jack = changeset.data(name: 'Jack').commit
46
+ # jane = changeset.data(name: 'Jane').commit
47
+ #
48
+ # @example using a command graph
49
+ # users.
50
+ # changeset(
51
+ # :create,
52
+ # name: "Jane",
53
+ # posts: [{ title: "Something about aliens" }]
54
+ # )
55
+ #
56
+ # @param [Symbol] type The changeset type
57
+ # @param [Hash] data
58
+ # @return [Changeset]
59
+ #
60
+ # @overload changeset(changeset_class, data)
61
+ # @example using a custom changeset class
62
+ # class NewUser < ROM::Changeset::Create
63
+ # map do |tuple|
64
+ # { **tuple, name: tuple.values_at(:first_name, :last_name).join(' ') }
65
+ # end
66
+ # end
67
+ #
68
+ # users.changeset(NewUser, first_name: 'John', last_name: 'Doe').commit
69
+ #
70
+ # @param [Class] changeset_class A custom changeset class
71
+ # @return [Changeset]
28
72
  #
29
73
  # @api public
30
74
  def changeset(type, data = EMPTY_HASH)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rom-changeset
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta2
4
+ version: 1.0.0.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-04 00:00:00.000000000 Z
11
+ date: 2017-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-core
@@ -101,7 +101,6 @@ files:
101
101
  - lib/rom/changeset/create.rb
102
102
  - lib/rom/changeset/delete.rb
103
103
  - lib/rom/changeset/pipe.rb
104
- - lib/rom/changeset/restricted.rb
105
104
  - lib/rom/changeset/stateful.rb
106
105
  - lib/rom/changeset/update.rb
107
106
  - lib/rom/changeset/version.rb
@@ -126,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
125
  version: 1.3.1
127
126
  requirements: []
128
127
  rubyforge_project:
129
- rubygems_version: 2.6.12
128
+ rubygems_version: 2.6.11
130
129
  signing_key:
131
130
  specification_version: 4
132
131
  summary: Changeset abstraction for rom-rb
@@ -1,28 +0,0 @@
1
- module ROM
2
- class Changeset
3
- module Restricted
4
- # Return a command restricted by the changeset's relation
5
- #
6
- # @see Changeset#command
7
- #
8
- # @api private
9
- def command
10
- super.new(relation)
11
- end
12
-
13
- # Restrict changeset's relation by its PK
14
- #
15
- # @example
16
- # repo.changeset(UpdateUser).by_pk(1).data(name: "Jane")
17
- #
18
- # @param [Object] pk
19
- #
20
- # @return [Changeset]
21
- #
22
- # @api public
23
- def by_pk(pk, data = EMPTY_HASH)
24
- new(relation.by_pk(pk), __data__: data)
25
- end
26
- end
27
- end
28
- end