active_tools 0.0.52 → 0.1.0

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: cfe18a76260474bb133da839b557c81cc8e6aec4
4
- data.tar.gz: 4065dc7f15810a7d8b19068e6d99e09d643b1bda
3
+ metadata.gz: 7cf669472ca4f394eed4f88c701b210297b3cf86
4
+ data.tar.gz: 2b8b57bd4db879100eba570471c62a9ed087bd1d
5
5
  SHA512:
6
- metadata.gz: 4e8f2873d1a32a51440b408200a025ca0c85bb510a04192cd916297869e4f2318903562ebf884f7f7ac5797eae3563e4eb83c8fa188704e86f74c3115ebc5f5d
7
- data.tar.gz: bcff8bd17960012ffb93268c4a56f2606d8c0ab0e652fc397a7152ecdb5fefda16050e42ca95b65e1de698350fd45bd019122fb993379ff4a59f7efeeb42b9f2
6
+ metadata.gz: 21cef49c611aa55c42934206f5fb6c93c9c209a7be14463c7f96376a2a4ecfa8161b6397ef43df8242cbb48d78bb6e1ce90ebc5e148390ba1dc595d233492c3f
7
+ data.tar.gz: e353c911a674cd4a78e6765e8a8b36feb66b9bf9625fa795089a79f52417da31e16b3a3805277564f5a5c15b3096e9fe0017afc5fdde05425e017a284d7e5e56
data/active_tools.gemspec CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |gem|
14
14
 
15
15
  gem.rubyforge_project = "active_tools"
16
16
 
17
- gem.add_runtime_dependency "rails", ">= 4"
17
+ gem.add_runtime_dependency "rails", ">= 5"
18
18
  gem.add_development_dependency "rspec", ">= 0"
19
19
 
20
20
  gem.files = `git ls-files`.split($/)
@@ -8,8 +8,10 @@ module ActiveTools
8
8
  extend ::ActiveSupport::Concern
9
9
 
10
10
  included do
11
- include ComplexHelpers
12
- helper_method :path?, :action?, :controller?, :current_action, :current_controller, :http_referer
11
+ if respond_to?(:helper_method)
12
+ include ComplexHelpers
13
+ helper_method :path?, :action?, :controller?, :current_action, :current_controller, :http_referer
14
+ end
13
15
  end
14
16
 
15
17
  def current_action
@@ -43,11 +43,12 @@ module ActiveTools
43
43
  store_backup!
44
44
  create_template!
45
45
  target.send("#{name}=", value)
46
- owner.send(:clear_attribute_changes, local_attribute) if owner.changes[local_attribute].try(:last) == owner.changes[local_attribute].try(:first)
46
+ owner.send(:attributes_changed_by_setter).except!(local_attribute) if owner.changes[local_attribute].try(:last) == owner.changes[local_attribute].try(:first)
47
47
  if @backup.present? && same_records?(@backup, target, :attributes => @remote_attributes)
48
48
  restore_backup!
49
49
  end
50
50
  end
51
+ value
51
52
  end
52
53
 
53
54
  def try_nullify
@@ -77,20 +78,16 @@ module ActiveTools
77
78
 
78
79
  def try_restore_refreshed_backup
79
80
  if updateable_backup?
80
- warn "Adaptive going to update: <#{@backup.class.name}: #{@backup.class.primary_key}: #{@backup.send(@backup.class.primary_key)}>"
81
+ warn "Adaptive is going to update: <#{@backup.class.name}: #{@backup.class.primary_key}: #{@backup.send(@backup.class.primary_key)}>"
81
82
  @backup.attributes = template_attributes
82
- if @backup.valid?
83
- restore_backup!
84
- true
85
- else
86
- false
87
- end
83
+ restore_backup!
84
+ true
88
85
  end
89
86
  end
90
87
 
91
88
  def try_commit_existed
92
89
  if @template.present? && @uniq_by.any? && (existed = detect_existed) && !(@backup.present? && same_records?(@backup, existed, :attributes => @uniq_by))
93
- warn "Adaptive fetching existed <#{existed.class.name}: #{existed.class.primary_key}: #{existed.send(existed.class.primary_key)}>"
90
+ warn "Adaptive is fetching existed <#{existed.class.name}: #{existed.class.primary_key}: #{existed.send(existed.class.primary_key)}>"
94
91
  self.target = existed
95
92
  if updateable_backup?
96
93
  @backup.mark_for_destruction
