inferred_crumpets 0.2.6 → 0.5.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
- SHA1:
3
- metadata.gz: 62dd5a686657e7ac35de533b178e8a06a0523ae6
4
- data.tar.gz: 2f2eb671e2c074abe798766c06351ad463127066
2
+ SHA256:
3
+ metadata.gz: df7c96a402d26e19410b2e36b5f5627ba7d82d9133ca4505ac2d56e83698a7bd
4
+ data.tar.gz: 37f975409e519768f883c815924253e727a385b2c956d0b4ad83b3d84998550d
5
5
  SHA512:
6
- metadata.gz: 055a30abcc20d6277d8b849751b9df67910d6f05259c8be9ea9ad85827fe2c9f6a55cb45156fa50307445ed1b10c35069dbd7d457b8849621e262034dea68ce2
7
- data.tar.gz: b8fc00da8bfc2b6a2b025996046468ac62136f850f24032cc9b450f7d351d871916ea41613731e9c37b264726e8fca1215f80c8c8f60648bd8453f5dd941b326
6
+ metadata.gz: 5bf10586c402d098f3a7bf290156d70f6ed00f431c360616cdba24c68101f9dc723f799e5f97a59e1b3f2fcbcffde5bd703c88b4414cc2511e4a642845ba91e3
7
+ data.tar.gz: e86965e111940f9493a4a120e27af1cf308c7c22f06afc7ccfcee468b2364aa649f0dfc4a2468cffbfc95c2e449a9d7c349c57a937d4b183ef422ac422d23326
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "bundler"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "daily"
@@ -0,0 +1,59 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - "v*"
7
+
8
+ jobs:
9
+ build:
10
+ name: Build
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout
14
+ uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ bundler-cache: true
18
+ - run: bundle exec rake
19
+
20
+ release:
21
+ needs: build
22
+ name: Release
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - name: Checkout
26
+ uses: actions/checkout@v2
27
+
28
+ - name: Generate Changelog
29
+ run: |
30
+ # Get version from github ref (remove 'refs/tags/' and prefix 'v')
31
+ version="${GITHUB_REF#refs/tags/v}"
32
+ npx changelog-parser CHANGELOG.md | jq -cr ".versions | .[] | select(.version == \"$version\") | .body" > ${{ github.workflow }}-CHANGELOG.txt
33
+
34
+ - name: Release
35
+ uses: softprops/action-gh-release@v1
36
+ with:
37
+ body_path: ${{ github.workflow }}-CHANGELOG.txt
38
+ env:
39
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40
+
41
+ publish:
42
+ needs: [build, release]
43
+ name: Publish
44
+ runs-on: ubuntu-latest
45
+
46
+ steps:
47
+ - uses: actions/checkout@v2
48
+ - uses: ruby/setup-ruby@v1
49
+
50
+ - name: Publish to RubyGems
51
+ run: |
52
+ mkdir -p $HOME/.gem
53
+ touch $HOME/.gem/credentials
54
+ chmod 0600 $HOME/.gem/credentials
55
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
56
+ gem build *.gemspec
57
+ gem push *.gem
58
+ env:
59
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,16 @@
1
+ name: Build and Test
2
+ on: [push, pull_request]
3
+ jobs:
4
+ test:
5
+ strategy:
6
+ fail-fast: false
7
+ matrix:
8
+ ruby: ["2.6", "2.7", "3.0"]
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: ${{ matrix.ruby }}
15
+ bundler-cache: true
16
+ - run: bundle exec rake
@@ -1 +1 @@
1
- 2.4.2
1
+ 3.0.0
@@ -1,5 +1,26 @@
1
1
  # InferredCrumpets
2
2
 
3
+ ## 0.5.0
4
+
5
+ - [TT-8631] Update to build with github actions / ruby 3.0 / rails 6.1
6
+
7
+ ## 0.4.2
8
+
9
+ * [TT-6224] ActiveRecord::Base subjects can now take a custom crumb name
10
+
11
+ ## 0.4.1
12
+
13
+ * [TT-5835] Fix crumb title for active record relation
14
+
15
+ ## 0.4.0
16
+
17
+ * [TT-5807] Use crumb title for the subject name
18
+
19
+ ## 0.3.0
20
+
21
+ * [TT-5087] Add parent to be displayed on index routes
22
+ * [TT-5088] Add ability to link to all actions
23
+
3
24
  ## 0.2.6
4
25
 
5
26
  * [TT-4479] Added grandparent support
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # InferredCrumpets
2
2
 
