rails_core_extensions 0.7.0 → 0.11.0.beta.11

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
  SHA256:
3
- metadata.gz: 76094dd88c18760346576faf8e2f43e77fa292c833bb8902cb9865aba56371da
4
- data.tar.gz: 40249dfbe47be586f8dc55af8d8d3cba6b7a2605e2e1064c1c1b84851f5568d9
3
+ metadata.gz: 5ccb364109694e5146403ee03a9083c0702aa442e8e57a0c7530c7729f74a33b
4
+ data.tar.gz: 69b3dcaa3c1b31d2bb896d934bbd173e79f1506b1e1c590fce7a96525bd3a9f7
5
5
  SHA512:
6
- metadata.gz: 2298db57d113a3faa06be3e0626c63a489c0c2ca9ae525b8a69c51d4c5137d60805b3582ee12335e8f0d2bdc6e30fc08a6dcd442e70fa229ddaa9f8fde3a02da
7
- data.tar.gz: 65fc675533679d6aeebf6b6437d004da18a1bde67c59051b4e0b3e6cc8e400bfb4b6bf49e808028e9ce9ae1aeefe6412617a26aa2d1b592dd9acbf71b1b06dd8
6
+ metadata.gz: 3cbdd58723a57b2230f74ba5ec42a91256e2ab2152d30c84e271b15cab8a2e910b40adacef32ce48aca90bd372ddddd2cc9a4d0909af04b03942993f4a69af4c
7
+ data.tar.gz: c6ad9dd46a34fc8680f681fa19f8b4e412e4df4c90ff167cd126dbb8c6b89d2a4757c01ff235ceb37030ce87165485ef19252a62d649761307ad1e899fadb0b0
@@ -0,0 +1,25 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ release:
5
+ types: [created]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build + Publish
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - uses: ruby/setup-ruby@v1
15
+
16
+ - name: Publish to RubyGems
17
+ run: |
18
+ mkdir -p $HOME/.gem
19
+ touch $HOME/.gem/credentials
20
+ chmod 0600 $HOME/.gem/credentials
21
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
22
+ gem build *.gemspec
23
+ gem push *.gem
24
+ env:
25
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,45 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - name: Checkout
13
+ uses: actions/checkout@v2
14
+
15
+ - name: Generate Changelog
16
+ run: |
17
+ # Get version from github ref (remove 'refs/tags/' and prefix 'v')
18
+ version="${GITHUB_REF#refs/tags/v}"
19
+ npx changelog-parser CHANGELOG.md | jq -cr ".versions | .[] | select(.version == \"$version\") | .body" > ${{ github.workflow }}-CHANGELOG.txt
20
+
21
+ - name: Release
22
+ uses: softprops/action-gh-release@v1
23
+ with:
24
+ body_path: ${{ github.workflow }}-CHANGELOG.txt
25
+ env:
26
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27
+
28
+ publish:
29
+ name: Publish
30
+ runs-on: ubuntu-latest
31
+
32
+ steps:
33
+ - uses: actions/checkout@v2
34
+ - uses: ruby/setup-ruby@v1
35
+
36
+ - name: Publish to RubyGems
37
+ run: |
38
+ mkdir -p $HOME/.gem
39
+ touch $HOME/.gem/credentials
40
+ chmod 0600 $HOME/.gem/credentials
41
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
42
+ gem build *.gemspec
43
+ gem push *.gem
44
+ env:
45
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,19 @@
1
+ name: Build
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ gemfile: [rails60, rails61]
9
+ ruby: ["2.6", "2.7", "3.0"]
10
+ runs-on: ubuntu-latest
11
+ env:
12
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ bundler-cache: true
19
+ - run: bundle exec rake
@@ -1 +1 @@
1
- 2.5.5
1
+ 3.0.0
@@ -1,19 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4
4
- - 2.5
5
- matrix:
6
- exclude:
7
- - rvm: 2.4
8
- gemfile: gemfiles/rails6.gemfile
3
+ - 2.6
4
+ - 2.7
9
5
 
10
6
  script: "bundle exec rake spec"
11
7
  gemfile:
12
- - gemfiles/rails5.gemfile
13
8
  - gemfiles/rails6.gemfile
14
9
  sudo: false
15
10
  cache: bundler
16
- # Due to this issue, stil not resolved: travis-ci/travis-ci#8969
17
11
  before_install:
18
12
  - gem update --system