@@ -101,7 +98,7 @@ module ActiveTools
101
98
 
102
99
  def try_destroy_backup
103
100
  if destroyable_backup?
104
- warn "Adaptive destroying backed up: <#{@backup.class.name}: #{@backup.class.primary_key}: #{@backup.send(@backup.class.primary_key)}>"
101
+ warn "Adaptive is destroying backed up: <#{@backup.class.name}: #{@backup.class.primary_key}: #{@backup.send(@backup.class.primary_key)}>"
105
102
  begin
106
103
  @backup.destroy
107
104
  rescue ::ActiveRecord::StaleObjectError
@@ -116,7 +113,7 @@ module ActiveTools
116
113
 
117
114
  def try_destroy_target
118
115
  if destroyable_target?
119
- warn "Adaptive destroying target: <#{target.class.name}: #{target.class.primary_key}: #{target.send(target.class.primary_key)}>"
116
+ warn "Adaptive is destroying target: <#{target.class.name}: #{target.class.primary_key}: #{target.send(target.class.primary_key)}>"
120
117
  begin
121
118
  target.destroy
122
119
  rescue ::ActiveRecord::StaleObjectError
@@ -134,15 +131,13 @@ module ActiveTools
134
131
  end
135
132
 
136
133
  def update_target_if_changed!
137
- if target.changes.any?
138
- warn "Adaptive updating: <#{target.class.name}: #{target.class.primary_key}: #{target.send(target.class.primary_key)}>"
134
+ if target && target.changes.any?
135
+ warn "Adaptive is updating: <#{target.class.name}: #{target.class.primary_key}: #{target.send(target.class.primary_key)}>"
139
136
  begin
140
137
  target.save
141
138
  rescue ::ActiveRecord::StaleObjectError
142
- target.reload
143
139
  update_target_if_changed!
144
140
  rescue ::ActiveRecord::StatementInvalid
145
- target.reload
146
141
  update_target_if_changed!
147
142
  end
148
143
  end
@@ -169,26 +164,26 @@ module ActiveTools
169
164
  outer_values.deep_merge!(values[:outer_values])
170
165
  where_values.deep_merge!(values[:where_values])
171
166
  else
172
- where_values[attribute] = @template[attribute] #@template.send(attribute)
167
+ where_values[attribute] = @template[attribute]
173
168
  end
174
169
  end
175
170
  klass.includes(outer_values).where(where_values).limit(1).first
176
171
  end
177
172
 
178
173
  def nullify_target?
179
- target.present? && @nullify_if.try(:call, (target.persisted? ? target.reload : target), owner)
174
+ target.present? && @nullify_if.try(:call, target, owner) # .reload is NOT acceptable (flushes changes)
180
175
  end
181
176
 
182
177
  def updateable_backup?
183
- @backup.try(:persisted?) && @update_if.try(:call, @backup.reload, owner)
178
+ @backup.try(:persisted?) && @update_if.try(:call, @backup.reload, owner) # .reload is acceptable
184
179
  end
185
180
 
186
181
  def destroyable_backup?
187
- @backup.try(:persisted?) && (!@backup.destroyed?||@backup.marked_for_destruction?) && @destroy_if.try(:call, @backup.reload, owner)
182
+ @backup.try(:persisted?) && (!@backup.destroyed?||@backup.marked_for_destruction?) && @destroy_if.try(:call, @backup.reload, owner) # .reload is acceptable
188
183
  end
189
184
 
190
185
  def destroyable_target?
191
- target.try(:persisted?) && (!target.destroyed?||target.marked_for_destruction?) && @destroy_if.try(:call, target.reload, owner)
186
+ target.try(:persisted?) && (!target.destroyed?||target.marked_for_destruction?) && @destroy_if.try(:call, target.reload, owner) # .reload is acceptable
192
187
  end
193
188
 
194
189
  def attributes(object, *attrs)
@@ -215,6 +210,7 @@ module ActiveTools
215
210
  end
216
211
  self.target = @backup
217
212
  @backup = nil
213
+ true
218
214
  end
219
215
  end
220
216
 
@@ -30,10 +30,10 @@ module ActiveTools
30
30
  end
31
31
  if content
32
32
  case request.format
33
- when Mime::JS then
33
+ when Mime[:js] then
34
34
  uniq_content_storage.append_content(content, Misc::DEFAULT_JS_FLOW_KEY)
35
35
  nil
36
- when Mime::HTML then
36
+ when Mime[:html] then
37
37
  volume = options.delete(:volume)
