inferred_crumpets 0.2.6 → 0.3.0
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 +5 -5
- data/.ruby-version +1 -1
- data/.travis.yml +3 -1
- data/CHANGELOG.md +5 -0
- data/lib/inferred_crumpets/action_processor.rb +42 -0
- data/lib/inferred_crumpets/builder.rb +7 -10
- data/lib/inferred_crumpets/subject_finder.rb +17 -0
- data/lib/inferred_crumpets/version.rb +1 -1
- data/lib/inferred_crumpets.rb +2 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 28553af4aca28551fc937604483c9f5f2acb0cadb86a7a2bafb5fbd19b223577
|
4
|
+
data.tar.gz: 422d6c7c1b50a4d74d140215528ee507bd6cf7985f0d83331f92d5969a5d5ed0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a39bf86391c5dacb4644599007755cdc9d03e1d7226de98a0b540a058dccfd1922b20901bea31858820864593923b5d50e88c17aac0dce732f08fb3014022ee1
|
7
|
+
data.tar.gz: cdcf54c989ed2e39b9c6043fdca9a4287eb20988684a9bd6f300be1d2dd4874ee5f21dabb6a954d032e618f70ba2cc3ff855fd4694a9d8cfd8db574a426ce6ef
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.6.1
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -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 =
|
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
|
-
|
59
|
-
|
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
|
data/lib/inferred_crumpets.rb
CHANGED
@@ -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.
|
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:
|
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
|
-
|
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.
|