19
13
  - gem install bundler
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.0.beta.11
4
+
5
+ * [TT-] Switch from travis to gihthub actions
6
+ * [TT-] Add support for Rails 6.1 / Ruby 3
7
+
8
+ ## 0.10.0
9
+
10
+ * [TT-8507] Sortable will now fire callbacks to ensure we audit these changes
11
+
12
+ ## 0.9.0
13
+
14
+ * [TT-6727] Fix usage of symbolize_keys in sortable
15
+
16
+ ## 0.8.0
17
+
18
+ * [TT-6539] Remove cache_all_attributes and other unused methods
19
+ * [TT-5384] Remove validates_presence_of_parent method (Use rails optional flag instead)
20
+ * [TT-6293] Drop breadcrumbs / cache without host and some unused view helpers
21
+
22
+ ## 0.7.1
23
+
24
+ * [TT-5745] Fix passing of symbol to liquid template parse
25
+
3
26
  ## 0.7.0
4
27
 
5
28
  * [TT-5745] Update Liquid validate to be v4 compatible
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => '../'
3
+
4
+ group :development, :test do
5
+ gem 'activerecord', '~> 6.0'
6
+ end
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ gemspec :path => '../'
3
+
4
+ group :development, :test do
5
+ gem 'activerecord', '~> 6.1'
6
+ end
@@ -1,9 +1,5 @@
1
1
  module RailsCoreExtensions
2
2
  require 'rails_core_extensions/sortable'
3
- require 'rails_core_extensions/action_view_currency_extensions'
4
- require 'rails_core_extensions/action_view_has_many_extensions'
5
- require 'rails_core_extensions/action_view_extensions'
6
- require 'rails_core_extensions/breadcrumb'
7
3
  require 'rails_core_extensions/position_initializer'
8
4
  require 'rails_core_extensions/time_with_zone'
9
5
  require 'rails_core_extensions/transfer_records'
@@ -13,32 +9,32 @@ module RailsCoreExtensions
13
9
  require 'rails_core_extensions/railtie' if defined?(Rails)
14
10
 
15
11
  if defined? ActionController
16
- require 'rails_core_extensions/caches_action_without_host'
17
12
  require 'rails_core_extensions/activatable'
18
13
  require 'rails_core_extensions/action_controller_sortable'
19
14
 
20
- ActionController::Base.send(:include, CachesActionWithoutHost)
21
15
  ActionController::Base.send(:include, Activatable)
22
16
  ActionController::Base.send(:include, ActionControllerSortable)
23
17
  end
24
18
 
19
+ if defined? ActionView
20
+ require 'rails_core_extensions/action_view_extensions'
21
+ require 'rails_core_extensions/action_view_has_many_extensions'
22
+
23
+ ActionView::Base.send(:include, RailsCoreExtensions::ActionViewExtensions)
24
+ end
25
+
25
26
  if defined? ActiveRecord
26
27
  require 'rails_core_extensions/active_record_cloning'
27
- require 'rails_core_extensions/active_record_cache_all_attributes'
28
28
  require 'rails_core_extensions/active_record_extensions'
29
29
  require 'rails_core_extensions/active_record_liquid_extensions'
30
30
  require 'rails_core_extensions/translations'
31
+ require 'rails_core_extensions/active_model_extensions'
31
32
 
32
33
  ActiveRecord::Base.send(:include, ActiveRecordCloning)
33
34
  ActiveRecord::Base.send(:include, ActiveRecordExtensions)
34
35
  ActiveRecord::Base.send(:include, RailsCoreExtensions::ActiveRecordLiquidExtensions)
35
36
  ActiveRecord::Base.send(:include, ActiveRecordExtensions::InstanceMethods)
36
37
  ActiveRecord::Base.send(:include, RailsCoreExtensions::Translations)
37
-
38
- if ActiveRecord::VERSION::MAJOR >= 3
39
- require 'rails_core_extensions/active_model_extensions'
40
- ActiveRecord::Base.send(:include, ActiveModelExtensions::Validations)
41
- end
38
+ ActiveRecord::Base.send(:include, ActiveModelExtensions::Validations)
42
39
  end
43
40
  end
44
-
@@ -4,25 +4,6 @@ module RailsCoreExtensions
4
4
  super(h(content)).html_safe
5
5
  end
6
6
 
