acts_as_journalized 0.0.2 → 3.3.0

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: d506e23a40b3c83e33a0f05e57154ef7d0eab07e
4
- data.tar.gz: 1afe44e8edbfdd2a9b455311fb6ce506383eb63b
3
+ metadata.gz: 7c8d10075caaaf4ad7612322b5c8ded7da4ad3d0
4
+ data.tar.gz: 953e82d6ed62d7acf4102c28a847b936c027de80
5
5
  SHA512:
6
- metadata.gz: d468aa5e3988a6883d93a3a737eeb8d67521da84512281e4f8a3f0606f78374ddf13097633af361a4d955112c750f48fd3c706fd4db8ef55fcc4958bc537d384
7
- data.tar.gz: 0382efc123e3c44c7000b77ad955b569aaa5dab2ab429ce549a2121c8640d1e417b1bbdb143bba29ccf5500a28f375484d94cd0d56fcc08f72500c860a4e3f17
6
+ metadata.gz: afa57502ebb75851067d7a86a759e0296a1a72ad584f29b4b64f85123e509cb6e8c4049fc47b0eed7ec1ca2320e51fc047b6183daaa227afd71440d1245ce857
7
+ data.tar.gz: b6d439583226d836d278c76b224d1841981434306b3b735e60320617d8ae8ab8e3d1bc78ac38e456e46b6cede0c4d9fc2a10e3bedd398888424dc1808049fd98
data/README.md CHANGED
@@ -20,19 +20,19 @@ Or install it yourself as:
20
20
 
21
21
  ### Model
22
22
 
23
- class MyModel < ActiveRecord::Base
24
- ...
25
- acts_as_journalized
26
- ...
27
- end
23
+ class MyModel < ActiveRecord::Base
24
+ ...
25
+ acts_as_journalized
26
+ ...
27
+ end
28
28
 
29
29
  Or
30
30
 
31
- class MyModel < ActiveRecord::Base
32
- ...
33
- acts_as_journalized name: 'journals', excepted_attributes: [:updated_at, :updated_on], find_options: {}
34
- ...
35
- end
31
+ class MyModel < ActiveRecord::Base
32
+ ...
33
+ acts_as_journalized name: 'journals', excepted_attributes: [:updated_at, :updated_on], find_options: {}
34
+ ...
35
+ end
36
36
 
37
37
  ## Contributing
38
38
 
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Roman Shipiev']
10
10
  spec.email = ['roman@shipiev.pro']
11
11
  spec.summary = %q{Plug-in for Redmine}
12
- spec.description = %q{Used for tracking and recording changes in model attributes}
13
- spec.homepage = 'https://github.com/rubynovich/acts_as_journalized'
12
+ spec.description = %q{Plug-in uses for tracking and recording changes of attributes in model}
13
+ spec.homepage = 'https://github.com/shipiev/acts_as_journalized'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -20,5 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.5'
22
22
  spec.add_development_dependency 'rake'
23
- spec.add_development_dependency 'rails', '3.2.13'
23
+ spec.add_development_dependency 'rails', '~> 4.1.11'
24
24
  end
@@ -3,28 +3,51 @@ module Redmine
3
3
  module Journalized
4
4
  extend ActiveSupport::Concern
5
5
 
6
+ def journalized_attribute_names
7
+ self.class.journalized_attribute_names
8
+ end
9
+
6
10
  module ClassMethods
7
11
  def acts_as_journalized(options = {})
8
- cattr_accessor :journalized_options
12
+ cattr_accessor :journalized_options, :journalized_attribute_names
13
+
14
+ options.assert_valid_keys(
15
+ :excepted_attributes,
16
+ :name,
17
+ :scope,
18
+ :find_options
19
+ )
9
20
 
10
- options.assert_valid_keys(:excepted_attributes, :name, :find_options)
11
- self.journalized_options = {
12
- excepted_attributes: [:updated_at, :updated_on],
13
- name: 'journals',
14
- find_options: {}
15
- }.merge(options)
21
+ excepted_attributes =
22
+ options.delete(:excepted_attributes) || %w(id updated_at updated_on)
16
23
 
