piko-smart-pkg 0.0.1

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.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/paper_trail-17.0.0/LICENSE +20 -0
  3. data/paper_trail-17.0.0/lib/generators/paper_trail/install/USAGE +31 -0
  4. data/paper_trail-17.0.0/lib/generators/paper_trail/install/install_generator.rb +249 -0
  5. data/paper_trail-17.0.0/lib/generators/paper_trail/install/templates/add_object_changes_to_versions.rb.erb +12 -0
  6. data/paper_trail-17.0.0/lib/generators/paper_trail/install/templates/create_versions.rb.erb +41 -0
  7. data/paper_trail-17.0.0/lib/generators/paper_trail/migration_generator.rb +65 -0
  8. data/paper_trail-17.0.0/lib/generators/paper_trail/update_item_subtype/USAGE +4 -0
  9. data/paper_trail-17.0.0/lib/generators/paper_trail/update_item_subtype/templates/update_versions_for_item_subtype.rb.erb +86 -0
  10. data/paper_trail-17.0.0/lib/generators/paper_trail/update_item_subtype/update_item_subtype_generator.rb +40 -0
  11. data/paper_trail-17.0.0/lib/paper_trail/attribute_serializers/README.md +10 -0
  12. data/paper_trail-17.0.0/lib/paper_trail/attribute_serializers/attribute_serializer_factory.rb +41 -0
  13. data/paper_trail-17.0.0/lib/paper_trail/attribute_serializers/cast_attribute_serializer.rb +51 -0
  14. data/paper_trail-17.0.0/lib/paper_trail/attribute_serializers/object_attribute.rb +48 -0
  15. data/paper_trail-17.0.0/lib/paper_trail/attribute_serializers/object_changes_attribute.rb +51 -0
  16. data/paper_trail-17.0.0/lib/paper_trail/cleaner.rb +60 -0
  17. data/paper_trail-17.0.0/lib/paper_trail/compatibility.rb +51 -0
  18. data/paper_trail-17.0.0/lib/paper_trail/config.rb +41 -0
  19. data/paper_trail-17.0.0/lib/paper_trail/errors.rb +33 -0
  20. data/paper_trail-17.0.0/lib/paper_trail/events/base.rb +343 -0
  21. data/paper_trail-17.0.0/lib/paper_trail/events/create.rb +32 -0
  22. data/paper_trail-17.0.0/lib/paper_trail/events/destroy.rb +42 -0
  23. data/paper_trail-17.0.0/lib/paper_trail/events/update.rb +76 -0
  24. data/paper_trail-17.0.0/lib/paper_trail/frameworks/active_record/models/paper_trail/version.rb +16 -0
  25. data/paper_trail-17.0.0/lib/paper_trail/frameworks/active_record.rb +12 -0
  26. data/paper_trail-17.0.0/lib/paper_trail/frameworks/cucumber.rb +33 -0
  27. data/paper_trail-17.0.0/lib/paper_trail/frameworks/rails/controller.rb +103 -0
  28. data/paper_trail-17.0.0/lib/paper_trail/frameworks/rails/railtie.rb +34 -0
  29. data/paper_trail-17.0.0/lib/paper_trail/frameworks/rails.rb +3 -0
  30. data/paper_trail-17.0.0/lib/paper_trail/frameworks/rspec/helpers.rb +29 -0
  31. data/paper_trail-17.0.0/lib/paper_trail/frameworks/rspec.rb +42 -0
  32. data/paper_trail-17.0.0/lib/paper_trail/has_paper_trail.rb +92 -0
  33. data/paper_trail-17.0.0/lib/paper_trail/model_config.rb +257 -0
  34. data/paper_trail-17.0.0/lib/paper_trail/queries/versions/where_attribute_changes.rb +50 -0
  35. data/paper_trail-17.0.0/lib/paper_trail/queries/versions/where_object.rb +65 -0
  36. data/paper_trail-17.0.0/lib/paper_trail/queries/versions/where_object_changes.rb +70 -0
  37. data/paper_trail-17.0.0/lib/paper_trail/queries/versions/where_object_changes_from.rb +57 -0
  38. data/paper_trail-17.0.0/lib/paper_trail/queries/versions/where_object_changes_to.rb +57 -0
  39. data/paper_trail-17.0.0/lib/paper_trail/record_history.rb +51 -0
  40. data/paper_trail-17.0.0/lib/paper_trail/record_trail.rb +342 -0
  41. data/paper_trail-17.0.0/lib/paper_trail/reifier.rb +147 -0
  42. data/paper_trail-17.0.0/lib/paper_trail/request.rb +163 -0
  43. data/paper_trail-17.0.0/lib/paper_trail/serializers/json.rb +36 -0
  44. data/paper_trail-17.0.0/lib/paper_trail/serializers/yaml.rb +68 -0
  45. data/paper_trail-17.0.0/lib/paper_trail/type_serializers/postgres_array_serializer.rb +35 -0
  46. data/paper_trail-17.0.0/lib/paper_trail/version_concern.rb +406 -0
  47. data/paper_trail-17.0.0/lib/paper_trail/version_number.rb +23 -0
  48. data/paper_trail-17.0.0/lib/paper_trail.rb +138 -0
  49. data/piko-smart-pkg.gemspec +12 -0
  50. metadata +89 -0
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "paper_trail/events/base"
4
+
5
+ module PaperTrail
6
+ module Events
7
+ # See docs in `Base`.
8
+ #
9
+ # @api private
10
+ class Create < Base
11
+ # Return attributes of nascent `Version` record.
12
+ #
13
+ # @api private
14
+ def data
15
+ data = {
16
+ item: @record,
17
+ event: @record.paper_trail_event || "create",
18
+ whodunnit: PaperTrail.request.whodunnit
19
+ }
20
+ if @record.respond_to?(:updated_at)
21
+ data[:created_at] = @record.updated_at
22
+ end
23
+ if record_object_changes? && changed_notably?
24
+ changes = notable_changes
25
+ data[:object_changes] = prepare_object_changes(changes)
26
+ end
27
+ merge_item_subtype_into(data)
28
+ merge_metadata_into(data)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "paper_trail/events/base"
4
+
5
+ module PaperTrail
6
+ module Events
7
+ # See docs in `Base`.
8
+ #
9
+ # @api private
10
+ class Destroy < Base
11
+ # Return attributes of nascent `Version` record.
12
+ #
13
+ # @api private
14
+ def data
15
+ data = {
16
+ item_id: @record.id,
17
+ item_type: @record.class.base_class.name,
18
+ event: @record.paper_trail_event || "destroy",
19
+ whodunnit: PaperTrail.request.whodunnit
20
+ }
21
+ if record_object?
22
+ data[:object] = recordable_object(false)
23
+ end
24
+ if record_object_changes?
25
+ data[:object_changes] = prepare_object_changes(notable_changes)
26
+ end
27
+ merge_item_subtype_into(data)
28
+ merge_metadata_into(data)
29
+ end
30
+
31
+ private
32
+
33
+ # Rails' implementation (eg. `@record.saved_changes`) returns nothing on
34
+ # destroy, so we have to build the hash we want.
35
+ #
36
+ # @override
37
+ def changes_in_latest_version
38
+ @record.attributes.transform_values { |value| [value, nil] }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "paper_trail/events/base"
4
+
5
+ module PaperTrail
6
+ module Events
7
+ # See docs in `Base`.
8
+ #
9
+ # @api private
10
+ class Update < Base
11
+ # - is_touch - [boolean] - Used in the two situations that are touch-like:
12
+ # - `after_touch` we call `RecordTrail#record_update`
13
+ # - force_changes - [Hash] - Only used by `RecordTrail#update_columns`,
14
+ # because there dirty-tracking is off, so it has to track its own changes.
15
+ #
16
+ # @api private
17
+ def initialize(record, in_after_callback, is_touch, force_changes)
18
+ super(record, in_after_callback)
19
+ @is_touch = is_touch
20
+ @force_changes = force_changes
21
+ end
22
+
23
+ # Return attributes of nascent `Version` record.
24
+ #
25
+ # @api private
26
+ def data
27
+ data = {
28
+ item: @record,
29
+ event: @record.paper_trail_event || "update",
30
+ whodunnit: PaperTrail.request.whodunnit
31
+ }
32
+ if record_object?
33
+ data[:object] = recordable_object(@is_touch)
34
+ end
35
+ merge_object_changes_into(data)
36
+ merge_item_subtype_into(data)
37
+ merge_metadata_into(data)
38
+ end
39
+
40
+ # If it is a touch event, and changed are empty, it is assumed to be
41
+ # implicit `touch` mutation, and will a version is created.
42
+ #
43
+ # See https://github.com/rails/rails/commit/dcb825902d79d0f6baba956f7c6ec5767611353e
44
+ #
45
+ # @api private
46
+ def changed_notably?
47
+ if @is_touch && changes_in_latest_version.empty?
48
+ true
49
+ else
50
+ super
51
+ end
52
+ end
53
+
54
+ private
55
+
56
+ # @api private
57
+ def merge_object_changes_into(data)
58
+ if record_object_changes?
59
+ changes = @force_changes.nil? ? notable_changes : @force_changes
60
+ data[:object_changes] = prepare_object_changes(changes)
61
+ end
62
+ end
63
+
64
+ # `touch` cannot record `object_changes` because rails' `touch` does not
65
+ # perform dirty-tracking. Specifically, methods from `Dirty`, like
66
+ # `saved_changes`, return the same values before and after `touch`.
67
+ #
68
+ # See https://github.com/rails/rails/issues/33429
69
+ #
70
+ # @api private
71
+ def record_object_changes?
72
+ !@is_touch && super
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "paper_trail/version_concern"
4
+
5
+ module PaperTrail
6
+ # This is the default ActiveRecord model provided by PaperTrail. Most simple
7
+ # applications will use this model as-is, but it is possible to sub-class,
8
+ # extend, or even do without this model entirely. See documentation section
9
+ # 6.a. Custom Version Classes.
10
+ #
11
+ # The paper_trail-association_tracking gem provides a related model,
12
+ # `VersionAssociation`.
13
+ class Version < ::ActiveRecord::Base
14
+ include PaperTrail::VersionConcern
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Either ActiveRecord has already been loaded by the Lazy Load Hook in our
4
+ # Railtie, or else we load it now.
5
+ require "active_record"
6
+ PaperTrail::Compatibility.check_activerecord(ActiveRecord.gem_version)
7
+
8
+ # Now we can load the parts of PT that depend on AR.
9
+ require "paper_trail/has_paper_trail"
10
+ require "paper_trail/reifier"
11
+ require "paper_trail/frameworks/active_record/models/paper_trail/version"
12
+ ActiveRecord::Base.include PaperTrail::Model
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # before hook for Cucumber
4
+ Before do
5
+ PaperTrail.enabled = false
6
+ PaperTrail.request.enabled = true
7
+ PaperTrail.request.whodunnit = nil
8
+ PaperTrail.request.controller_info = {} if defined?(Rails)
9
+ end
10
+
11
+ module PaperTrail
12
+ module Cucumber
13
+ # Helper method for enabling PT in Cucumber features.
14
+ module Extensions
15
+ # :call-seq:
16
+ # with_versioning
17
+ #
18
+ # enable versioning for specific blocks
19
+
20
+ def with_versioning
21
+ was_enabled = ::PaperTrail.enabled?
22
+ ::PaperTrail.enabled = true
23
+ begin
24
+ yield
25
+ ensure
26
+ ::PaperTrail.enabled = was_enabled
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ World PaperTrail::Cucumber::Extensions
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaperTrail
4
+ module Rails
5
+ # Extensions to rails controllers. Provides convenient ways to pass certain
6
+ # information to the model layer, with `controller_info` and `whodunnit`.
7
+ # Also includes a convenient on/off switch,
8
+ # `paper_trail_enabled_for_controller`.
9
+ module Controller
10
+ def self.included(controller)
11
+ controller.before_action(
12
+ :set_paper_trail_enabled_for_controller,
13
+ :set_paper_trail_controller_info
14
+ )
15
+ end
16
+
17
+ protected
18
+
19
+ # Returns the user who is responsible for any changes that occur.
20
+ # By default this calls `current_user` and returns the result.
21
+ #
22
+ # Override this method in your controller to call a different
23
+ # method, e.g. `current_person`, or anything you like.
24
+ #
25
+ # @api public
26
+ def user_for_paper_trail
27
+ return unless defined?(current_user)
28
+ current_user.try(:id) || current_user
29
+ end
30
+
31
+ # Returns any information about the controller or request that you
32
+ # want PaperTrail to store alongside any changes that occur. By
33
+ # default this returns an empty hash.
34
+ #
35
+ # Override this method in your controller to return a hash of any
36
+ # information you need. The hash's keys must correspond to columns
37
+ # in your `versions` table, so don't forget to add any new columns
38
+ # you need.
39
+ #
40
+ # For example:
41
+ #
42
+ # {:ip => request.remote_ip, :user_agent => request.user_agent}
43
+ #
44
+ # The columns `ip` and `user_agent` must exist in your `versions` # table.
45
+ #
46
+ # Use the `:meta` option to
47
+ # `PaperTrail::Model::ClassMethods.has_paper_trail` to store any extra
48
+ # model-level data you need.
49
+ #
50
+ # @api public
51
+ def info_for_paper_trail
52
+ {}
53
+ end
54
+
55
+ # Returns `true` (default) or `false` depending on whether PaperTrail
56
+ # should be active for the current request.
57
+ #
58
+ # Override this method in your controller to specify when PaperTrail
59
+ # should be off.
60
+ #
61
+ # ```
62
+ # def paper_trail_enabled_for_controller
63
+ # # Don't omit `super` without a good reason.
64
+ # super && request.user_agent != 'Disable User-Agent'
65
+ # end
66
+ # ```
67
+ #
68
+ # @api public
69
+ def paper_trail_enabled_for_controller
70
+ ::PaperTrail.enabled?
71
+ end
72
+
73
+ private
74
+
75
+ # Tells PaperTrail whether versions should be saved in the current
76
+ # request.
77
+ #
78
+ # @api public
79
+ def set_paper_trail_enabled_for_controller
80
+ ::PaperTrail.request.enabled = paper_trail_enabled_for_controller
81
+ end
82
+
83
+ # Tells PaperTrail who is responsible for any changes that occur.
84
+ #
85
+ # @api public
86
+ def set_paper_trail_whodunnit
87
+ if ::PaperTrail.request.enabled?
88
+ ::PaperTrail.request.whodunnit = user_for_paper_trail
89
+ end
90
+ end
91
+
92
+ # Tells PaperTrail any information from the controller you want to store
93
+ # alongside any changes that occur.
94
+ #
95
+ # @api public
96
+ def set_paper_trail_controller_info
97
+ if ::PaperTrail.request.enabled?
98
+ ::PaperTrail.request.controller_info = info_for_paper_trail
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaperTrail
4
+ # Represents code to load within Rails framework. See documentation in
5
+ # `railties/lib/rails/railtie.rb`.
6
+ # @api private
7
+ class Railtie < ::Rails::Railtie
8
+ # PaperTrail only has one initializer.
9
+ #
10
+ # We specify `before: "load_config_initializers"` to ensure that the PT
11
+ # initializer happens before "app initializers" (those defined in
12
+ # the app's `config/initalizers`).
13
+ initializer "paper_trail", before: "load_config_initializers" do |app|
14
+ # `on_load` is a "lazy load hook". It "declares a block that will be
15
+ # executed when a Rails component is fully loaded". (See
16
+ # `active_support/lazy_load_hooks.rb`)
17
+ ActiveSupport.on_load(:action_controller) do
18
+ require "paper_trail/frameworks/rails/controller"
19
+
20
+ # Mix our extensions into `ActionController::Base`, which is `self`
21
+ # because of the `class_eval` in `lazy_load_hooks.rb`.
22
+ include PaperTrail::Rails::Controller
23
+ end
24
+
25
+ ActiveSupport.on_load(:active_record) do
26
+ require "paper_trail/frameworks/active_record"
27
+ end
28
+
29
+ if Gem::Version.new(::Rails::VERSION::STRING) >= Gem::Version.new("7.1")
30
+ app.deprecators[:paper_trail] = PaperTrail.deprecator
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "paper_trail/frameworks/rails/railtie"
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PaperTrail
4
+ module RSpec
5
+ module Helpers
6
+ # Included in the RSpec configuration in `frameworks/rspec.rb`
7
+ module InstanceMethods
8
+ # enable versioning for specific blocks (at instance-level)
9
+ def with_versioning
10
+ was_enabled = ::PaperTrail.enabled?
11
+ ::PaperTrail.enabled = true
12
+ yield
13
+ ensure
14
+ ::PaperTrail.enabled = was_enabled
15
+ end
16
+ end
17
+
18
+ # Extended by the RSpec configuration in `frameworks/rspec.rb`
19
+ module ClassMethods
20
+ # enable versioning for specific blocks (at class-level)
21
+ def with_versioning(&block)
22
+ context "with versioning", versioning: true do
23
+ class_exec(&block)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/core"
4
+ require "rspec/matchers"
5
+ require "paper_trail/frameworks/rspec/helpers"
6
+
7
+ RSpec.configure do |config|
8
+ config.include PaperTrail::RSpec::Helpers::InstanceMethods
9
+ config.extend PaperTrail::RSpec::Helpers::ClassMethods
10
+
11
+ config.before(:each) do
12
+ PaperTrail.enabled = false
13
+ PaperTrail.request.enabled = true
14
+ PaperTrail.request.whodunnit = nil
15
+ PaperTrail.request.controller_info = {} if defined?(Rails) && defined?(RSpec::Rails)
16
+ end
17
+
18
+ config.before(:each, versioning: true) do
19
+ PaperTrail.enabled = true
20
+ end
21
+ end
22
+
23
+ RSpec::Matchers.define :be_versioned do
24
+ # check to see if the model has `has_paper_trail` declared on it
25
+ match { |actual| actual.is_a?(PaperTrail::Model::InstanceMethods) }
26
+ end
27
+
28
+ RSpec::Matchers.define :have_a_version_with do |attributes|
29
+ # check if the model has a version with the specified attributes
30
+ match do |actual|
31
+ versions_association = actual.class.versions_association_name
32
+ actual.send(versions_association).where_object(attributes).any?
33
+ end
34
+ end
35
+
36
+ RSpec::Matchers.define :have_a_version_with_changes do |attributes|
37
+ # check if the model has a version changes with the specified attributes
38
+ match do |actual|
39
+ versions_association = actual.class.versions_association_name
40
+ actual.send(versions_association).where_object_changes(attributes).any?
41
+ end
42
+ end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "paper_trail/attribute_serializers/object_attribute"
4
+ require "paper_trail/attribute_serializers/object_changes_attribute"
5
+ require "paper_trail/model_config"
6
+ require "paper_trail/record_trail"
7
+
8
+ module PaperTrail
9
+ # Extensions to `ActiveRecord::Base`. See `frameworks/active_record.rb`.
10
+ # It is our goal to have the smallest possible footprint here, because
11
+ # `ActiveRecord::Base` is a very crowded namespace! That is why we introduced
12
+ # `.paper_trail` and `#paper_trail`.
13
+ module Model
14
+ def self.included(base)
15
+ base.extend ClassMethods
16
+ end
17
+
18
+ # :nodoc:
19
+ module ClassMethods
20
+ # Declare this in your model to track every create, update, and destroy.
21
+ # Each version of the model is available in the `versions` association.
22
+ #
23
+ # Options:
24
+ #
25
+ # - :on - The events to track (optional; defaults to all of them). Set
26
+ # to an array of `:create`, `:update`, `:destroy` and `:touch` as desired.
27
+ # - :class_name (deprecated) - The name of a custom Version class that
28
+ # includes `PaperTrail::VersionConcern`.
29
+ # - :ignore - An array of attributes for which a new `Version` will not be
30
+ # created if only they change. It can also accept a Hash as an
31
+ # argument where the key is the attribute to ignore (a `String` or
32
+ # `Symbol`), which will only be ignored if the value is a `Proc` which
33
+ # returns truthily.
34
+ # - :if, :unless - Procs that allow to specify conditions when to save
35
+ # versions for an object.
36
+ # - :only - Inverse of `ignore`. A new `Version` will be created only
37
+ # for these attributes if supplied it can also accept a Hash as an
38
+ # argument where the key is the attribute to track (a `String` or
39
+ # `Symbol`), which will only be counted if the value is a `Proc` which
40
+ # returns truthily.
41
+ # - :skip - Fields to ignore completely. As with `ignore`, updates to
42
+ # these fields will not create a new `Version`. In addition, these
43
+ # fields will not be included in the serialized versions of the object
44
+ # whenever a new `Version` is created.
45
+ # - :meta - A hash of extra data to store. You must add a column to the
46
+ # `versions` table for each key. Values are objects or procs (which
47
+ # are called with `self`, i.e. the model with the paper trail). See
48
+ # `PaperTrail::Controller.info_for_paper_trail` for how to store data
49
+ # from the controller.
50
+ # - :versions - Either,
51
+ # - A String (deprecated) - The name to use for the versions
52
+ # association. Default is `:versions`.
53
+ # - A Hash - options passed to `has_many`, plus `name:` and `scope:`.
54
+ # - :version - The name to use for the method which returns the version
55
+ # the instance was reified from. Default is `:version`.
56
+ # - :synchronize_version_creation_timestamp - By default, paper trail
57
+ # sets the `created_at` field for a new Version equal to the `updated_at`
58
+ # column of the model being updated. If you instead want `created_at` to
59
+ # populate with the current timestamp, set this option to `false`.
60
+ #
61
+ # Plugins like the experimental `paper_trail-association_tracking` gem
62
+ # may accept additional options.
63
+ #
64
+ # You can define a default set of options via the configurable
65
+ # `PaperTrail.config.has_paper_trail_defaults` hash in your applications
66
+ # initializer. The hash can contain any of the following options and will
67
+ # provide an overridable default for all models.
68
+ #
69
+ # @api public
70
+ def has_paper_trail(options = {})
71
+ raise Error, "has_paper_trail must be called only once" if self < InstanceMethods
72
+
73
+ defaults = PaperTrail.config.has_paper_trail_defaults
74
+ paper_trail.setup(defaults.merge(options))
75
+ end
76
+
77
+ # @api public
78
+ def paper_trail
79
+ ::PaperTrail::ModelConfig.new(self)
80
+ end
81
+ end
82
+
83
+ # Wrap the following methods in a module so we can include them only in the
84
+ # ActiveRecord models that declare `has_paper_trail`.
85
+ module InstanceMethods
86
+ # @api public
87
+ def paper_trail
88
+ ::PaperTrail::RecordTrail.new(self)
89
+ end
90
+ end
91
+ end
92
+ end