7
- # Will recursively parse a Hash and any sub hashes to be normal hashes
8
- # This is useful when exporting hashes to non ruby systems, which don't understand HashWithIndifferentAccess
9
- def hashify(element)
10
- if element.is_a? Hash
11
- element = element.to_hash if element.is_a?(HashWithIndifferentAccess)
12
- element.each_pair do |key, value|
13
- element[key] = hashify(value)
14
- end
15
- else
16
- # Must hashify enumerables encase their sub items are hashes
17
- # Can't enumerate through string as it returns strings, which are also enumerable (stack level too deep)
18
- if element.respond_to?(:each) && !element.is_a?(String)
19
- element.map{ |sub| hashify(sub) }
20
- else
21
- element
22
- end
23
- end
24
- end
25
-
26
7
  # Generates a tooltip with given text
27
8
  # text is textilized before display
28
9
  def tooltip(hover_element_id, text, title='')
@@ -34,21 +15,6 @@ module RailsCoreExtensions
34
15
  "</script>"
35
16
  end
36
17
 
37
- def expandable_list_for(objects, show = 4)
38
- first, others = objects[0..(show-1)], objects[show..(objects.size-1)]
39
- first.each do |o|
40
- yield o
41
- end
42
- if others
43
- content_tag 'div', :id => 'others', :style => 'display: none' do
44
- others.each do |o|
45
- yield o
46
- end
47
- end
48
- "#{others.size} Others - ".html_safe + link_to_function("Show/Hide", "$('others').toggle()")
49
- end
50
- end
51
-
52
18
  def boolean_select_tag(name, *args)
53
19
  options = args.extract_options!
54
20
  options ||= {}
@@ -58,5 +24,3 @@ module RailsCoreExtensions
58
24
  end
59
25
  end
60
26
  end
61
-
62
- ActionView::Base.send(:include, RailsCoreExtensions::ActionViewExtensions) if defined?(ActionView::Base)
@@ -11,37 +11,6 @@ module ActiveRecordExtensions
11
11
  establish_connection("#{key}_#{Rails.env}")
12
12
  end
13
13
 
14
- def cache_all_attributes(options = {})
15
- method = options[:by] || 'id'
16
- class_eval <<-CACHE
17
- after_save :clear_attribute_cache
18
- after_destroy :clear_attribute_cache
19
- cattr_accessor :cache_attributes_by
20
- self.cache_attributes_by = '#{method}'
21
- CACHE
22
- extend ActiveRecordCacheAllAttributes::ClassMethods
23
- include ActiveRecordCacheAllAttributes::InstanceMethods
24
- end
25
-
26
- # Create a new object from the attributes passed in
27
- # OR update an existing
28
- #
29
- # If an :id attribute is present it will assume it's an existing record, and needs update
30
- def new_or_update!(hash={}, options = {:hard_update => true})
31
- hash.symbolize_keys!
32
- if hash[:id].blank?
33
- self.new(hash)
34
- else
35
- rec = self.find(hash[:id])
36
- if options[:hard_update]
37
- rec.update_attributes!(hash.except(:id))
38
- else
39
- rec.update_attributes(hash.except(:id))
40
- end
41
- rec
42
- end
43
- end
44
-
45
14
  def enum_int(field, values, options = {})
46
15
  const_set("#{field.to_s.upcase}_OPTIONS", values)
47
16
 
@@ -101,49 +70,13 @@ module ActiveRecordExtensions
101
70
  reload
102
71
  #{collection}.sort_by(&:position).each_with_index do |o, index|
103
72
  if o.position != (index + 1)
104
- o.update_attribute(:position, index + 1)
73
+ o.update(:position, index + 1)
105
74
  end
106
75
  end
107
76
  end
108
77
  EVAL
109
78
  end
110
79
  end
111
-
112
- # Validates presence of -- but works on parent within accepts_nested_attributes
113
- #
114
- def validates_presence_of_parent(foreign_key)
115
- after_save do |record|
116
- unless record.send(foreign_key)
117
- record.errors.add_on_blank(foreign_key)
118
- raise ActiveRecord::ActiveRecordError, record.errors.full_messages.to_sentence
119
- end
120
- end
121
- end
122
-
123
- # Run a block, being respectful of connection pools
124
- #
125
- # Useful for when you're not in the standard rails request process,
126
- # since normally rails will take, then clear you're connection in the
127
- # processing of the request.
128
- #
129
- # If you don't do this in, say, a command line task with threads, then
130
- # you'll run out of connections after 5 x Threads are run simultaneously...
131
- def with_connection_pooling
132
- # Verify active connections and remove and disconnect connections
133
- # associated with stale threads.
134
- ActiveRecord::Base.verify_active_connections!
135
-
136
- yield
137
-
138
- # This code checks in the connection being used by the current thread back
139
- # into the connection pool. It repeats this if you are using multiple
140
- # connection pools. It will not disconnect the connection.
141
- #
142
- # Returns any connections in use by the current thread back to the pool,
143
- # and also returns connections to the pool cached by threads that are no
144
- # longer alive.
145
- ActiveRecord::Base.clear_active_connections!
146
- end
147
80
  end
