cookbook 0.1.4 → 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/VERSION +1 -1
- data/cookbook.gemspec +3 -3
- data/lib/cookbook/mixins/acts_as_use_of.rb +19 -0
- data/lib/cookbook/mixins/acts_as_used_in.rb +7 -7
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1080 -0
- data/spec/dummy/log/test.log +1244 -0
- metadata +2 -2
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/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
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]
|
@@ -15,7 +15,24 @@ module Cookbook
|
|
15
15
|
|
16
16
|
# Relationships
|
17
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
|
18
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
|
19
36
|
end
|
20
37
|
|
21
38
|
# Extended by has_cookbook mixin
|
@@ -33,6 +50,8 @@ module Cookbook
|
|
33
50
|
has_many uses_symbol, lambda {
|
34
51
|
where(use_of_type: name)
|
35
52
|
}, as: :use_in, class_name: 'Cookbook::Use', inverse_of: singular_symbol
|
53
|
+
|
54
|
+
# Used only as a getter, not a setter
|
36
55
|
accepts_nested_attributes_for uses_symbol, reject_if: :all_blank, allow_destroy: true
|
37
56
|
|
38
57
|
has_many table_sym, through: uses_symbol, source: :use_of, source_type: name
|
@@ -10,20 +10,20 @@ module Cookbook
|
|
10
10
|
extend ClassMethods
|
11
11
|
include InstanceMethods
|
12
12
|
|
13
|
-
|
13
|
+
self.use_of = model_symbols
|
14
14
|
self.label_method = :name
|
15
15
|
Cookbook::Use.add_use_of(table_name.to_sym)
|
16
16
|
|
17
17
|
# Relationships
|
18
|
-
has_many :uses, as: :use_of, class_name: 'Cookbook::Use'
|
19
|
-
associate_uses_of
|
18
|
+
has_many :uses, as: :use_of, class_name: 'Cookbook::Use', inverse_of: :use_of
|
19
|
+
associate_uses_of
|
20
20
|
|
21
21
|
if defined?(RailsAdmin)
|
22
22
|
rails_admin do
|
23
23
|
field :uses do
|
24
24
|
visible false
|
25
25
|
end
|
26
|
-
|
26
|
+
self.use_of.each do |table_sym| # We don't want these associations to show
|
27
27
|
table_uses_sym = "#{table_sym.to_s.singularize}_uses".to_sym
|
28
28
|
field table_uses_sym do
|
29
29
|
visible false
|
@@ -38,10 +38,10 @@ module Cookbook
|
|
38
38
|
|
39
39
|
# Extended by acts_as_used_in mixin
|
40
40
|
module ClassMethods
|
41
|
-
attr_accessor :label_method
|
41
|
+
attr_accessor :label_method, :use_of
|
42
42
|
|
43
|
-
def associate_uses_of
|
44
|
-
|
43
|
+
def associate_uses_of
|
44
|
+
self.use_of.each do |table_sym|
|
45
45
|
model = table_sym.to_s.classify.constantize
|
46
46
|
name = model.model_name.to_s
|
47
47
|
|
Binary file
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|