3
- [![Build Status](https://travis-ci.org/sealink/inferred_crumpets.svg?branch=master)](https://travis-ci.org/sealink/inferred_crumpets)
3
+ [![Gem Version](https://badge.fury.io/rb/inferred_crumpets.svg)](http://badge.fury.io/rb/inferred_crumpets)
4
+ [![Build Status](https://github.com/sealink/inferred_crumpets/workflows/Build%20and%20Test/badge.svg?branch=master)](https://github.com/sealink/inferred_crumpets/actions)
4
5
 
5
6
  Automatic breadcrumbs for Rails. Built with [crumpet](https://github.com/blaknite/crumpet).
6
7
 
@@ -24,11 +25,22 @@ In the view call `render_inferred_crumbs`
24
25
 
25
26
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
27
 
28
+ ## Release
29
+
30
+ To publish a new version of this gem the following steps must be taken.
31
+
32
+ * Update the version in the following files
33
+ ```
34
+ CHANGELOG.md
35
+ lib/inferred_crumpets/version.rb
36
+ ````
37
+ * Create a tag using the format v0.1.0
38
+ * Follow build progress in GitHub actions
39
+
27
40
  ## Contributing
28
41
 
29
42
  Bug reports and pull requests are welcome on GitHub at https://github.com/sealink/inferred_crumpets. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
30
43
 
31
-
32
44
  ## License
33
45
 
34
46
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -20,11 +20,12 @@ Gem::Specification.new do |spec|
20
20
  spec.bindir = "exe"
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
+ spec.required_ruby_version = '>= 2.6.0'
23
24
 
24
- spec.add_dependency "rails", ">= 3"
25
+ spec.add_dependency "rails", ">= 6"
25
26
  spec.add_dependency "crumpet", ">= 0.3.0"
26
27
 
27
- spec.add_development_dependency "bundler", "~> 1.14"
28
- spec.add_development_dependency "rake", "~> 10.0"
29
- spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "bundler"
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rspec"
30
31
  end
@@ -1,7 +1,9 @@
1
1
  require "inferred_crumpets/route_checker"
2
+ require "inferred_crumpets/subject_finder"
2
3
  require "inferred_crumpets/builder"
3
4
  require "inferred_crumpets/railtie"
4
5
  require "inferred_crumpets/version"
5
6
  require "inferred_crumpets/view_helpers"
7
+ require "inferred_crumpets/action_processor"
6
8
 
7
9
  module InferredCrumpets; end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InferredCrumpets
4
+ class ActionProcessor
5
+ NEW_ACTIONS = %w[new create].freeze
6
+ private_constant :NEW_ACTIONS
7
+
8
+ EDIT_ACTIONS = %w[edit update].freeze
9
+ private_constant :EDIT_ACTIONS
10
+
11
+ IGNORED_ACTIONS = %w[show].freeze
12
+ private_constant :IGNORED_ACTIONS
13
+
14
+ NEW_LABEL = 'New'
15
+ private_constant :NEW_LABEL
16
+
17
+ EDIT_LABEL = 'Edit'
18
+ private_constant :EDIT_LABEL
19
+
20
+ def self.for_action(action)
21
+ new(action).call
22
+ end
23
+
24
+ def initialize(action)
25
+ @action = action
26
+ end
27
+
28
+ def call
29
+ return build_opts(nil) if IGNORED_ACTIONS.include?(@action)
30
+ return build_opts(NEW_LABEL, false) if NEW_ACTIONS.include?(@action)
31
+ return build_opts(EDIT_LABEL) if EDIT_ACTIONS.include?(@action)
32
+
33
+ build_opts(@action.humanize)
34
+ end
35
+
36
+ private
37
+
38
+ def build_opts(label, has_subject = true)
39
+ OpenStruct.new(label: label, has_subject?: has_subject)
40
+ end
41
+ end
42
+ end
@@ -3,7 +3,7 @@ module InferredCrumpets
3
3
  attr_reader :view_context, :subject, :parents
4
4
 
5
5
  def self.build_inferred_crumbs!(view_context)
6
- subject = view_context.current_object rescue view_context.collection rescue nil
6
+ subject = SubjectFinder.for_context(view_context)
7
7
  return unless subject
8
8
  parents = [view_context.parent_object].compact.flatten rescue []
9
9
  build_all!(view_context, subject, parents)
@@ -45,8 +45,10 @@ module InferredCrumpets
45
45
  def build_crumb_for_collection!
46
46
  return if parents.present? && linkable?
47
47
 
48
- if subject.is_a?(ActiveRecord::Relation)
49
- view_context.crumbs.add_crumb subject_name.pluralize.titleize
48
+ if subject.class.respond_to?(:collection_title)
49
+ view_context.crumbs.add_crumb subject.class.collection_title, url_for_collection
50
+ elsif subject.is_a?(ActiveRecord::Relation)
51
+ view_context.crumbs.add_crumb relation_name.pluralize.titleize
50
52
  elsif subject.is_a?(ActiveRecord::Base)
51
53
  view_context.crumbs.add_crumb subject.class.table_name.titleize, url_for_collection
52
54
  end
@@ -54,16 +56,13 @@ module InferredCrumpets
54
56
 
55
57
  def build_crumb_for_action!
56
58
  return unless subject.is_a?(ActiveRecord::Base)
59
+ crumb = ActionProcessor.for_action(action)
60
+ build_crumb_for_subject! if crumb.has_subject?
61
+ add_crumb(crumb.label) if crumb.label.present?
62
+ end
57
63
 
58
- if %w(new create).include?(action)
59
- view_context.crumbs.add_crumb('New', wrapper_options: { class: 'active' })
60
- return
61
- end
62
-
63
- build_crumb_for_subject!
64
- if %w(edit update).include?(action)
65
- view_context.crumbs.add_crumb('Edit', wrapper_options: { class: 'active' })
66
- end
64
+ def add_crumb(label)
65
+ view_context.crumbs.add_crumb(label, wrapper_options: { class: 'active' })
67
66
  end
68
67
 
69
68
  def build_crumb_for_subject!
@@ -110,16 +109,16 @@ module InferredCrumpets
110
109
  view_context.params[:action]
111
110
  end
112
111
 
113
- def subject_name
112
+ def relation_name
114
113
  subject.respond_to?(:name) && subject.name.present? ? subject.name : subject.to_s
115
114
  end
116
115
 
117
- def class_with_parents
118
- [parents.last, transformed_subject.class].compact
116
+ def subject_name
117
+ subject.respond_to?(:crumb_title) && subject.crumb_title.present? ? subject.crumb_title : subject.to_s
119
118
  end
120
119
 
121
- def inherited_resources?
122
- defined?(InheritedResources) && view_context.controller.responder == InheritedResources::Responder
120
+ def class_with_parents
121
+ [parents.last, transformed_subject.class].compact
123
122
  end
124
123
  end
125
124
  end
@@ -0,0 +1,17 @@
1
+ module InferredCrumpets
2
+ class SubjectFinder
3
+ def self.for_context(context)
4
+ new(context).call
5
+ end
6
+
7
+ def initialize(context)
8
+ @context = context
9
+ end
10
+
11
+ def call
12
+ current_object = begin @context.current_object rescue nil end
13
+ collection_object = begin @context.collection rescue nil end
14
+ current_object || collection_object
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module InferredCrumpets
2
- VERSION = "0.2.6"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inferred_crumpets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Colegate
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-21 00:00:00.000000000 Z
11
+ date: 2021-01-06 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: '3'
19
+ version: '6'
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: '3'
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: crumpet
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,44 +42,44 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.14'
47
+ version: '0'
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: '1.14'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '3.0'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '3.0'
82
+ version: '0'
83
83
  description: Automatic breadcrumbs for Rails.
84
84
  email:
85
85
  - support@travellink.com.au
@@ -87,10 +87,12 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
+ - ".github/dependabot.yml"
91
+ - ".github/workflows/release.yml"
92
+ - ".github/workflows/ruby.yml"
90
93
  - ".gitignore"
91
94
  - ".rspec"
92
95
  - ".ruby-version"
93
- - ".travis.yml"
94
96
  - CHANGELOG.md
95
97
  - CODE_OF_CONDUCT.md
96
98
  - Gemfile
@@ -101,9 +103,11 @@ files:
101
103
  - bin/setup
102
104
  - inferred_crumpets.gemspec
103
105
  - lib/inferred_crumpets.rb
106
+ - lib/inferred_crumpets/action_processor.rb
104
107
  - lib/inferred_crumpets/builder.rb
105
108
  - lib/inferred_crumpets/railtie.rb
106
109
  - lib/inferred_crumpets/route_checker.rb
110
+ - lib/inferred_crumpets/subject_finder.rb
107
111
  - lib/inferred_crumpets/version.rb
108
112
  - lib/inferred_crumpets/view_helpers.rb
109
113
  homepage: https://github.com/sealink/inferred_crumpets
@@ -118,15 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
122
  requirements:
119
123
  - - ">="
120
124
  - !ruby/object:Gem::Version
121
- version: '0'
125
+ version: 2.6.0
122
126
  required_rubygems_version: !ruby/object:Gem::Requirement
123
127
  requirements:
124
128
  - - ">="
125
129
  - !ruby/object:Gem::Version
126
130
  version: '0'
127
131
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.6.13
132
+ rubygems_version: 3.2.3
130
133
  signing_key:
131
134
  specification_version: 4
132
135
  summary: Automatic breadcrumbs for Rails.
@@ -1,5 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4.1
5
- before_install: gem install bundler -v 1.14.6