148
81
 
149
82
  module InstanceMethods
@@ -10,7 +10,7 @@ module RailsCoreExtensions
10
10
  field = field.to_sym
11
11
  before_validation do |record|
12
12
  begin
13
- Liquid::Template.parse(record.send(field), error_mode: strict)
13
+ Liquid::Template.parse(record.send(field), error_mode: :strict)
14
14
  rescue Liquid::SyntaxError => e
15
15
  record.errors.add(field, "Liquid Syntax Error: #{e}")
16
16
  end
@@ -8,7 +8,7 @@ module RailsCoreExtensions
8
8
  # category_id (or whatever the name of scope is)
9
9
  # model_1_body (or whatever id of scope id)
10
10
  def initialize(params, controller_name)
11
- @params = params.symbolize_keys
11
+ @params = params.permit!.to_h.symbolize_keys
12
12
  @controller_name = controller_name
13
13
  @klass = controller_name.classify.constantize
14
14
  end
@@ -43,7 +43,7 @@ module RailsCoreExtensions
43
43
  end
44
44
 
45
45
  def update(object, new_position)
46
- @klass.where(id: object.id).limit(1).update_all(position: new_position)
46
+ @klass.find(object.id).update(position: new_position)
47
47
  end
48
48
  end
49
49
  end
@@ -6,7 +6,7 @@ module RailsCoreExtensions
6
6
 
7
7
  module ClassMethods
8
8
  def translate(key, options = {})
9
- I18n.translate key, options.merge(scope: translation_key)
9
+ I18n.translate key, **options.merge(scope: translation_key)
10
10
  end
11
11
 
12
12
  def translation_key
@@ -1,3 +1,3 @@
1
1
  module RailsCoreExtensions
2
- VERSION = '0.7.0'
2
+ VERSION = '0.11.0.beta.11'
3
3
  end
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'activerecord', ['>= 5.0.0']
23
- spec.add_dependency 'actionpack', ['>= 5.0.0']
22
+ spec.add_dependency 'activerecord', ['>= 6.0.0']
23
+ spec.add_dependency 'actionpack', ['>= 6.0.0']
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 2.0'
26
26
  spec.add_development_dependency 'rake'
@@ -32,8 +32,4 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'rubocop'
33
33
  spec.add_development_dependency 'sqlite3'
34
34
  spec.add_development_dependency 'travis'
35
-
36
- # breadcrumbs optional dependencies
37
- spec.add_development_dependency 'make_resourceful'
38
- spec.add_development_dependency 'inherited_resources'
39
35
  end
@@ -26,7 +26,7 @@ describe RailsCoreExtensions::Sortable do
26
26
  models.each(&:destroy)
27
27
  end
28
28
 
29
- subject { RailsCoreExtensions::Sortable.new(params, 'models') }
29
+ subject { RailsCoreExtensions::Sortable.new(ActionController::Parameters.new(params), 'models') }
30
30
 
31
31
  RSpec.shared_examples 'unscoped' do
32
32
  let(:scope) { Model.reorder(:position) }
@@ -68,25 +68,6 @@ describe 'enum_int' do
68
68
  end
69
69
  end
70
70
 
71
- describe "ActiveRecord::Base" do
72
- let(:mock_model) { double }
73
- let(:model_class) { Class.new(ActiveRecord::Base) }
74
- before { stub_const 'Model', model_class }
75
-
76
- it "should create a new record if new_or_update! is passed a hash without an :id" do
77
- attributes = {:fake_column => 'nothing really'}
78
- expect(Model).to receive(:new).with(attributes)
79
- Model.new_or_update!(attributes)
80
- end
81
-
82
- it "should update record if new_or_update! is passed hash with :id" do
83
- attributes = {:fake_column => 'nothing really', :id => 1}
84
- expect(Model).to receive(:find) { mock_model }
85
- expect(mock_model).to receive(:update_attributes!)
86
- Model.new_or_update!(attributes)
87
- end
88
- end
89
-
90
71
  describe RailsCoreExtensions::ActionControllerSortable do
