inferred_crumpets 0.2.6 → 0.3.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: 28553af4aca28551fc937604483c9f5f2acb0cadb86a7a2bafb5fbd19b223577
4
+ data.tar.gz: 422d6c7c1b50a4d74d140215528ee507bd6cf7985f0d83331f92d5969a5d5ed0
5
5
  SHA512:
6
- metadata.gz: 055a30abcc20d6277d8b849751b9df67910d6f05259c8be9ea9ad85827fe2c9f6a55cb45156fa50307445ed1b10c35069dbd7d457b8849621e262034dea68ce2
7
- data.tar.gz: b8fc00da8bfc2b6a2b025996046468ac62136f850f24032cc9b450f7d351d871916ea41613731e9c37b264726e8fca1215f80c8c8f60648bd8453f5dd941b326
6
+ metadata.gz: a39bf86391c5dacb4644599007755cdc9d03e1d7226de98a0b540a058dccfd1922b20901bea31858820864593923b5d50e88c17aac0dce732f08fb3014022ee1
7
+ data.tar.gz: cdcf54c989ed2e39b9c6043fdca9a4287eb20988684a9bd6f300be1d2dd4874ee5f21dabb6a954d032e618f70ba2cc3ff855fd4694a9d8cfd8db574a426ce6ef
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.2
1
+ 2.6.1
data/.travis.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.4.1
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
5
7
  before_install: gem install bundler -v 1.14.6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # InferredCrumpets
2
2
 
3
+ ## 0.3.0
4
+
5
+ * [TT-5087] Add parent to be displayed on index routes
6
+ * [TT-5088] Add ability to link to all actions
7
+
3
8
  ## 0.2.6
4
9
 
5
10
  * [TT-4479] Added grandparent support
@@ -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)
@@ -54,16 +54,13 @@ module InferredCrumpets
54
54
 
55
55
  def build_crumb_for_action!
56
56
  return unless subject.is_a?(ActiveRecord::Base)
57
+ crumb = ActionProcessor.for_action(action)
58
+ build_crumb_for_subject! if crumb.has_subject?
59
+ add_crumb(crumb.label) if crumb.label.present?
60
+ end
57
61
 
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
62
+ def add_crumb(label)
63
+ view_context.crumbs.add_crumb(label, wrapper_options: { class: 'active' })
67
64
  end
68
65
 
69
66
  def build_crumb_for_subject!
@@ -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.3.0"
3
3
  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
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.3.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: 2019-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -101,9 +101,11 @@ files:
101
101
  - bin/setup
102
102
  - inferred_crumpets.gemspec
103
103
  - lib/inferred_crumpets.rb
104
+ - lib/inferred_crumpets/action_processor.rb
104
105
  - lib/inferred_crumpets/builder.rb
105
106
  - lib/inferred_crumpets/railtie.rb
106
107
  - lib/inferred_crumpets/route_checker.rb
108
+ - lib/inferred_crumpets/subject_finder.rb
107
109
  - lib/inferred_crumpets/version.rb
108
110
  - lib/inferred_crumpets/view_helpers.rb
109
111
  homepage: https://github.com/sealink/inferred_crumpets
@@ -125,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
127
  - !ruby/object:Gem::Version
126
128
  version: '0'
127
129
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.6.13
130
+ rubygems_version: 3.0.1
130
131
  signing_key:
131
132
  specification_version: 4
132
133
  summary: Automatic breadcrumbs for Rails.