38
38
  unless uniq_content_storage.remembered?(content, volume)
39
39
  flow = uniq_content_storage.remember(content, volume)
@@ -48,7 +48,9 @@ module ActiveTools
48
48
 
49
49
  module OnLoadActionController
50
50
  included do
51
- helper_method :uniq_content_storage
51
+ if respond_to?(:helper_method)
52
+ helper_method :uniq_content_storage
53
+ end
52
54
  end
53
55
 
54
56
  def uniq_content_storage
@@ -1,6 +1,5 @@
1
1
  require 'active_tools/misc/uniq_content'
2
2
  require 'active_tools/misc/script_flow'
3
- require 'active_tools/misc/input_source'
4
3
 
5
4
  module ActiveTools
6
5
  module Misc
@@ -1,3 +1,3 @@
1
1
  module ActiveTools
2
- VERSION = "0.0.52"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.52
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valery Kvon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4'
19
+ version: '5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +100,6 @@ files:
100
100
  - lib/active_tools/core_extension/string_round_with.rb
101
101
  - lib/active_tools/engine.rb
102
102
  - lib/active_tools/misc.rb
103
- - lib/active_tools/misc/input_source.rb
104
103
  - lib/active_tools/misc/script_flow.rb
105
104
  - lib/active_tools/misc/uniq_content.rb
106
105
  - lib/active_tools/railtie.rb
@@ -1,105 +0,0 @@
1
- module ActiveTools
2
- module Misc
3
- module InputSource
4
- module ErrorsExtension
5
- extend ::ActiveSupport::Concern
6
-
7
- included do
8
- delegate :field_of, :to => :@base
9
- end
10
-
11
- def fields
12
- keys.map {|attribute| field_of(attribute)}.compact.tap do |names|
13
- names.instance_eval do
14
- def ids
15
- self.map(&:to_id)
16
- end
17
- end
18
- end
19
- end
20
- end
21
-
22
- module ConverseParameters
23
- def converse_parameters(value, prefix = nil, parent = nil)
24
- case value
25
- when Hash
26
- value.each do |k, v|
27
- new_prefix = prefix ? "#{prefix}[#{k}]" : k
28
- converse_parameters(v, new_prefix, value)
29
- end
30
- when Array
31
- value.each do |e|
32
- new_prefix = "#{prefix}[]"
33
- converse_parameters(e, new_prefix, value)
34
- end
35
- else
36
- value
37
- end
38
- value.tap do |v|
39
- v.singleton_class.send(:undef_method, :belongs_to) if v.respond_to?(:belongs_to)
40
- v.define_singleton_method :belongs_to do
41
- parent
42
- end
43
- v.singleton_class.send(:undef_method, :input_source) if v.respond_to?(:input_source)
44
- v.define_singleton_method :input_source do
45
- prefix.to_s
46
- end
47
- end
48
- end
49
- end
50
-
51
- module RequestExtension
52
- include ConverseParameters
53
-
54
- private
55
- def normalize_parameters(value)
56
- converse_parameters(super)
57
- end
58
- end
59
-
60
- module AttributesAssignment
61
- def assign_attributes(*args)
62
- new_attributes = args.first
63
- if new_attributes.respond_to?(:input_source)
64
- @input_source = new_attributes.input_source
65
- end
66
- super(*args)
67
- end
68
-
69
- def field_of(attribute)
70
- if @input_source && has_attribute?(attribute)
71
- "#{@input_source}[#{attribute}]".tap do |input_source|
72
- input_source.instance_eval do
73
- def to_id
74
- self.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
75
- end
76
- end
77
- end
78
- end
79
- end
80
- end
81
-
82
- end
83
- end
84
-
85
- module OnLoadActionController
86
- ::ActionDispatch::Request.send(:include, Misc::InputSource::RequestExtension)
87
-
88
- def converse(hash, key)
89
- converse_parameters(hash[key], key)
90
- end
91
-
92
- private
93
- include Misc::InputSource::ConverseParameters
94
- end
95
-
96
- module OnLoadActiveRecord
97
- ::ActiveModel::Errors.send(:include, Misc::InputSource::ErrorsExtension)
98
-
99
- if Rails.version >= "3.2.9"
100
- ::ActiveRecord::AttributeAssignment.send(:include, Misc::InputSource::AttributesAssignment)
101
- else
102
- include Misc::InputSource::AttributesAssignment
103
- end
104
- end
105
- end