91
72
  class NormalController < ActionController::Base
92
73
  end
@@ -101,38 +82,3 @@ describe RailsCoreExtensions::ActionControllerSortable do
101
82
  expect(SortableController.new.methods.map(&:to_sym)).to include(:sort)
102
83
  end
103
84
  end
104
-
105
- describe ActiveRecordExtensions do
106
- let(:model_class) {
107
- Class.new(ActiveRecord::Base) do
108
- cache_all_attributes :by => 'name'
109
- end
110
- }
111
- let(:first) { Model.create!(:name => 'First') }
112
- let(:second) { Model.create!(:name => 'Second') }
113
- let(:expected) {
114
- {
115
- 'First' => first.attributes,
116
- 'Second' => second.attributes
117
- }
118
- }
119
-
120
- before do
121
- connect_to_sqlite
122
- stub_const 'Model', model_class
123
- allow(Model).to receive(:cache) { ActiveSupport::Cache::MemoryStore.new }
124
- allow(Model).to receive(:should_cache?) { true }
125
- [first, second]
126
- end
127
-
128
- it 'should cache all attributes' do
129
- # Test underlying generate attributes hash method works
130
- expect(Model.generate_attributes_hash).to eq expected
131
- expect(Model.attribute_cache).to eq expected
132
-
133
- # Test after save/destroy it updates
134
- first.destroy
135
- expect(Model.attribute_cache).to eq 'Second' => second.attributes
136
- second.destroy # Clean up after
137
- end
138
- end
@@ -1,4 +1,5 @@
1
1
  require 'simplecov-rcov'
2
2
  require 'coveralls'
3
3
  require 'coverage/kit'
4
- Coverage::Kit.setup(minimum_coverage: 81.3)
4
+
5
+ Coverage::Kit.setup(minimum_coverage: 86.7)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_core_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.11.0.beta.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Noack
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-12 00:00:00.000000000 Z
12
+ date: 2021-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 5.0.0
20
+ version: 6.0.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 5.0.0
27
+ version: 6.0.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: actionpack
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: 5.0.0
34
+ version: 6.0.0
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: 5.0.0
41
+ version: 6.0.0
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -179,34 +179,6 @@ dependencies:
179
179
  - - ">="
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
- - !ruby/object:Gem::Dependency
183
- name: make_resourceful
184
- requirement: !ruby/object:Gem::Requirement
185
- requirements:
186
- - - ">="
187
- - !ruby/object:Gem::Version
188
- version: '0'
189
- type: :development
190
- prerelease: false
191
- version_requirements: !ruby/object:Gem::Requirement
192
- requirements:
193
- - - ">="
194
- - !ruby/object:Gem::Version
195
- version: '0'
196
- - !ruby/object:Gem::Dependency
197
- name: inherited_resources
198
- requirement: !ruby/object:Gem::Requirement
199
- requirements:
200
- - - ">="
201
- - !ruby/object:Gem::Version
202
- version: '0'
203
- type: :development
204
- prerelease: false
205
- version_requirements: !ruby/object:Gem::Requirement
206
- requirements:
207
- - - ">="
208
- - !ruby/object:Gem::Version
209
- version: '0'
210
182
  description: Set of extensions to core rails libraries.
211
183
  email:
212
184
  - support@travellink.com.au
@@ -214,6 +186,9 @@ executables: []
214
186
  extensions: []
215
187
  extra_rdoc_files: []
216
188
  files:
189
+ - ".github/workflows/gem-push.yml"
190
+ - ".github/workflows/release.yml"
191
+ - ".github/workflows/ruby.yml"
217
192
  - ".gitignore"
218
193
  - ".hound.yml"
219
194
  - ".rspec"
@@ -225,22 +200,18 @@ files:
225
200
  - LICENSE.txt
226
201
  - README.md
227
202
  - Rakefile
228
- - gemfiles/rails5.gemfile
229
- - gemfiles/rails6.gemfile
203
+ - gemfiles/rails60.gemfile
204
+ - gemfiles/rails61.gemfile
230
205
  - lib/rails_core_extensions.rb
231
206
  - lib/rails_core_extensions/action_controller_sortable.rb
232
- - lib/rails_core_extensions/action_view_currency_extensions.rb
233
207
  - lib/rails_core_extensions/action_view_extensions.rb
