active_tools 0.0.10 → 0.0.11
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 +4 -4
- data/.DS_Store +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/active_tools/.DS_Store +0 -0
- data/lib/active_tools/action_pack/action_controller/path_helper/complex_helpers.rb +32 -0
- data/lib/active_tools/action_pack/action_controller/path_helper/http_referer.rb +39 -0
- data/lib/active_tools/action_pack/action_view/uniq_content_for.rb +29 -0
- data/lib/active_tools/active_model/valid_with.rb +12 -16
- data/lib/active_tools/active_record/adaptive_belongs_to.rb +18 -8
- data/lib/active_tools/active_record/adaptive_belongs_to/adapter.rb +42 -9
- data/lib/active_tools/active_record/custom_counter_cache/instance_methods.rb +15 -10
- data/lib/active_tools/active_record/with_permalink.rb +92 -0
- data/lib/active_tools/misc/script_flow.rb +3 -2
- data/lib/active_tools/misc/uniq_content.rb +76 -0
- data/lib/active_tools/version.rb +1 -1
- metadata +10 -4
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c3a808736336301eb85cdfd4dcda22dca43306b
|
4
|
+
data.tar.gz: 46ff38509cbc5f40dc83d8afc70a8a04303fcc6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea8c069240fff2daebd6fe87b96fe116e2cb4da2d89083dea00c6a34795136c4ae7fbfcf821a4be0c2775575790721a4f47466603b7ae25f24e790c2324d9319
|
7
|
+
data.tar.gz: adf4bff7c29823e5678a021632403438da55969cc4fbf30bc213123ce6278b58571351ef1cea6ae38fce890af9477a974a779ab0f2bd485d113e6470d7733cd6
|
data/.DS_Store
ADDED
Binary file
|
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActiveTools
|
2
|
+
module ActionPack
|
3
|
+
module ActionController
|
4
|
+
module PathHelper
|
5
|
+
module ComplexHelpers
|
6
|
+
def path?(controller, action = nil)
|
7
|
+
controller?(controller) && action?(action)
|
8
|
+
end
|
9
|
+
|
10
|
+
def action?(action)
|
11
|
+
actions = case action
|
12
|
+
when Array then action.map {|c| c.to_s}
|
13
|
+
when String, Symbol then Array.wrap(action.to_s)
|
14
|
+
else nil
|
15
|
+
end
|
16
|
+
actions.blank? ? true : current_action.in?(actions)
|
17
|
+
end
|
18
|
+
|
19
|
+
def controller?(controller)
|
20
|
+
controllers = case controller
|
21
|
+
when Array then controller.map {|c| c.to_s}
|
22
|
+
when String, Symbol then Array.wrap(controller.to_s)
|
23
|
+
else nil
|
24
|
+
end
|
25
|
+
controllers.blank? ? true : current_controller.in?(controllers)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'active_tools/action_pack/action_controller/path_helper/complex_helpers'
|
2
|
+
|
3
|
+
module ActiveTools
|
4
|
+
module ActionPack
|
5
|
+
module ActionController
|
6
|
+
module PathHelper
|
7
|
+
class HttpReferer
|
8
|
+
attr_reader :url, :recognized
|
9
|
+
include ComplexHelpers
|
10
|
+
|
11
|
+
delegate :[], :to => :recognized
|
12
|
+
|
13
|
+
def initialize(request, environment = {})
|
14
|
+
@url = request.env['HTTP_REFERER']
|
15
|
+
@recognized = begin
|
16
|
+
@url.present? ? Rails.application.routes.recognize_path(@url, environment) : {}
|
17
|
+
rescue ::ActionController::RoutingError
|
18
|
+
{}
|
19
|
+
end
|
20
|
+
@recognized.freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_controller
|
24
|
+
recognized[:controller]
|
25
|
+
end
|
26
|
+
|
27
|
+
def current_action
|
28
|
+
recognized[:action]
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
@url
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'active_tools/misc/uniq_content'
|
2
|
+
|
3
|
+
module ActiveTools
|
4
|
+
module ActionPack
|
5
|
+
module ActionView
|
6
|
+
module UniqContentFor
|
7
|
+
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module OnLoadActionView
|
13
|
+
|
14
|
+
def uniq_content_for(name, content = nil, options = {}, &block)
|
15
|
+
if content || block_given?
|
16
|
+
if block_given?
|
17
|
+
options = content if content
|
18
|
+
content = capture(&block)
|
19
|
+
end
|
20
|
+
if content && !uniq_content_storage.remembered?(content, name)
|
21
|
+
content_for(name, uniq_content_storage.remember(content, name), options)
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -8,9 +8,8 @@ module ActiveTools
|
|
8
8
|
def valid_with(*args)
|
9
9
|
options = args.extract_options!
|
10
10
|
object_name = args.first
|
11
|
-
passed_attr_map = options.delete(:attributes)
|
11
|
+
passed_attr_map = options.delete(:attributes)||{}
|
12
12
|
prefix = options.delete(:prefix)
|
13
|
-
raise(TypeError, "Option :attributes must be a Hash. #{passed_attr_map.class} passed!") unless passed_attr_map.is_a?(Hash)
|
14
13
|
attr_map_name = :"_valid_with_#{object_name}"
|
15
14
|
unless respond_to?(attr_map_name)
|
16
15
|
class_attribute attr_map_name
|
@@ -19,23 +18,20 @@ module ActiveTools
|
|
19
18
|
self.send(attr_map_name).merge!(passed_attr_map)
|
20
19
|
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
21
|
+
validate(*[options]) do
|
22
|
+
if object = send(object_name)
|
23
|
+
if options[:fit] == true
|
24
|
+
object.instance_variable_set(:@errors, ActiveTools::ActiveModel::ValidWith::FakeErrors.new(object))
|
25
|
+
end
|
26
|
+
if !object.valid?
|
27
|
+
object.errors.messages.each do |attribute, suberrors|
|
28
|
+
local_attribute = send(attr_map_name)[attribute]||attribute
|
29
|
+
suberrors.each do |suberror|
|
30
|
+
errors.add([prefix.to_s, local_attribute].select(&:present?).join("_"), suberror)
|
35
31
|
end
|
36
32
|
end
|
37
33
|
end
|
38
|
-
|
34
|
+
end
|
39
35
|
end
|
40
36
|
end
|
41
37
|
end
|
@@ -52,22 +52,22 @@ module ActiveTools
|
|
52
52
|
raise(ArgumentError, ":#{assoc_name} method doesn't look like an association accessor!")
|
53
53
|
end
|
54
54
|
adapter_name = "#{assoc_name}_adaptive"
|
55
|
-
config_name = "#{assoc_name}_adaptive_options"
|
56
55
|
|
57
56
|
raise(TypeError, "Option :attributes must be a Hash. #{options[:attributes].class} passed!") unless options[:attributes].is_a?(Hash)
|
58
57
|
attr_map = options.delete(:attributes).with_indifferent_access
|
59
58
|
|
60
|
-
valid_with assoc_name, :attributes => attr_map
|
59
|
+
valid_with assoc_name, :attributes => attr_map#, :fit => true
|
61
60
|
|
62
|
-
class_attribute
|
63
|
-
self.
|
61
|
+
class_attribute :adaptive_options unless defined?(adaptive_options)
|
62
|
+
self.adaptive_options ||= {}
|
63
|
+
self.adaptive_options[assoc_name.to_sym] = options.merge(:remote_attributes => attr_map.keys)
|
64
64
|
|
65
65
|
class_eval <<-EOV
|
66
66
|
before_validation do
|
67
67
|
#{adapter_name}.try_nullify
|
68
68
|
end
|
69
69
|
|
70
|
-
#{Rails.version >= "4.1.0" ? "
|
70
|
+
#{Rails.version >= "4.1.0" ? "before_validation" : "before_save"} do
|
71
71
|
#{adapter_name}.try_commit
|
72
72
|
end
|
73
73
|
|
@@ -81,7 +81,7 @@ module ActiveTools
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def #{adapter_name}
|
84
|
-
@#{adapter_name} ||= ActiveTools::ActiveRecord::AdaptiveBelongsTo::Adapter.new(
|
84
|
+
@#{adapter_name} ||= ActiveTools::ActiveRecord::AdaptiveBelongsTo::Adapter.new(self, :#{assoc_name}, adaptive_options[:#{assoc_name}])
|
85
85
|
end
|
86
86
|
EOV
|
87
87
|
|
@@ -91,15 +91,25 @@ module ActiveTools
|
|
91
91
|
define_method local_attribute do
|
92
92
|
send(adapter_name).read(remote_attribute)
|
93
93
|
end
|
94
|
-
|
95
94
|
define_method "#{local_attribute}=" do |value|
|
96
95
|
send(adapter_name).write(remote_attribute, value)
|
97
96
|
end
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
101
|
-
end
|
100
|
+
end
|
102
101
|
end
|
102
|
+
|
103
|
+
# def reload(*args)
|
104
|
+
# super.tap do |record|
|
105
|
+
# adaptive_options.keys.each do |assoc_name|
|
106
|
+
# puts assoc_name
|
107
|
+
# adapter_name = "#{assoc_name}_adaptive"
|
108
|
+
# eval("@#{adapter_name}.try(:replace_association, association(:#{assoc_name}))")
|
109
|
+
# end
|
110
|
+
# end
|
111
|
+
# end
|
112
|
+
|
103
113
|
end
|
104
114
|
end
|
105
115
|
|
@@ -2,12 +2,13 @@ module ActiveTools
|
|
2
2
|
module ActiveRecord
|
3
3
|
module AdaptiveBelongsTo
|
4
4
|
class Adapter
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :owner, :assoc_name, :options
|
6
6
|
|
7
|
-
delegate :target, :target_id, :
|
7
|
+
delegate :target, :target_id, :reflection, :to => :association
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@
|
9
|
+
def initialize(owner, assoc_name, options = {})
|
10
|
+
@owner = owner
|
11
|
+
@assoc_name = assoc_name
|
11
12
|
@options = options.with_indifferent_access
|
12
13
|
@foreign_key = reflection.foreign_key
|
13
14
|
@remote_attributes = @options[:remote_attributes]
|
@@ -16,7 +17,15 @@ module ActiveTools
|
|
16
17
|
@update_if = @options[:update_if]
|
17
18
|
@destroy_if = @options[:destroy_if]
|
18
19
|
@uniq_by = Array(@options[:uniq_by]).map(&:to_s)
|
19
|
-
|
20
|
+
association.load_target
|
21
|
+
end
|
22
|
+
|
23
|
+
def klass
|
24
|
+
association.klass||reflection.class_name.constantize
|
25
|
+
end
|
26
|
+
|
27
|
+
def association
|
28
|
+
owner.association(assoc_name)
|
20
29
|
end
|
21
30
|
|
22
31
|
def read(name)
|
@@ -43,7 +52,7 @@ module ActiveTools
|
|
43
52
|
end
|
44
53
|
end
|
45
54
|
|
46
|
-
def try_commit
|
55
|
+
def try_commit
|
47
56
|
try_commit_existed || try_update
|
48
57
|
end
|
49
58
|
|
@@ -52,13 +61,24 @@ module ActiveTools
|
|
52
61
|
try_destroy_target
|
53
62
|
end
|
54
63
|
|
64
|
+
def template_attributes
|
65
|
+
attributes(@template, *@remote_attributes)
|
66
|
+
end
|
67
|
+
|
68
|
+
def target_attributes
|
69
|
+
attributes(target, *@remote_attributes)
|
70
|
+
end
|
71
|
+
|
55
72
|
def try_update
|
56
73
|
if updateable_backup?
|
57
74
|
begin
|
58
|
-
@backup.update(
|
75
|
+
@backup.update(template_attributes)
|
59
76
|
rescue ::ActiveRecord::StaleObjectError
|
60
77
|
@backup.reload
|
61
78
|
try_update
|
79
|
+
rescue ::ActiveRecord::StatementInvalid
|
80
|
+
@backup.reload
|
81
|
+
try_update
|
62
82
|
end
|
63
83
|
self.target = @backup
|
64
84
|
end
|
@@ -81,6 +101,9 @@ module ActiveTools
|
|
81
101
|
rescue ::ActiveRecord::StaleObjectError
|
82
102
|
@backup.reload
|
83
103
|
try_destroy_backup
|
104
|
+
rescue ::ActiveRecord::StatementInvalid
|
105
|
+
@backup.reload
|
106
|
+
try_destroy_backup
|
84
107
|
end
|
85
108
|
end
|
86
109
|
end
|
@@ -92,6 +115,9 @@ module ActiveTools
|
|
92
115
|
rescue ::ActiveRecord::StaleObjectError
|
93
116
|
target.reload
|
94
117
|
try_destroy_target
|
118
|
+
rescue ::ActiveRecord::StatementInvalid
|
119
|
+
target.reload
|
120
|
+
try_destroy_target
|
95
121
|
end
|
96
122
|
end
|
97
123
|
end
|
@@ -136,7 +162,14 @@ module ActiveTools
|
|
136
162
|
end
|
137
163
|
|
138
164
|
def attributes(object, *attrs)
|
139
|
-
|
165
|
+
array = attrs.map do |a|
|
166
|
+
begin
|
167
|
+
[a, object.send(a)]
|
168
|
+
rescue NoMethodError
|
169
|
+
nil
|
170
|
+
end
|
171
|
+
end.compact
|
172
|
+
Hash[array]
|
140
173
|
end
|
141
174
|
|
142
175
|
def create_template!
|
@@ -191,7 +224,7 @@ module ActiveTools
|
|
191
224
|
def template
|
192
225
|
@template ||=
|
193
226
|
if target.try(:persisted?)
|
194
|
-
klass.new(
|
227
|
+
klass.new(target_attributes)
|
195
228
|
elsif target.nil?
|
196
229
|
klass.new
|
197
230
|
elsif target.try(:new_record?)
|
@@ -12,10 +12,8 @@ module ActiveTools
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def custom_counter_cache_before_destroy(assoc_name, reflection, assoc_mapping)
|
15
|
-
foreign_key
|
16
|
-
|
17
|
-
record = send(assoc_name)
|
18
|
-
if record && !self.destroyed?
|
15
|
+
unless destroyed_by_association && (destroyed_by_association.foreign_key.to_sym == reflection.foreign_key.to_sym)
|
16
|
+
if (record = send(assoc_name)) && !self.destroyed?
|
19
17
|
ActiveRecord::CustomCounterCache.digger(self, record, assoc_mapping) do |parent, cache_column, value|
|
20
18
|
parent.class.update_counters(parent.id, cache_column => -value)
|
21
19
|
end
|
@@ -24,20 +22,27 @@ module ActiveTools
|
|
24
22
|
end
|
25
23
|
|
26
24
|
def custom_counter_cache_after_update(assoc_name, reflection, assoc_mapping)
|
27
|
-
|
25
|
+
record_changed =
|
26
|
+
if reflection.polymorphic?
|
27
|
+
send(:attribute_changed?, reflection.foreign_type)||send(:attribute_changed?, reflection.foreign_key)
|
28
|
+
else
|
29
|
+
send(:attribute_changed?, reflection.foreign_key) && defined?(reflection.klass.to_s.camelize)
|
30
|
+
end
|
31
|
+
|
28
32
|
if (@_after_create_custom_counter_called ||= false)
|
29
33
|
@_after_create_custom_counter_called = false
|
30
|
-
elsif
|
31
|
-
model = reflection.klass
|
32
|
-
|
33
|
-
foreign_key = attribute
|
34
|
+
elsif !new_record? && record_changed
|
35
|
+
model = reflection.polymorphic? ? attribute(reflection.foreign_type).try(:constantize) : reflection.klass
|
36
|
+
model_was = reflection.polymorphic? ? attribute_was(reflection.foreign_type).try(:constantize) : reflection.klass
|
37
|
+
foreign_key = attribute(reflection.foreign_key)
|
38
|
+
foreign_key_was = attribute_was(reflection.foreign_key)
|
34
39
|
|
35
40
|
if foreign_key && model.respond_to?(:increment_counter) && to_increment = model.find_by_id(foreign_key)
|
36
41
|
ActiveRecord::CustomCounterCache.digger(self, to_increment, assoc_mapping) do |parent, cache_column, value|
|
37
42
|
parent.class.update_counters(parent.id, cache_column => value)
|
38
43
|
end
|
39
44
|
end
|
40
|
-
if foreign_key_was &&
|
45
|
+
if foreign_key_was && model_was.respond_to?(:decrement_counter) && to_decrement = model_was.find_by_id(foreign_key_was)
|
41
46
|
ActiveRecord::CustomCounterCache.digger(self, to_decrement, assoc_mapping) do |parent, cache_column, value|
|
42
47
|
parent.class.update_counters(parent.id, cache_column => -value)
|
43
48
|
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module ActiveTools
|
2
|
+
module ActiveRecord
|
3
|
+
module WithPermalink
|
4
|
+
extend ::ActiveSupport::Concern
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def with_permalink(*args)
|
8
|
+
options = args.extract_options!
|
9
|
+
unless (column_name = args.first.to_sym) || options[:from].present?
|
10
|
+
raise "WithPermalink: column_name and/or options[:from] expected!"
|
11
|
+
end
|
12
|
+
|
13
|
+
options[:uniq] ||= true
|
14
|
+
|
15
|
+
cattr_accessor :with_permalink_options unless defined?(with_permalink_options)
|
16
|
+
self.with_permalink_options ||= {}
|
17
|
+
self.with_permalink_options[column_name] = options
|
18
|
+
|
19
|
+
validates_presence_of column_name
|
20
|
+
validates_uniqueness_of column_name, options[:scope] ? {:scope => Array(options[:scope])} : {}
|
21
|
+
|
22
|
+
before_validation do
|
23
|
+
self.with_permalink_options.each do |column_name, options|
|
24
|
+
eval <<-EOV
|
25
|
+
source = @_#{column_name}_demanded
|
26
|
+
EOV
|
27
|
+
source ||= case options[:from]
|
28
|
+
when String, Symbol then send(options[:from])
|
29
|
+
when Proc then options[:from].call(self)
|
30
|
+
end
|
31
|
+
if options[:uniq]
|
32
|
+
self.send("#{column_name}=", generate_permalink(column_name, source, options))
|
33
|
+
else
|
34
|
+
self.send("#{column_name}=", source)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
after_save do
|
40
|
+
instance_variable_set(:"@_#{column_name}_demanded", nil)
|
41
|
+
end
|
42
|
+
|
43
|
+
class_eval <<-EOV
|
44
|
+
def #{column_name}=(value)
|
45
|
+
@_#{column_name}_demanded = value if value.present?
|
46
|
+
super(value)
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_param
|
50
|
+
changes["#{column_name}"].try(:first)||#{column_name}
|
51
|
+
end
|
52
|
+
EOV
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def generate_permalink(column_name, permalink, options = {})
|
58
|
+
tester, correction = permalink, 0
|
59
|
+
while exists_permalink?(column_name, tester, options)
|
60
|
+
correction += 1
|
61
|
+
tester = [permalink, correction].select(&:present?).join("-")
|
62
|
+
end
|
63
|
+
tester
|
64
|
+
end
|
65
|
+
|
66
|
+
def exists_permalink?(column_name, permalink, options = {})
|
67
|
+
sql_clause, values = [], []
|
68
|
+
sql_clause << "#{column_name} = ?"
|
69
|
+
values << permalink
|
70
|
+
if options[:scope]
|
71
|
+
Array(options[:scope]).each do |field|
|
72
|
+
if value = send(field)
|
73
|
+
sql_clause << "#{field} = ?"
|
74
|
+
values << value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
if persisted?
|
79
|
+
sql_clause << "id != ?"
|
80
|
+
values << self.id
|
81
|
+
end
|
82
|
+
self.class.exists?([sql_clause.join(" AND "), *values])
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
module OnLoadActiveRecord
|
89
|
+
include ActiveRecord::WithPermalink
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -29,8 +29,9 @@ module ActiveTools
|
|
29
29
|
uniq_content_storage.append_content(content, Misc::DEFAULT_JS_FLOW_KEY)
|
30
30
|
nil
|
31
31
|
when Mime::HTML then
|
32
|
-
|
33
|
-
|
32
|
+
volume = options.delete(:volume)
|
33
|
+
unless uniq_content_storage.remembered?(content, volume)
|
34
|
+
flow = uniq_content_storage.remember(content, volume)
|
34
35
|
options[:javascript_tag] == false ? flow : javascript_tag(flow, options)
|
35
36
|
end
|
36
37
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module ActiveTools
|
2
|
+
module Misc
|
3
|
+
module UniqContent
|
4
|
+
class Storage
|
5
|
+
attr_reader :content
|
6
|
+
|
7
|
+
delegate :any?, :empty?, :to => :content
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@content = ::ActiveSupport::OrderedHash.new {|h,k| h[k] = []}
|
11
|
+
@hashes = ::ActiveSupport::OrderedHash.new {|h,k| h[k] = []}
|
12
|
+
end
|
13
|
+
|
14
|
+
# Called by _layout_for to read stored values.
|
15
|
+
def get_content(key = nil)
|
16
|
+
@content[key]
|
17
|
+
end
|
18
|
+
|
19
|
+
# Called by each renderer object to set the layout contents.
|
20
|
+
def set_content(value, key = nil)
|
21
|
+
@content[key] = Array(value)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Called by content_for
|
25
|
+
def append_content(value, key = nil)
|
26
|
+
@content[key] |= Array(value)
|
27
|
+
end
|
28
|
+
alias_method :append_content!, :append_content
|
29
|
+
|
30
|
+
def render_content(key = nil)
|
31
|
+
@content[key].join("\n").html_safe
|
32
|
+
end
|
33
|
+
|
34
|
+
def remember(value, key = nil)
|
35
|
+
unless remembered?(value, key)
|
36
|
+
@hashes[key] << value.hash
|
37
|
+
value
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def remembered?(value, key = nil)
|
42
|
+
@hashes[key].include?(value.hash)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module OnLoadActionController
|
50
|
+
included do
|
51
|
+
helper_method :uniq_content_storage
|
52
|
+
end
|
53
|
+
|
54
|
+
def uniq_content_storage
|
55
|
+
@_uniq_content_storage ||= Misc::UniqContent::Storage.new
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
module OnLoadActionView
|
60
|
+
def uniq_content(*args, &block)
|
61
|
+
options = args.extract_options!
|
62
|
+
content = args.first
|
63
|
+
if content || block_given?
|
64
|
+
if block_given?
|
65
|
+
content = capture(&block)
|
66
|
+
end
|
67
|
+
if content && !uniq_content_storage.remembered?(content, options[:volume])
|
68
|
+
uniq_content_storage.remember(content, options[:volume])
|
69
|
+
else
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
data/lib/active_tools/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valery Kvon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -45,23 +45,27 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- ".DS_Store"
|
48
49
|
- ".gitignore"
|
49
|
-
- ".ruby-gemset"
|
50
|
-
- ".ruby-version"
|
51
50
|
- Gemfile
|
52
51
|
- LICENSE.txt
|
53
52
|
- README.md
|
54
53
|
- Rakefile
|
55
54
|
- active_tools.gemspec
|
56
55
|
- copy
|
56
|
+
- lib/.DS_Store
|
57
57
|
- lib/active_tools.rb
|
58
|
+
- lib/active_tools/.DS_Store
|
58
59
|
- lib/active_tools/action_pack/action_controller.rb
|
59
60
|
- lib/active_tools/action_pack/action_controller/path_helper.rb
|
61
|
+
- lib/active_tools/action_pack/action_controller/path_helper/complex_helpers.rb
|
62
|
+
- lib/active_tools/action_pack/action_controller/path_helper/http_referer.rb
|
60
63
|
- lib/active_tools/action_pack/action_dispatch.rb
|
61
64
|
- lib/active_tools/action_pack/action_dispatch/flash_stack.rb
|
62
65
|
- lib/active_tools/action_pack/action_view.rb
|
63
66
|
- lib/active_tools/action_pack/action_view/perform_as_tree.rb
|
64
67
|
- lib/active_tools/action_pack/action_view/tag_attributes.rb
|
68
|
+
- lib/active_tools/action_pack/action_view/uniq_content_for.rb
|
65
69
|
- lib/active_tools/actionpack.rb
|
66
70
|
- lib/active_tools/active_model/delegate_attributes.rb
|
67
71
|
- lib/active_tools/active_model/valid_with.rb
|
@@ -71,6 +75,7 @@ files:
|
|
71
75
|
- lib/active_tools/active_record/custom_counter_cache.rb
|
72
76
|
- lib/active_tools/active_record/custom_counter_cache/instance_methods.rb
|
73
77
|
- lib/active_tools/active_record/record_id.rb
|
78
|
+
- lib/active_tools/active_record/with_permalink.rb
|
74
79
|
- lib/active_tools/activemodel.rb
|
75
80
|
- lib/active_tools/activerecord.rb
|
76
81
|
- lib/active_tools/activesupport.rb
|
@@ -89,6 +94,7 @@ files:
|
|
89
94
|
- lib/active_tools/misc.rb
|
90
95
|
- lib/active_tools/misc/input_source.rb
|
91
96
|
- lib/active_tools/misc/script_flow.rb
|
97
|
+
- lib/active_tools/misc/uniq_content.rb
|
92
98
|
- lib/active_tools/railtie.rb
|
93
99
|
- lib/active_tools/version.rb
|
94
100
|
- spec/active_tools/active_model/delegate_attributes_spec.rb
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
delegate_attributes
|
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby-2.0.0-p247
|