statesman_mongoid 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 12b141e7bcaf520970181af415dcdfe5256b148573fd01e3a4639d6585811f97
4
+ data.tar.gz: 536f5ef0cd30da45fa1abb42ff78fcb80f1be5362fa57257c515580d32676c9a
5
+ SHA512:
6
+ metadata.gz: 836739d3e0bc37bebcb07a509bf4e5609715545b3aa564954999d6da5823a0f2442e0f60ef1756e1ce47163a6d1481e284c1591608b6c8f9376f30293fda4805
7
+ data.tar.gz: 90d396cfbec77f2e354970e214a7f845e5dac8bbeac546ac2262a41cead4abe11da8d9485e3aa9dcdfc576d538c60b66fbc5059cdddcc8cc9da88a2bac18caed
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in statesman_mongoid.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ statesman_mongoid (0.1.1)
5
+ statesman (~> 10.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ rake (13.0.6)
11
+ statesman (10.2.2)
12
+
13
+ PLATFORMS
14
+ x86_64-linux
15
+
16
+ DEPENDENCIES
17
+ rake (~> 13.0)
18
+ statesman_mongoid!
19
+
20
+ BUNDLED WITH
21
+ 2.3.7
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 oz-tal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Statesman Mongoid
2
+
3
+ Restored mongoid adapters for the Statesman gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'statesman_mongoid'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install statesman_mongoid
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/statesman_mongoid.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,67 @@
1
+ # Restored mongoid support, untouched
2
+ # Extracted from commit b9906ee1cf0ac6c1bbdd56c003ffe407c2f59833
3
+
4
+ module Statesman
5
+ module Adapters
6
+ class Mongoid
7
+ attr_reader :transition_class
8
+ attr_reader :parent_model
9
+
10
+ def initialize(transition_class, parent_model, observer, _opts = {})
11
+ @transition_class = transition_class
12
+ @parent_model = parent_model
13
+ @observer = observer
14
+ unless transition_class_hash_fields.include?("statesman_metadata")
15
+ raise UnserializedMetadataError, metadata_field_error_message
16
+ end
17
+ end
18
+
19
+ def create(from, to, metadata = {})
20
+ from = from.to_s
21
+ to = to.to_s
22
+ transition = transitions_for_parent.build(to_state: to,
23
+ sort_key: next_sort_key,
24
+ statesman_metadata: metadata)
25
+
26
+ @observer.execute(:before, from, to, transition)
27
+ transition.save!
28
+ @last_transition = transition
29
+ @observer.execute(:after, from, to, transition)
30
+ @observer.execute(:after_commit, from, to, transition)
31
+ transition
32
+ ensure
33
+ @last_transition = nil
34
+ end
35
+
36
+ def history(*)
37
+ transitions_for_parent.asc(:sort_key)
38
+ end
39
+
40
+ def last(force_reload: false)
41
+ if force_reload
42
+ @last_transition = history.last
43
+ else
44
+ @last_transition ||= history.last
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def transition_class_hash_fields
51
+ transition_class.fields.select { |_, v| v.type == Hash }.keys
52
+ end
53
+
54
+ def metadata_field_error_message
55
+ "#{transition_class.name}#statesman_metadata is not of type 'Hash'"
56
+ end
57
+
58
+ def transitions_for_parent
59
+ @parent_model.send(@transition_class.collection_name)
60
+ end
61
+
62
+ def next_sort_key
63
+ (last && last.sort_key + 10) || 10
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,23 @@
1
+ # Restored mongoid support, fixes applied: concernized the module and added includes + fields
2
+ # Extracted from commit b9906ee1cf0ac6c1bbdd56c003ffe407c2f59833
3
+
4
+ module Statesman
5
+ module Adapters
6
+ module MongoidTransition
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ include ::Mongoid::Document
11
+ include ::Mongoid::Timestamps
12
+
13
+ field :to_state, type: String
14
+ field :statesman_metadata, type: Hash
15
+ field :sort_key, type: Integer
16
+ field :most_recent, type: ::Mongoid::Boolean
17
+
18
+ self.send(:alias_method, :metadata, :statesman_metadata)
19
+ self.send(:alias_method, :metadata=, :statesman_metadata=)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StatesmanMongoid
4
+ VERSION = "0.1.1"
5
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "statesman_mongoid/version"
4
+ require_relative "statesman/adapters/mongoid"
5
+ require_relative "statesman/adapters/mongoid_transition"
6
+
7
+ module StatesmanMongoid
8
+ class Error < StandardError; end
9
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/statesman_mongoid/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "statesman_mongoid"
7
+ spec.version = StatesmanMongoid::VERSION
8
+ spec.authors = ["oz-tal"]
9
+ spec.email = ["979951+oz-tal@users.noreply.github.com"]
10
+
11
+ spec.summary = "Mongoid adapters for Statesman"
12
+ spec.homepage = "https://github.com/oz-tal/statesman_mongoid"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/oz-tal/statesman_mongoid"
18
+ spec.metadata["changelog_uri"] = "https://github.com/oz-tal/statesman_mongoid"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
25
+ end
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ spec.add_dependency "statesman", "~> 10.0"
33
+
34
+ # For more information and examples about making a new gem, check out our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statesman_mongoid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - oz-tal
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: statesman
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ description:
28
+ email:
29
+ - 979951+oz-tal@users.noreply.github.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - Gemfile.lock
36
+ - LICENSE.txt
37
+ - README.md
38
+ - Rakefile
39
+ - lib/statesman/adapters/mongoid.rb
40
+ - lib/statesman/adapters/mongoid_transition.rb
41
+ - lib/statesman_mongoid.rb
42
+ - lib/statesman_mongoid/version.rb
43
+ - statesman_mongoid.gemspec
44
+ homepage: https://github.com/oz-tal/statesman_mongoid
45
+ licenses:
46
+ - MIT
47
+ metadata:
48
+ homepage_uri: https://github.com/oz-tal/statesman_mongoid
49
+ source_code_uri: https://github.com/oz-tal/statesman_mongoid
50
+ changelog_uri: https://github.com/oz-tal/statesman_mongoid
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 2.6.0
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.3.7
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: Mongoid adapters for Statesman
70
+ test_files: []