17
- find_options = {class_name: 'Journal', as: :journalized, dependent: :destroy}.
18
- merge(self.journalized_options[:find_options])
24
+ self.journalized_attribute_names = column_names - excepted_attributes
19
25
 
20
- has_many self.journalized_options[:name].to_sym, find_options
26
+ self.journalized_options =
27
+ {
28
+ name: 'journals',
29
+ scope: -> { all },
30
+ find_options: {}
31
+ }.merge(options)
32
+
33
+ find_options =
34
+ {
35
+ class_name: 'Journal',
36
+ as: :journalized,
37
+ dependent: :destroy
38
+ }.merge(journalized_options[:find_options])
21
39
 
22
40
  send :include, Redmine::Acts::Journalized::Callbacks
23
41
 
24
- before_update :journalize_attributes
42
+ has_many journalized_options[:name].to_sym,
43
+ journalized_options[:scope],
44
+ find_options
45
+
46
+ after_create :create_journal_on_create
47
+ after_update :create_journal_on_update
25
48
  end
26
49
  end
27
50
 
28
51
  end
29
52
  end
30
- end
53
+ end
@@ -5,23 +5,32 @@ module Redmine
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  def init_journal(user = User.current, notes = '')
8
- @journal ||= send(self.journalized_options[:name]).build(user: user, notes: notes)
8
+ @journal ||= Journal.new(journalized: self, user: user, notes: notes)
9
9
  end
10
10
 
11
- def excepted_attributes
12
- self.class.journalized_options[:excepted_attributes]
11
+ def create_journal_on_create
12
+ if @journal
13
+ @journal.save
14
+ end
13
15
  end
14
16
 
15
- def journalize_attributes(user = User.current, notes = '')
16
- init_journal(user, notes)
17
- changes.except(*excepted_attributes).each_pair do |column, values|
18
- @journal.details.build(property: 'attr', prop_key: column, old_value: values.first, value: values.last)
17
+ def create_journal_on_update
18
+ if @journal && @journal.changed?
19
+ @journal.save
20
+ else
21
+ journalized_changes =
22
+ changes.slice(
23
+ *self.class.journalized_attribute_names
24
+ )
25
+ if journalized_changes.present?
26
+ init_journal
27
+ journalized_changes.each_pair do |column, values|
28
+ @journal.details.build(property: 'attr', prop_key: column, old_value: values.first, value: values.last)
29
+ end
30
+ @journal.save
31
+ end
19
32
  end
20
33
  end
21
-
22
- private :journalize_attributes, :excepted_attributes
23
-
24
- module ClassMethods; end
25
34
  end
26
35
  end
27
36
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsJournalized
2
- VERSION = '0.0.2'
2
+ VERSION = '3.3.0'
3
3
  end
metadata CHANGED
@@ -1,65 +1,65 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_journalized
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Shipiev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-22 00:00:00.000000000 Z
11
+ date: 2017-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '='
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.2.13
47
+ version: 4.1.11
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '='
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.2.13
55
- description: Used for tracking and recording changes in model attributes
54
+ version: 4.1.11
55
+ description: Plug-in uses for tracking and recording changes of attributes in model
56
56
  email:
57
57
  - roman@shipiev.pro
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -69,7 +69,7 @@ files:
69
69
  - lib/acts_as_journalized/acts_as_journalized.rb
70
70
  - lib/acts_as_journalized/callbacks.rb
71
71
  - lib/acts_as_journalized/version.rb
72
- homepage: https://github.com/rubynovich/acts_as_journalized
72
+ homepage: https://github.com/shipiev/acts_as_journalized
73
73
  licenses:
74
74
  - MIT
75
75
  metadata: {}
@@ -79,19 +79,18 @@ require_paths:
79
79
  - lib
80
80
  required_ruby_version: !ruby/object:Gem::Requirement
81
81
  requirements:
82
- - - '>='
82
+ - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
91
  rubyforge_project:
92
- rubygems_version: 2.0.2
92
+ rubygems_version: 2.6.11
93
93
  signing_key:
94
94
  specification_version: 4
95
95
  summary: Plug-in for Redmine
96
96
  test_files: []
97
- has_rdoc: