ramen-rails 0.4.0 → 0.5.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 +4 -4
- data/CHANGELOG +3 -0
- data/lib/ramen-rails/config.rb +12 -0
- data/lib/ramen-rails/ramen_after_filter.rb +42 -0
- data/lib/ramen-rails/version.rb +1 -1
- data/spec/lib/ramen_after_filter_spec.rb +33 -12
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4bdf745220103d28895c16d259b69f1e390fd44
|
|
4
|
+
data.tar.gz: 4e9e118f904506cd55e13dfedb109ed4a313dd5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae8cffe0b2ba0ee8b09d92c6aefb7c72c11dc2cd5799743a2a2d45de836256caab170ac8522c380c3a8161b5d044588da90c782d0649de7bf57c6a9b5b3e81e1
|
|
7
|
+
data.tar.gz: 7b1593f7be00a1e2ce9a6c33440557ab92c37cc0663b8a160c8c7b87e593a6bcd08407884738e22f1f71f83ef54d397f9eb5c8313108e274ba3c30ff893ae815
|
data/CHANGELOG
CHANGED
data/lib/ramen-rails/config.rb
CHANGED
|
@@ -30,6 +30,18 @@ module RamenRails
|
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
def current_company_labels=(value)
|
|
34
|
+
raise ArgumentError, "current_company_labels should be a Proc" unless value.kind_of?(Proc)
|
|
35
|
+
ensure_not_lambda!(value)
|
|
36
|
+
|
|
37
|
+
@current_company_labels = value
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def current_company_labels
|
|
41
|
+
@current_company_labels
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
33
45
|
def current_company=(value)
|
|
34
46
|
raise ArgumentError, "current_company should be a Proc" unless value.kind_of?(Proc)
|
|
35
47
|
ensure_not_lambda!(value)
|
|
@@ -85,6 +85,38 @@ module RamenRails
|
|
|
85
85
|
controller.instance_variable_get(SCRIPT_TAG_HELPER_CALLED_INSTANCE_VARIABLE)
|
|
86
86
|
end
|
|
87
87
|
|
|
88
|
+
POTENTIAL_RAMEN_COMPANY_OBJECTS = [
|
|
89
|
+
Proc.new { instance_eval(&RamenRails.config.current_company) if RamenRails.config.current_company.present? },
|
|
90
|
+
Proc.new { current_company },
|
|
91
|
+
Proc.new { @company }
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
def ramen_company_labels
|
|
95
|
+
return nil unless ramen_company_object
|
|
96
|
+
controller.instance_eval(&RamenRails.config.current_company_labels) if RamenRails.config.current_company_labels.present?
|
|
97
|
+
rescue NameError => e
|
|
98
|
+
Rails.logger.debug "Swallowing NameError. We're probably in an Engine or some other context like Devise."
|
|
99
|
+
Rails.logger.debug e
|
|
100
|
+
|
|
101
|
+
nil
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def ramen_company_object
|
|
105
|
+
POTENTIAL_RAMEN_COMPANY_OBJECTS.each do |potential_company|
|
|
106
|
+
begin
|
|
107
|
+
company = controller.instance_eval &potential_company
|
|
108
|
+
if (company.present? && company.name.present? && company.id.present?)
|
|
109
|
+
return company
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
rescue NameError
|
|
113
|
+
next
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
nil
|
|
118
|
+
end
|
|
119
|
+
|
|
88
120
|
POTENTIAL_RAMEN_USER_OBJECTS = [
|
|
89
121
|
Proc.new { instance_eval(&RamenRails.config.current_user) if RamenRails.config.current_user.present? },
|
|
90
122
|
Proc.new { current_user },
|
|
@@ -173,6 +205,16 @@ module RamenRails
|
|
|
173
205
|
obj[:user][:labels] = ramen_user_labels unless ramen_user_labels.nil?
|
|
174
206
|
obj[:custom_links] = ramen_custom_links if ramen_custom_links.present?
|
|
175
207
|
|
|
208
|
+
company = ramen_company_object
|
|
209
|
+
if company
|
|
210
|
+
obj[:company] = {}
|
|
211
|
+
|
|
212
|
+
[:url, :name, :id].each do |attr|
|
|
213
|
+
obj[:company][attr] = company.send(attr)
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
obj[:company][:labels] = ramen_company_labels unless ramen_company_labels.nil?
|
|
217
|
+
end
|
|
176
218
|
|
|
177
219
|
obj = obj.deep_merge(ramen_script_tag_options) if ramen_script_tag_options.present?
|
|
178
220
|
|
data/lib/ramen-rails/version.rb
CHANGED
|
@@ -171,23 +171,44 @@ describe 'After filter' do
|
|
|
171
171
|
end
|
|
172
172
|
|
|
173
173
|
context "and a company" do
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
|
|
175
|
+
context "that has no id" do
|
|
176
|
+
before :each do
|
|
177
|
+
RamenRails.config do |c|
|
|
178
|
+
c.current_company = Proc.new { Hashie::Mash.new(name: 'Scrubber', url: 'https://scrubber.social') }
|
|
179
|
+
c.current_company_labels = Proc.new { ["ryan", "gold"] }
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
it "should not attach user & company" do
|
|
184
|
+
filter = RamenRails::RamenAfterFilter.filter(@dummy)
|
|
185
|
+
expect(@dummy.response.body).to include("script")
|
|
186
|
+
expect(@dummy.response.body).to include("Angilly")
|
|
187
|
+
expect(@dummy.response.body).not_to include("company")
|
|
188
|
+
expect(@dummy.response.body).not_to include("Scrubber")
|
|
189
|
+
expect(@dummy.response.body).not_to include("gold")
|
|
178
190
|
end
|
|
179
191
|
end
|
|
192
|
+
|
|
193
|
+
context "that has an id" do
|
|
194
|
+
before :each do
|
|
195
|
+
RamenRails.config do |c|
|
|
196
|
+
c.current_company = Proc.new { Hashie::Mash.new(id: "1245", name: 'Scrubber', url: 'https://scrubber.social') }
|
|
197
|
+
c.current_company_labels = Proc.new { ["ryan", "gold"] }
|
|
198
|
+
end
|
|
199
|
+
end
|
|
180
200
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
201
|
+
it "should attach user & company" do
|
|
202
|
+
filter = RamenRails::RamenAfterFilter.filter(@dummy)
|
|
203
|
+
expect(@dummy.response.body).to include("script")
|
|
204
|
+
expect(@dummy.response.body).to include("Angilly")
|
|
205
|
+
expect(@dummy.response.body).to include("company")
|
|
206
|
+
expect(@dummy.response.body).to include("Scrubber")
|
|
207
|
+
expect(@dummy.response.body).to include("1245")
|
|
208
|
+
expect(@dummy.response.body).to include("gold")
|
|
209
|
+
end
|
|
188
210
|
end
|
|
189
211
|
end
|
|
190
|
-
|
|
191
212
|
end
|
|
192
213
|
end
|
|
193
214
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ramen-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Angilly
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-06-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: actionpack
|