administrate-field-state_machine 0.0.1 → 0.0.2

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: e56c0d26a762ae436509c8ffc1c0972d1ce979e8
4
- data.tar.gz: 46cec486e91733e601f04e377be89c078f023192
3
+ metadata.gz: dc1b91185f4fbb162b1a19f60caa253da4955243
4
+ data.tar.gz: 8c2e3f0d3249ec9d97dc5b1f1673e54463c0ca95
5
5
  SHA512:
6
- metadata.gz: 2bcd428af796960a42b40e1a065602f24c16fff3bf707afe08c822b69c05cca8fa9d50eff89d2ad296d61a7feccb02996448021b35cb961d45fb1f3d6aec32a4
7
- data.tar.gz: 74da2d430020e99a9873cfc83a054115a300bf2186b545ebb46f6e379ac5744c49751ba2da0b09c8dd15148a1d4a3a7a4c5fd177e9a8442cdca780708e3ae92d
6
+ metadata.gz: 9cea98a35ceea7bddaa5f2f0d92ce50170b6a84d0bd418821c3704f4448f12a6db0e1c158e841b1de8ff98bebd998d330a837cd87a4a9e8e81098f838d8918ae
7
+ data.tar.gz: ef5766e2136a32c1940d31bd48640ec7b3f45ebead7ebacfec7aae70ae3ba37ae72ac63c011ac13fb08139c145c3ef32bc9a1edfc02099ee94befb8ea0a9ec86
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.0.2](https://github.com/z-productions/administrate-field-state_machine/tree/v0.0.2) (2016-11-25)
4
+ [Full Changelog](https://github.com/z-productions/administrate-field-state_machine/compare/v0.0.1...v0.0.2)
5
+
6
+ * Switch to selecting transitions rather than states
7
+
3
8
  ## [v0.0.1](https://github.com/z-productions/administrate-field-state_machine/tree/v0.0.1) (2016-11-16)
4
9
  First release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- administrate-field-state_machine (0.0.1)
4
+ administrate-field-state_machine (0.0.2)
5
5
  administrate (~> 0.3.0)
6
6
  rails (>= 4.2)
7
7
 
data/README.md CHANGED
@@ -4,10 +4,7 @@
4
4
 
5
5
  A plugin to handle [state machine] attributes in [Administrate].
6
6
 
7
- The edit view uses a `<select>` element: if a transition path to the target state exists that state will be selectable,
8
- otherwise it will be disabled.
9
-
10
- **IMPORTANT**
7
+ ## IMPORTANT NOTICE
11
8
  This gem relies on the original resource being passed to the field.
12
9
  This functionality is not yet merged in Administrate
13
10
  ([a PR has been in review for a while](thoughtbot/administrate#381)),
@@ -18,7 +15,7 @@ so you will have to fork and [patch it](https://git.io/vXhCo) yourself.
18
15
  Add it to your `Gemfile`:
19
16
 
20
17
  ```ruby
21
- gem 'administrate-field-state_machine', '~> 0.0.1'
18
+ gem 'administrate-field-state_machine', '~> 0.0.2'
22
19
  ```
23
20
 
24
21
  Run:
@@ -35,6 +32,16 @@ ATTRIBUTE_TYPES = {
35
32
  }.freeze
36
33
  ```
37
34
 
35
+ Add to your `FooController`:
36
+
37
+ ```ruby
38
+ def permitted_attributes
39
+ super + [:state_event]
40
+ end
41
+ ```
42
+
43
+ [`state_event`](https://github.com/state-machines/state_machines#explicit-vs-implicit-event-transitions) is used by the state machine gem to implicitly trigger the event.
44
+
38
45
  ## About
39
46
 
40
47
  Administrate::Field::StateMachine is maintained by [z.productions].
@@ -2,7 +2,7 @@ $:.push File.expand_path('../lib', __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = 'administrate-field-state_machine'
5
- gem.version = '0.0.1'
5
+ gem.version = '0.0.2'
6
6
  gem.authors = ['Michele Gerarduzzi']
7
7
  gem.email = ['michele.gerarduzzi@gmail.com']
8
8
  gem.homepage = 'https://github.com/z-productions/administrate-field-state_machine'
@@ -1,8 +1,8 @@
1
1
  <%#
2
2
  # StateMachine Form Partial
3
3
 
4
- This partial renders a selectable state attribute.
5
- Saving the state will trigger callbacks defined in the state machine
4
+ This partial renders a list of selectable transitions.
5
+ Saving the state will trigger the event callbacks defined in the state machine.
6
6
 
7
7
  ## Local variables:
8
8
 
@@ -20,13 +20,10 @@ Saving the state will trigger callbacks defined in the state machine
20
20
  <%= f.select(
21
21
  :state_event,
22
22
  options_from_collection_for_select(
23
- field.all_states,
24
- :to_s,
25
- :to_s,
26
- {
27
- selected: field.data.presence,
28
- disabled: field.all_states - field.possible_states
29
- }
30
- )
23
+ field.transitions,
24
+ :event,
25
+ ->(transition) { transition.event.to_s.humanize },
26
+ ),
27
+ include_blank: 'Select…'
31
28
  ) %>
32
29
  </div>
@@ -15,12 +15,9 @@ module Administrate
15
15
  data
16
16
  end
17
17
 
18
- def all_states
19
- resource.class.state_machine.states.map(&:name)
20
- end
21
-
22
- def possible_states
23
- resource.state_paths.to_states
18
+ # First-level transitions that can be triggered from the current state
19
+ def transitions
20
+ resource.state_paths.map(&:first).uniq
24
21
  end
25
22
  end
26
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-field-state_machine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michele Gerarduzzi