cookbook 0.1.1 → 0.1.5
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/Gemfile +1 -1
- data/Gemfile.lock +1 -14
- data/README.md +0 -2
- data/VERSION +1 -1
- data/app/models/cookbook/use.rb +26 -8
- data/cookbook.gemspec +6 -6
- data/lib/cookbook/mixins/acts_as_use_of.rb +32 -3
- data/lib/cookbook/mixins/acts_as_used_in.rb +22 -4
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1092 -0
- data/spec/dummy/log/test.log +8758 -0
- data/spec/models/cookbook/use_spec.rb +2 -13
- data/spec/models/how_to_spec.rb +3 -3
- data/spec/models/recipe_spec.rb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed17e18fbc21b1e5cd13d56061cbfb70cfa37390463f3b066c00216d990f791d
|
4
|
+
data.tar.gz: 6f027dbee389ea0ed9b33ded8a68aeaa9a941a1ee74b7ccb23600e555105ee5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4944c3707a8612da91fee783427a50500de9bc3a03f3ae13395f29fb2124175222fb2f22f0f0de28df92bdf15444ed02e359e91c5f5d26ef2a5371c93d36b60a
|
7
|
+
data.tar.gz: ed9430324055b96146b3480f570403e42117e77d5a7594805e01f1391076d5e3739e163f0d0a6868f50d7a7bc5546c09ca905df5b4b744fe9470d10bff7e7fce
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -155,18 +155,6 @@ GEM
|
|
155
155
|
rdoc
|
156
156
|
semver
|
157
157
|
jwt (2.2.3)
|
158
|
-
kaminari (1.2.1)
|
159
|
-
activesupport (>= 4.1.0)
|
160
|
-
kaminari-actionview (= 1.2.1)
|
161
|
-
kaminari-activerecord (= 1.2.1)
|
162
|
-
kaminari-core (= 1.2.1)
|
163
|
-
kaminari-actionview (1.2.1)
|
164
|
-
actionview
|
165
|
-
kaminari-core (= 1.2.1)
|
166
|
-
kaminari-activerecord (1.2.1)
|
167
|
-
activerecord
|
168
|
-
kaminari-core (= 1.2.1)
|
169
|
-
kaminari-core (1.2.1)
|
170
158
|
loofah (2.12.0)
|
171
159
|
crass (~> 1.0.2)
|
172
160
|
nokogiri (>= 1.5.9)
|
@@ -347,7 +335,6 @@ DEPENDENCIES
|
|
347
335
|
faker
|
348
336
|
haml-rails (>= 2.0, < 3)
|
349
337
|
juwelier (~> 2.1.0)
|
350
|
-
kaminari (>= 1.2.1, < 2)
|
351
338
|
puma (>= 4.3, < 5)
|
352
339
|
rails (>= 6, < 7)
|
353
340
|
rspec-html-matchers
|
@@ -355,7 +342,7 @@ DEPENDENCIES
|
|
355
342
|
rubocop
|
356
343
|
rubocop-rails
|
357
344
|
rubocop-rspec
|
358
|
-
sass-rails (>=
|
345
|
+
sass-rails (>= 5, < 7)
|
359
346
|
shoulda
|
360
347
|
shoulda-matchers (>= 4.3, < 5)
|
361
348
|
simple_form (>= 5.1, < 6)
|
data/README.md
CHANGED
@@ -3,8 +3,6 @@ Works Cited allows you to add a list of the works cited in ActiveRecord objects,
|
|
3
3
|
|
4
4
|
Works Cited can be configured to use CanCanCan to authorize the editing of citations. This makes it easy for you to control access.
|
5
5
|
|
6
|
-
Works Cited does not require, but is compatible with Rails Admin.
|
7
|
-
|
8
6
|
## Installation
|
9
7
|
Add this line to your application's Gemfile:
|
10
8
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/app/models/cookbook/use.rb
CHANGED
@@ -1,17 +1,37 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'pp'
|
2
3
|
|
3
4
|
module Cookbook
|
4
5
|
# Cookbook::Use is basically a linking table with extra information.
|
5
6
|
class Use < ApplicationRecord
|
7
|
+
attr_accessor(:used_in_tables)
|
8
|
+
|
6
9
|
# Relationships
|
7
|
-
belongs_to :use_in, polymorphic: true
|
8
|
-
belongs_to :use_of, polymorphic: true
|
10
|
+
belongs_to :use_in, polymorphic: true, inverse_of: :uses
|
11
|
+
belongs_to :use_of, polymorphic: true, inverse_of: :uses
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def add_use_of(table_sym)
|
15
|
+
singular = table_sym.to_s.singularize
|
16
|
+
model_name = singular.classify.constantize.to_s
|
17
|
+
belongs_to singular.to_sym, class_name: model_name, foreign_key: :use_of_id, inverse_of: :uses, optional: true
|
18
|
+
end
|
9
19
|
|
10
|
-
|
11
|
-
|
12
|
-
|
20
|
+
def add_use_in(table_sym)
|
21
|
+
singular = table_sym.to_s.singularize
|
22
|
+
model_name = singular.classify.constantize.to_s
|
23
|
+
belongs_to singular.to_sym, class_name: model_name, foreign_key: :use_in_id, inverse_of: :uses, optional: true
|
24
|
+
end
|
25
|
+
end
|
13
26
|
|
14
27
|
# Methods
|
28
|
+
def object_label
|
29
|
+
return use_of.name if use_of.respond_to?(:name)
|
30
|
+
return use_of.title if use_of.respond_to?(:title)
|
31
|
+
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
15
35
|
def quantity_with_unit
|
16
36
|
[quantity, unit].compact.join(' ')
|
17
37
|
end
|
@@ -26,11 +46,9 @@ module Cookbook
|
|
26
46
|
if defined?(RailsAdmin)
|
27
47
|
rails_admin do
|
28
48
|
visible false
|
49
|
+
object_label_method { :object_label }
|
29
50
|
edit do
|
30
51
|
include_all_fields
|
31
|
-
field :use_in do
|
32
|
-
visible false
|
33
|
-
end
|
34
52
|
end
|
35
53
|
end
|
36
54
|
end
|
data/cookbook.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: cookbook 0.1.
|
5
|
+
# stub: cookbook 0.1.5 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "cookbook".freeze
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.5"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.metadata = { "source_code_uri" => "http://github.com/gemvein/cookbook" } if s.respond_to? :metadata=
|
13
13
|
s.require_paths = ["lib".freeze]
|
14
14
|
s.authors = ["Loren Lundgren".freeze]
|
15
|
-
s.date = "2021-09-
|
15
|
+
s.date = "2021-09-21"
|
16
16
|
s.description = "Cookbook allows you to associate instructions with components in a cross referenced way. Good for cooking recipes or an instruction manual for DIY projects.".freeze
|
17
17
|
s.email = "loren.lundgren@gmail.com".freeze
|
18
18
|
s.executables = ["rails".freeze]
|
@@ -192,7 +192,7 @@ Gem::Specification.new do |s|
|
|
192
192
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
193
193
|
s.add_runtime_dependency(%q<rails>.freeze, [">= 6", "< 7"])
|
194
194
|
s.add_runtime_dependency(%q<haml-rails>.freeze, [">= 2.0", "< 3"])
|
195
|
-
s.add_runtime_dependency(%q<sass-rails>.freeze, [">=
|
195
|
+
s.add_runtime_dependency(%q<sass-rails>.freeze, [">= 5", "< 7"])
|
196
196
|
s.add_runtime_dependency(%q<cancancan>.freeze, [">= 3.3", "< 4"])
|
197
197
|
s.add_runtime_dependency(%q<simple_form>.freeze, [">= 5.1", "< 6"])
|
198
198
|
s.add_runtime_dependency(%q<vanilla_nested>.freeze, [">= 1.3", "< 2"])
|
@@ -210,7 +210,7 @@ Gem::Specification.new do |s|
|
|
210
210
|
else
|
211
211
|
s.add_dependency(%q<rails>.freeze, [">= 6", "< 7"])
|
212
212
|
s.add_dependency(%q<haml-rails>.freeze, [">= 2.0", "< 3"])
|
213
|
-
s.add_dependency(%q<sass-rails>.freeze, [">=
|
213
|
+
s.add_dependency(%q<sass-rails>.freeze, [">= 5", "< 7"])
|
214
214
|
s.add_dependency(%q<cancancan>.freeze, [">= 3.3", "< 4"])
|
215
215
|
s.add_dependency(%q<simple_form>.freeze, [">= 5.1", "< 6"])
|
216
216
|
s.add_dependency(%q<vanilla_nested>.freeze, [">= 1.3", "< 2"])
|
@@ -229,7 +229,7 @@ Gem::Specification.new do |s|
|
|
229
229
|
else
|
230
230
|
s.add_dependency(%q<rails>.freeze, [">= 6", "< 7"])
|
231
231
|
s.add_dependency(%q<haml-rails>.freeze, [">= 2.0", "< 3"])
|
232
|
-
s.add_dependency(%q<sass-rails>.freeze, [">=
|
232
|
+
s.add_dependency(%q<sass-rails>.freeze, [">= 5", "< 7"])
|
233
233
|
s.add_dependency(%q<cancancan>.freeze, [">= 3.3", "< 4"])
|
234
234
|
s.add_dependency(%q<simple_form>.freeze, [">= 5.1", "< 6"])
|
235
235
|
s.add_dependency(%q<vanilla_nested>.freeze, [">= 1.3", "< 2"])
|
@@ -11,10 +11,28 @@ module Cookbook
|
|
11
11
|
include InstanceMethods
|
12
12
|
|
13
13
|
self.used_in = model_symbols
|
14
|
+
Cookbook::Use.add_use_in(table_name.to_sym)
|
14
15
|
|
15
16
|
# Relationships
|
16
|
-
has_many :uses, as: :use_in, class_name: 'Cookbook::Use'
|
17
|
+
has_many :uses, as: :use_in, class_name: 'Cookbook::Use', inverse_of: :use_in
|
18
|
+
# Used only as a setter, not a getter
|
19
|
+
accepts_nested_attributes_for :uses, reject_if: :all_blank, allow_destroy: true
|
17
20
|
associate_used_in
|
21
|
+
|
22
|
+
used_in.each do |table_sym|
|
23
|
+
singular = table_sym.to_s.singularize
|
24
|
+
model = singular.classify.constantize
|
25
|
+
equals_method_symbol = "#{singular}_uses_attributes=".to_sym
|
26
|
+
define_method(equals_method_symbol) do |values|
|
27
|
+
items = []
|
28
|
+
values.each_pair do |key, value|
|
29
|
+
value['use_in'] = self
|
30
|
+
value['use_of'] = model.find_by(id: value['use_of_id'])
|
31
|
+
items << value
|
32
|
+
end
|
33
|
+
self.uses_attributes = items
|
34
|
+
end
|
35
|
+
end
|
18
36
|
end
|
19
37
|
|
20
38
|
# Extended by has_cookbook mixin
|
@@ -27,20 +45,31 @@ module Cookbook
|
|
27
45
|
model = table_sym.to_s.classify.constantize
|
28
46
|
name = model.model_name.to_s
|
29
47
|
uses_symbol = "#{model.model_name.param_key}_uses".to_sym
|
48
|
+
singular_symbol = table_sym.to_s.singularize.to_sym
|
30
49
|
|
31
50
|
has_many uses_symbol, lambda {
|
32
51
|
where(use_of_type: name)
|
33
|
-
}, as: :use_in, class_name: 'Cookbook::Use'
|
52
|
+
}, as: :use_in, class_name: 'Cookbook::Use', inverse_of: singular_symbol
|
53
|
+
|
54
|
+
# Used only as a getter, not a setter
|
34
55
|
accepts_nested_attributes_for uses_symbol, reject_if: :all_blank, allow_destroy: true
|
35
56
|
|
36
|
-
has_many table_sym, through:
|
57
|
+
has_many table_sym, through: uses_symbol, source: :use_of, source_type: name
|
37
58
|
|
38
59
|
if defined?(RailsAdmin)
|
39
60
|
rails_admin do
|
61
|
+
include_all_fields
|
40
62
|
field :uses do
|
41
63
|
visible false
|
42
64
|
end
|
43
65
|
tables.each do |table_sym|
|
66
|
+
singular = table_sym.to_s.singularize
|
67
|
+
uses_symbol = "#{singular}_uses".to_sym
|
68
|
+
field uses_symbol do # Show only on reload
|
69
|
+
visible do
|
70
|
+
!bindings[:object].new_record?
|
71
|
+
end
|
72
|
+
end
|
44
73
|
field table_sym do # We don't want these associations to show
|
45
74
|
visible false
|
46
75
|
end
|
@@ -10,20 +10,38 @@ module Cookbook
|
|
10
10
|
extend ClassMethods
|
11
11
|
include InstanceMethods
|
12
12
|
|
13
|
-
self.
|
13
|
+
self.use_of = model_symbols
|
14
14
|
self.label_method = :name
|
15
|
+
Cookbook::Use.add_use_of(table_name.to_sym)
|
15
16
|
|
16
17
|
# Relationships
|
17
|
-
has_many :uses, as: :use_of, class_name: 'Cookbook::Use'
|
18
|
+
has_many :uses, as: :use_of, class_name: 'Cookbook::Use', inverse_of: :use_of
|
18
19
|
associate_uses_of
|
20
|
+
|
21
|
+
if defined?(RailsAdmin)
|
22
|
+
rails_admin do
|
23
|
+
field :uses do
|
24
|
+
visible false
|
25
|
+
end
|
26
|
+
self.use_of.each do |table_sym| # We don't want these associations to show
|
27
|
+
table_uses_sym = "#{table_sym.to_s.singularize}_uses".to_sym
|
28
|
+
field table_uses_sym do
|
29
|
+
visible false
|
30
|
+
end
|
31
|
+
field table_sym do
|
32
|
+
visible false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
19
37
|
end
|
20
38
|
|
21
39
|
# Extended by acts_as_used_in mixin
|
22
40
|
module ClassMethods
|
23
|
-
attr_accessor :
|
41
|
+
attr_accessor :label_method, :use_of
|
24
42
|
|
25
43
|
def associate_uses_of
|
26
|
-
|
44
|
+
self.use_of.each do |table_sym|
|
27
45
|
model = table_sym.to_s.classify.constantize
|
28
46
|
name = model.model_name.to_s
|
29
47
|
|
Binary file
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|