234
208
  - lib/rails_core_extensions/action_view_has_many_extensions.rb
235
209
  - lib/rails_core_extensions/activatable.rb
236
210
  - lib/rails_core_extensions/active_model_extensions.rb
237
- - lib/rails_core_extensions/active_record_cache_all_attributes.rb
238
211
  - lib/rails_core_extensions/active_record_cloning.rb
239
212
  - lib/rails_core_extensions/active_record_extensions.rb
240
213
  - lib/rails_core_extensions/active_record_liquid_extensions.rb
241
214
  - lib/rails_core_extensions/active_support_concern.rb
242
- - lib/rails_core_extensions/breadcrumb.rb
243
- - lib/rails_core_extensions/caches_action_without_host.rb
244
215
  - lib/rails_core_extensions/concurrency.rb
245
216
  - lib/rails_core_extensions/position_initializer.rb
246
217
  - lib/rails_core_extensions/railtie.rb
@@ -256,7 +227,6 @@ files:
256
227
  - spec/active_model_extensions_spec.rb
257
228
  - spec/active_record_cloning_spec.rb
258
229
  - spec/active_record_extensions_spec.rb
259
- - spec/breadcrumb_spec.rb
260
230
  - spec/concurrency_spec.rb
261
231
  - spec/en.yml
262
232
  - spec/position_initializer_spec.rb
@@ -281,12 +251,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
281
251
  version: '0'
282
252
  required_rubygems_version: !ruby/object:Gem::Requirement
283
253
  requirements:
284
- - - ">="
254
+ - - ">"
285
255
  - !ruby/object:Gem::Version
286
- version: '0'
256
+ version: 1.3.1
287
257
  requirements: []
288
- rubyforge_project:
289
- rubygems_version: 2.7.6.2
258
+ rubygems_version: 3.2.3
290
259
  signing_key:
291
260
  specification_version: 4
292
261
  summary: Set of extensions to core rails libraries.
@@ -296,7 +265,6 @@ test_files:
296
265
  - spec/active_model_extensions_spec.rb
297
266
  - spec/active_record_cloning_spec.rb
298
267
  - spec/active_record_extensions_spec.rb
299
- - spec/breadcrumb_spec.rb
300
268
  - spec/concurrency_spec.rb
301
269
  - spec/en.yml
302
270
  - spec/position_initializer_spec.rb
@@ -1,6 +0,0 @@
1
- source :rubygems
2
- gemspec :path => '../'
3
-
4
- group :development, :test do
5
- gem 'activerecord', '~> 5.0'
6
- end
@@ -1,6 +0,0 @@
1
- source :rubygems
2
- gemspec :path => '../'
3
-
4
- group :development, :test do
5
- gem 'activerecord', '~> 6.0.0.rc1'
6
- end
@@ -1,26 +0,0 @@
1
- module ActionView
2
- module Helpers
3
- module FormTagHelper
4
- # Create currency selector tag -- see select_tag for options
5
- def currency_select_tag(name, current_value, options={})
6
- selectable_options = []
7
- selectable_options << ["--", nil] if options[:include_blank]
8
- selectable_options += EnabledCurrency.all.map(&:iso_code) unless EnabledCurrency.all.empty?
9
- select_tag(name, options_for_select(selectable_options, current_value), options)
10
- end
11
- end
12
-
13
- module DateHelper
14
- def currency_select(object_name, method, options = {})
15
- value = options[:object] || EnabledCurrency.base_currency
16
- currency_select_tag("#{object_name}[#{method}]", value, options.merge(:id => "#{object_name}_#{method}"))
17
- end
18
- end
19
-
20
- class FormBuilder
21
- def currency_select(method, options = {})
22
- @template.currency_select(@object_name, method, options.merge(:object => @object.send(method)))
23
- end
24
- end
25
- end
26
- end
@@ -1,39 +0,0 @@
1
- module ActiveRecordCacheAllAttributes
2
- def self.included(base)
3
- base.extend ClassMethods
4
- end
5
-
6
- module InstanceMethods
7
- def clear_attribute_cache
8
- self.class.cache.delete("#{self.class.name}.attribute_cache")
9
- self.class.clear_request_cache
10
- end
11
- end
12
-
13
- module ClassMethods
14
- def cache
15
- Rails.cache
16
- end
17
-
18
- def clear_request_cache
19
- @request_cache = nil
20
- end
21
-
22
- def attribute_cache
23
- cache_key = "#{name}.attribute_cache"
24
- @request_cache ||= cache.read(cache_key) || generate_cache(cache_key)
25
- end
26
-
27
- def generate_attributes_hash
28
- scope = self
29
- scope = scope.ordered if respond_to?(:ordered)
30
- Hash[scope.all.map { |o| [o.send(cache_attributes_by), o.attributes] }]
31
- end
32
-
33
- def generate_cache(cache_key)
34
- cache_value = generate_attributes_hash
35
- cache.write(cache_key, cache_value)
36
- cache_value
37
- end
38
- end
39
- end
@@ -1,170 +0,0 @@
1
- module RailsCoreExtensions
2
-
3
- module Breadcrumb
4
-
5
- def breadcrumbs(object_or_nested_array = nil)
6
- breadcrumbs_builder_for(object_or_nested_array).breadcrumbs
7
- end
8
-
9
-
10
- private
11
-
12
- def breadcrumbs_builder_for(object_or_nested_array)
13
- BreadcrumbsBuilder.new(self, object_or_nested_array)
14
- end
15
-
16
-
17
- class BreadcrumbsBuilder
18
-
19
- attr_reader :view, :object_or_nested_array, :path
20
-
21
- def initialize(view, object_or_nested_array = nil)
22
- @view = view
23
- @object_or_nested_array = object_or_nested_array || path_builder.nested_array
24
- @path = path_builder.collection_url
25
- end
26
-
27
-
28
- def breadcrumbs
29
- view.content_tag :ul, :class =>'breadcrumb' do
30
- (breadcrumb_for_parent + breadcrumb_for_collection + breadcrumb_for_action).html_safe
31
- end
32
- end
33
-
34
-
35
- def breadcrumb_for_object_link
36
- breadcrumb_for link_to_object
37
- end
38
-
39
-
40
- private
41
-
42
- def breadcrumb_for_parent
43
- parent = path_builder.parent
44
- return ''.html_safe unless parent
45
- BreadcrumbsBuilder.new(view, parent).breadcrumb_for_object_link
46
- end
47
-
48
-
49
- def breadcrumb_for_collection
50
- breadcrumb_for view.link_to(object.class.table_name.titleize, path)
51
- end
52
-
53
-
54
- def breadcrumb_for_action
55
- case action
56
- when 'new' then breadcrumb_for('New', :class => 'active')
57
- when 'edit' then breadcrumb_for_object + breadcrumb_for('Edit', :class => 'active')
58
- else breadcrumb_for_object_name
59
- end
60
- end
61
-
62
-
63
- def breadcrumb_for_object
64
- if can_show?
65
- breadcrumb_for_object_link
66
- else
67
- breadcrumb_for_object_name
68
- end
69
- end
70
-
71
-
72
- def breadcrumb_for(content, options = {})
73
- view.content_tag :li, content, options
74
- end
75
-
76
-
77
- def breadcrumb_for_object_name
78
- breadcrumb_for object_name.html_safe
79
- end
80
-
81
-
82
- def link_to_object
83
- view.link_to object_name.html_safe, object_or_nested_array
84
- end
85
-
86
-
87
- def can_show?
88
- view.controller.respond_to?(:show)
89
- end
90
-
91
-
92
- def action
93
- return 'new' if object.new_record?
94
- view.params[:action]
95
- end
96
-
97
-
98
- def object_name
99
- if object.respond_to?(:name) && object.name.present?
100
- object.name
101
- else
102
- object.to_s
103
- end
104
- end
105
-
106
-
107
- def object
108
- @object ||= Array(object_or_nested_array).last
109
- end
110
-
111
-
112
- def path_builder
113
- @path_builder ||= if inherited_resources?
114
- InheritedResourcesPathBuilder.new(view)
115
- else
116
- PathBuilder.new(view)
117
- end
118
- end
119
-
120
-
121
- def inherited_resources?
122
- defined?(InheritedResources) && view.controller.responder == InheritedResources::Responder
123
- end
124
-
125
- end
126
-
127
-
128
- PathBuilder = Struct.new(:view) do
129
- def nested_array
130
- (namespaces + [parent] + [view.current_object]).compact
131
- end
132
-
133
- def collection_url
134
- view.objects_path
135
- end
136
-
137
- def parent
138
- view.parent_object
139
- end
140
-
141
- def namespaces
142
- return [] unless view.respond_to?(:namespaces)
143
- Array(view.namespaces)
144
- end
145
- end
146
-
147
-
148
- InheritedResourcesPathBuilder = Struct.new(:view) do
149
- def nested_array
150
- if view.respond_to? :calculate_nested_array
151
- view.calculate_nested_array
152
- else
153
- [parent, view.resource].compact
154
- end
155
- end
156
-
157
- def collection_url
158
- view.collection_url
159
- end
160
-
161
- def parent
162
- return view.parent.becomes(view.parent.class.base_class) if view.respond_to?(:parent)
163
- view.parent_object
164
- end
165
- end
166
-
167
- end
168
- end
169
-
170
- ActionView::Base.send(:include, RailsCoreExtensions::Breadcrumb) if defined?(ActionView::Base)
@@ -1,17 +0,0 @@
1
- module CachesActionWithoutHost
2
-
3
- def self.included(controller)
4
- controller.extend(ClassMethods)
5
- end
6
-
7
- module ClassMethods
8
- def caches_action_without_host(*args)
9
- options = args.extract_options!
10
- options ||= {}
11
- options[:cache_path] ||= proc{|c| c.url_for(c.params).split(/\//, 4).last}
12
- args << options
13
- caches_action(*args)
14
- end
15
- end
16
-
17
- end
@@ -1,86 +0,0 @@
1
- require 'rails_core_extensions/breadcrumb'
2
-
3
- require 'action_view'
4
- require 'action_view/helpers'
5
-
6
- describe RailsCoreExtensions::Breadcrumb do
7
- before do
8
- class MockView
9
- include ActionView::Helpers::TagHelper
10
- include ActionView::Helpers::UrlHelper
11
- include ActionView::Helpers::CaptureHelper
12
- attr_accessor :output_buffer
13
- include RailsCoreExtensions::Breadcrumb
14
-
15
- attr_reader :params
16
-
17
- def initialize(params)
18
- @params = params
19
- end
20
- end
21
- end
22
-
23
- after { Object.send(:remove_const, 'MockView') }
24
-
25
- subject { MockView.new(:action => action) }
26
-
27
- let(:objects_path) { '/users' }
28
- let(:parent) { nil }
29
-
30
- before do
31
- allow(subject).to receive(:objects_path) { objects_path }
32
- allow(subject).to receive(:collection_url) { objects_path }
33
-
34
- allow(subject).to receive(:parent) { parent }
35
- allow(subject).to receive(:parent_object) { parent }
36
-
37
- allow(subject).to receive(:controller) { double(:controller, :show => nil) }
38
- end
39
-
40
- context '#breadcrumbs (* = link)' do
41
- let(:user_class) { double(:table_name => 'users', :model_name => double(:singular_route_key => 'user')) }
42
- let(:user) { double(:to_s => 'Alice', :new_record? => new_record, :class => user_class) }
43
- context 'for a new record' do
44
- let(:action) { 'new' }
45
- let(:new_record) { true }
46
-
47
- it 'should breadcrumb: *Users / New' do
48
- result = subject.breadcrumbs(user)
49
- expect(result).to be_html_safe
50
- expect(result).to eq(
51
- %q(<ul class="breadcrumb"><li><a href="/users">Users</a></li><li class="active">New</li></ul>)
52
- )
53
- end
54
- end
55
-
56
- context 'for a existing record' do
57
- let(:new_record) { false }
58
-
59
- context 'when editing' do
60
- let(:action) { 'edit' }
61
- it 'should breadcrumb: *Users / *Alice / Edit' do
62
- expect(subject).to receive(:link_to).with('Users', '/users') {
63
- '<a href="/users">Users</a>'.html_safe }
64
- expect(subject).to receive(:link_to).with('Alice', user) {
65
- '<a href="/users/1">Alice</a>'.html_safe }
66
- result = subject.breadcrumbs(user)
67
- expect(result).to be_html_safe
68
- expect(result).to eq(
69
- %q(<ul class="breadcrumb"><li><a href="/users">Users</a></li><li><a href="/users/1">Alice</a></li><li class="active">Edit</li></ul>)
70
- )
71
- end
72
- end
73
-
74
- context 'when showing' do
75
- let(:action) { 'show' }
76
- it 'should breadcrumb: *Users / Alice' do
77
- result = subject.breadcrumbs(user)
78
- expect(result).to be_html_safe
79
- expect(result).to eq(
80
- %q(<ul class="breadcrumb"><li><a href="/users">Users</a></li><li>Alice</li></ul>)
81
- )
82
- end
83
- end
84
- end
85
- end
86
- end