cookbook 0.1.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.
Files changed (161) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +10 -0
  5. data/Gemfile +39 -0
  6. data/Gemfile.lock +367 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +105 -0
  9. data/Rakefile +52 -0
  10. data/VERSION +1 -0
  11. data/app/assets/stylesheets/cookbook/application.scss +180 -0
  12. data/app/controllers/concerns/cookbook/params.rb +27 -0
  13. data/app/helpers/cookbook/application_helper.rb +38 -0
  14. data/app/models/cookbook/use.rb +26 -0
  15. data/app/views/cookbook/_fields.html.haml +11 -0
  16. data/app/views/cookbook/_used_in.html.haml +15 -0
  17. data/app/views/cookbook/_uses_of.html.haml +11 -0
  18. data/app/views/cookbook/uses/_fields.html.haml +17 -0
  19. data/bin/rails +16 -0
  20. data/config/initializers/simple_form.rb +180 -0
  21. data/config/locales/simple_form.en.yml +31 -0
  22. data/cookbook.gemspec +249 -0
  23. data/db/migrate/20210909141929_create_uses.cookbook.rb +21 -0
  24. data/lib/cookbook/configuration.rb +28 -0
  25. data/lib/cookbook/engine.rb +34 -0
  26. data/lib/cookbook/extensions/float.rb +10 -0
  27. data/lib/cookbook/mixins/acts_as_use_of.rb +45 -0
  28. data/lib/cookbook/mixins/acts_as_used_in.rb +43 -0
  29. data/lib/cookbook/railtie.rb +6 -0
  30. data/lib/cookbook/version.rb +9 -0
  31. data/lib/cookbook.rb +27 -0
  32. data/lib/tasks/cookbook_tasks.rake +5 -0
  33. data/lib/templates/haml/scaffold/_form.html.haml +12 -0
  34. data/spec/cookbook_spec.rb +9 -0
  35. data/spec/dummy/Rakefile +8 -0
  36. data/spec/dummy/app/assets/config/manifest.js +2 -0
  37. data/spec/dummy/app/assets/images/.keep +0 -0
  38. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  39. data/spec/dummy/app/assets/stylesheets/scaffolds.scss +65 -0
  40. data/spec/dummy/app/channels/application_cable/channel.rb +6 -0
  41. data/spec/dummy/app/channels/application_cable/connection.rb +6 -0
  42. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  43. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  44. data/spec/dummy/app/controllers/how_tos_controller.rb +61 -0
  45. data/spec/dummy/app/controllers/ingredients_controller.rb +60 -0
  46. data/spec/dummy/app/controllers/recipes_controller.rb +61 -0
  47. data/spec/dummy/app/controllers/supplies_controller.rb +60 -0
  48. data/spec/dummy/app/controllers/tools_controller.rb +60 -0
  49. data/spec/dummy/app/javascript/packs/application.js +16 -0
  50. data/spec/dummy/app/jobs/application_job.rb +9 -0
  51. data/spec/dummy/app/mailers/application_mailer.rb +6 -0
  52. data/spec/dummy/app/models/ability.rb +21 -0
  53. data/spec/dummy/app/models/application_record.rb +7 -0
  54. data/spec/dummy/app/models/concerns/.keep +0 -0
  55. data/spec/dummy/app/models/how_to.rb +5 -0
  56. data/spec/dummy/app/models/ingredient.rb +5 -0
  57. data/spec/dummy/app/models/recipe.rb +5 -0
  58. data/spec/dummy/app/models/supply.rb +5 -0
  59. data/spec/dummy/app/models/tool.rb +5 -0
  60. data/spec/dummy/app/models/user.rb +8 -0
  61. data/spec/dummy/app/views/how_tos/_form.html.haml +7 -0
  62. data/spec/dummy/app/views/how_tos/edit.html.haml +7 -0
  63. data/spec/dummy/app/views/how_tos/index.html.haml +25 -0
  64. data/spec/dummy/app/views/how_tos/new.html.haml +5 -0
  65. data/spec/dummy/app/views/how_tos/show.html.haml +17 -0
  66. data/spec/dummy/app/views/ingredients/_form.html.haml +8 -0
  67. data/spec/dummy/app/views/ingredients/edit.html.haml +7 -0
  68. data/spec/dummy/app/views/ingredients/index.html.haml +29 -0
  69. data/spec/dummy/app/views/ingredients/new.html.haml +5 -0
  70. data/spec/dummy/app/views/ingredients/show.html.haml +23 -0
  71. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  72. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  73. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  74. data/spec/dummy/app/views/recipes/_form.html.haml +9 -0
  75. data/spec/dummy/app/views/recipes/edit.html.haml +7 -0
  76. data/spec/dummy/app/views/recipes/index.html.haml +29 -0
  77. data/spec/dummy/app/views/recipes/new.html.haml +5 -0
  78. data/spec/dummy/app/views/recipes/show.html.haml +23 -0
  79. data/spec/dummy/app/views/supplies/_form.html.haml +6 -0
  80. data/spec/dummy/app/views/supplies/edit.html.haml +7 -0
  81. data/spec/dummy/app/views/supplies/index.html.haml +25 -0
  82. data/spec/dummy/app/views/supplies/new.html.haml +5 -0
  83. data/spec/dummy/app/views/supplies/show.html.haml +17 -0
  84. data/spec/dummy/app/views/tools/_form.html.haml +6 -0
  85. data/spec/dummy/app/views/tools/edit.html.haml +7 -0
  86. data/spec/dummy/app/views/tools/index.html.haml +25 -0
  87. data/spec/dummy/app/views/tools/new.html.haml +5 -0
  88. data/spec/dummy/app/views/tools/show.html.haml +17 -0
  89. data/spec/dummy/bin/rails +6 -0
  90. data/spec/dummy/bin/rake +6 -0
  91. data/spec/dummy/bin/setup +35 -0
  92. data/spec/dummy/config/application.rb +28 -0
  93. data/spec/dummy/config/boot.rb +7 -0
  94. data/spec/dummy/config/cable.yml +10 -0
  95. data/spec/dummy/config/database.yml +25 -0
  96. data/spec/dummy/config/environment.rb +7 -0
  97. data/spec/dummy/config/environments/development.rb +80 -0
  98. data/spec/dummy/config/environments/production.rb +122 -0
  99. data/spec/dummy/config/environments/test.rb +61 -0
  100. data/spec/dummy/config/initializers/application_controller_renderer.rb +9 -0
  101. data/spec/dummy/config/initializers/assets.rb +14 -0
  102. data/spec/dummy/config/initializers/backtrace_silencers.rb +10 -0
  103. data/spec/dummy/config/initializers/content_security_policy.rb +29 -0
  104. data/spec/dummy/config/initializers/cookbook.rb +6 -0
  105. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  106. data/spec/dummy/config/initializers/devise.rb +313 -0
  107. data/spec/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  108. data/spec/dummy/config/initializers/inflections.rb +17 -0
  109. data/spec/dummy/config/initializers/json.rb +20 -0
  110. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  111. data/spec/dummy/config/initializers/permissions_policy.rb +12 -0
  112. data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
  113. data/spec/dummy/config/locales/devise.en.yml +65 -0
  114. data/spec/dummy/config/locales/en.yml +33 -0
  115. data/spec/dummy/config/puma.rb +45 -0
  116. data/spec/dummy/config/routes.rb +13 -0
  117. data/spec/dummy/config/storage.yml +34 -0
  118. data/spec/dummy/config.ru +8 -0
  119. data/spec/dummy/db/development.sqlite3 +0 -0
  120. data/spec/dummy/db/migrate/20210909175711_create_how_tos.rb +16 -0
  121. data/spec/dummy/db/migrate/20210909181442_create_ingredients.rb +16 -0
  122. data/spec/dummy/db/migrate/20210909181455_create_supplies.rb +14 -0
  123. data/spec/dummy/db/migrate/20210909181516_create_tools.rb +14 -0
  124. data/spec/dummy/db/migrate/20210909181533_create_recipes.rb +16 -0
  125. data/spec/dummy/db/migrate/20210909185303_create_uses.cookbook.rb +23 -0
  126. data/spec/dummy/db/migrate/20210910142322_create_users.rb +11 -0
  127. data/spec/dummy/db/migrate/20210910142323_add_devise_to_users.rb +50 -0
  128. data/spec/dummy/db/schema.rb +92 -0
  129. data/spec/dummy/db/seeds.rb +10 -0
  130. data/spec/dummy/db/test.sqlite3 +0 -0
  131. data/spec/dummy/lib/assets/.keep +0 -0
  132. data/spec/dummy/lib/templates/haml/scaffold/_form.html.haml +6 -0
  133. data/spec/dummy/log/.keep +0 -0
  134. data/spec/dummy/log/development.log +6643 -0
  135. data/spec/dummy/log/test.log +25990 -0
  136. data/spec/dummy/public/404.html +67 -0
  137. data/spec/dummy/public/422.html +67 -0
  138. data/spec/dummy/public/500.html +66 -0
  139. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  140. data/spec/dummy/public/apple-touch-icon.png +0 -0
  141. data/spec/dummy/public/favicon.ico +0 -0
  142. data/spec/dummy/storage/.keep +0 -0
  143. data/spec/factories/how_tos.rb +9 -0
  144. data/spec/factories/ingredients.rb +11 -0
  145. data/spec/factories/recipes.rb +11 -0
  146. data/spec/factories/supplies.rb +9 -0
  147. data/spec/factories/tools.rb +9 -0
  148. data/spec/factories/users.rb +9 -0
  149. data/spec/factories/uses.rb +24 -0
  150. data/spec/helpers/cookbook/application_helper_spec.rb +47 -0
  151. data/spec/models/cookbook/use_spec.rb +82 -0
  152. data/spec/models/how_to_spec.rb +18 -0
  153. data/spec/models/ingredient_spec.rb +15 -0
  154. data/spec/models/recipe_spec.rb +18 -0
  155. data/spec/models/supply_spec.rb +15 -0
  156. data/spec/models/tool_spec.rb +15 -0
  157. data/spec/rails_helper.rb +92 -0
  158. data/spec/requests/how_tos_spec.rb +114 -0
  159. data/spec/requests/recipes_spec.rb +116 -0
  160. data/spec/spec_helper.rb +44 -0
  161. metadata +517 -0
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Controller for Ingredients, like "Mushrooms"
4
+ class IngredientsController < ApplicationController
5
+ before_action :set_ingredient, only: %i[show edit update destroy]
6
+
7
+ # GET /ingredients
8
+ def index
9
+ @ingredients = Ingredient.all
10
+ end
11
+
12
+ # GET /ingredients/1
13
+ def show; end
14
+
15
+ # GET /ingredients/new
16
+ def new
17
+ @ingredient = Ingredient.new
18
+ end
19
+
20
+ # GET /ingredients/1/edit
21
+ def edit; end
22
+
23
+ # POST /ingredients
24
+ def create
25
+ @ingredient = Ingredient.new(ingredient_params)
26
+
27
+ if @ingredient.save
28
+ redirect_to @ingredient, notice: 'Ingredient was successfully created.'
29
+ else
30
+ render :new
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /ingredients/1
35
+ def update
36
+ if @ingredient.update(ingredient_params)
37
+ redirect_to @ingredient, notice: 'Ingredient was successfully updated.'
38
+ else
39
+ render :edit
40
+ end
41
+ end
42
+
43
+ # DELETE /ingredients/1
44
+ def destroy
45
+ @ingredient.destroy
46
+ redirect_to ingredients_url, notice: 'Ingredient was successfully destroyed.'
47
+ end
48
+
49
+ private
50
+
51
+ # Use callbacks to share common setup or constraints between actions.
52
+ def set_ingredient
53
+ @ingredient = Ingredient.find(params[:id])
54
+ end
55
+
56
+ # Only allow a list of trusted parameters through.
57
+ def ingredient_params
58
+ params.require(:ingredient).permit(:name, :description, :aisle, :store, :cost)
59
+ end
60
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Controller for Recipes, like "Caprese Salad"
4
+ class RecipesController < ApplicationController
5
+ include Cookbook::Params
6
+ before_action :set_recipe, only: %i[show edit update destroy]
7
+
8
+ # GET /recipes
9
+ def index
10
+ @recipes = Recipe.all
11
+ end
12
+
13
+ # GET /recipes/1
14
+ def show; end
15
+
16
+ # GET /recipes/new
17
+ def new
18
+ @recipe = Recipe.new
19
+ end
20
+
21
+ # GET /recipes/1/edit
22
+ def edit; end
23
+
24
+ # POST /recipes
25
+ def create
26
+ @recipe = Recipe.new(recipe_params)
27
+
28
+ if @recipe.save
29
+ redirect_to @recipe, notice: 'Recipe was successfully created.'
30
+ else
31
+ render :new
32
+ end
33
+ end
34
+
35
+ # PATCH/PUT /recipes/1
36
+ def update
37
+ if @recipe.update(recipe_params)
38
+ redirect_to @recipe, notice: 'Recipe was successfully updated.'
39
+ else
40
+ render :edit
41
+ end
42
+ end
43
+
44
+ # DELETE /recipes/1
45
+ def destroy
46
+ @recipe.destroy
47
+ redirect_to recipes_url, notice: 'Recipe was successfully destroyed.'
48
+ end
49
+
50
+ private
51
+
52
+ # Use callbacks to share common setup or constraints between actions.
53
+ def set_recipe
54
+ @recipe = Recipe.find(params[:id])
55
+ end
56
+
57
+ # Only allow a list of trusted parameters through.
58
+ def recipe_params
59
+ params.require(:recipe).permit(:name, :description, :serves, :meal, :instructions, cookbook_params('Recipe'))
60
+ end
61
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Controller for Supplies, like "Twine"
4
+ class SuppliesController < ApplicationController
5
+ before_action :set_supply, only: %i[show edit update destroy]
6
+
7
+ # GET /supplies
8
+ def index
9
+ @supplies = Supply.all
10
+ end
11
+
12
+ # GET /supplies/1
13
+ def show; end
14
+
15
+ # GET /supplies/new
16
+ def new
17
+ @supply = Supply.new
18
+ end
19
+
20
+ # GET /supplies/1/edit
21
+ def edit; end
22
+
23
+ # POST /supplies
24
+ def create
25
+ @supply = Supply.new(supply_params)
26
+
27
+ if @supply.save
28
+ redirect_to @supply, notice: 'Supply was successfully created.'
29
+ else
30
+ render :new
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /supplies/1
35
+ def update
36
+ if @supply.update(supply_params)
37
+ redirect_to @supply, notice: 'Supply was successfully updated.'
38
+ else
39
+ render :edit
40
+ end
41
+ end
42
+
43
+ # DELETE /supplies/1
44
+ def destroy
45
+ @supply.destroy
46
+ redirect_to supplies_url, notice: 'Supply was successfully destroyed.'
47
+ end
48
+
49
+ private
50
+
51
+ # Use callbacks to share common setup or constraints between actions.
52
+ def set_supply
53
+ @supply = Supply.find(params[:id])
54
+ end
55
+
56
+ # Only allow a list of trusted parameters through.
57
+ def supply_params
58
+ params.require(:supply).permit(:name, :description, :source)
59
+ end
60
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Controller for Tools, like "Skillet"
4
+ class ToolsController < ApplicationController
5
+ before_action :set_tool, only: %i[show edit update destroy]
6
+
7
+ # GET /tools
8
+ def index
9
+ @tools = Tool.all
10
+ end
11
+
12
+ # GET /tools/1
13
+ def show; end
14
+
15
+ # GET /tools/new
16
+ def new
17
+ @tool = Tool.new
18
+ end
19
+
20
+ # GET /tools/1/edit
21
+ def edit; end
22
+
23
+ # POST /tools
24
+ def create
25
+ @tool = Tool.new(tool_params)
26
+
27
+ if @tool.save
28
+ redirect_to @tool, notice: 'Tool was successfully created.'
29
+ else
30
+ render :new
31
+ end
32
+ end
33
+
34
+ # PATCH/PUT /tools/1
35
+ def update
36
+ if @tool.update(tool_params)
37
+ redirect_to @tool, notice: 'Tool was successfully updated.'
38
+ else
39
+ render :edit
40
+ end
41
+ end
42
+
43
+ # DELETE /tools/1
44
+ def destroy
45
+ @tool.destroy
46
+ redirect_to tools_url, notice: 'Tool was successfully destroyed.'
47
+ end
48
+
49
+ private
50
+
51
+ # Use callbacks to share common setup or constraints between actions.
52
+ def set_tool
53
+ @tool = Tool.find(params[:id])
54
+ end
55
+
56
+ # Only allow a list of trusted parameters through.
57
+ def tool_params
58
+ params.require(:tool).permit(:name, :description, :composition)
59
+ end
60
+ end
@@ -0,0 +1,16 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require activestorage
15
+ //= require cookbook
16
+ //= require_tree .
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationJob < ActiveJob::Base
4
+ # Automatically retry jobs that encountered a deadlock
5
+ # retry_on ActiveRecord::Deadlocked
6
+
7
+ # Most jobs are safe to ignore if the underlying records are no longer available
8
+ # discard_on ActiveJob::DeserializationError
9
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Ability class for our dummy app. Used by CanCanCan to determine
4
+ # the appropriate permissions for current_ability
5
+ class Ability
6
+ include CanCan::Ability
7
+
8
+ def initialize(_user)
9
+ # user ||= User.new
10
+
11
+ can :manage, Cookbook::Use
12
+ can :manage, Recipe
13
+ can :manage, Ingredient
14
+ can %i[manage select], Tool
15
+ can %i[manage select], Ingredient
16
+ can %i[manage select], Supply
17
+
18
+ # return if user.new_record? # Anonymous Users leave
19
+ # return unless user.admin? # Non Admin Users leave
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The class from which all other models inherit, including
4
+ # those in our engine
5
+ class ApplicationRecord < ActiveRecord::Base
6
+ self.abstract_class = true
7
+ end
File without changes
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class HowTo < ApplicationRecord
4
+ acts_as_use_of :tools, :supplies
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Ingredient < ApplicationRecord
4
+ acts_as_used_in :recipes
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Recipe < ApplicationRecord
4
+ acts_as_use_of :ingredients, :tools, :supplies
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Supply < ApplicationRecord
4
+ acts_as_used_in :recipes, :how_tos
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Tool < ApplicationRecord
4
+ acts_as_used_in :recipes, :how_tos
5
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class User < ApplicationRecord
4
+ # Include default devise modules. Others available are:
5
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
6
+ devise :database_authenticatable, :registerable,
7
+ :recoverable, :rememberable, :validatable
8
+ end
@@ -0,0 +1,7 @@
1
+ -# frozen_string_literal: true
2
+ = simple_form_for(@how_to, url: (@how_to.new_record? ? how_tos_path : how_to_path(@how_to.id))) do |f|
3
+ = f.input :name
4
+ = f.input :description
5
+ = f.input :instructions
6
+ = cookbook_fields f
7
+ .actions= f.button :submit, class: 'button-large button-action'
@@ -0,0 +1,7 @@
1
+ %h1 Editing how_to
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', @how_to
6
+ \|
7
+ = link_to 'Back', how_tos_path
@@ -0,0 +1,25 @@
1
+ %h1 Listing how_tos
2
+
3
+ %table
4
+ %thead
5
+ %tr
6
+ %th Name
7
+ %th Description
8
+ %th Instructions
9
+ %th
10
+ %th
11
+ %th
12
+
13
+ %tbody
14
+ - @how_tos.each do |how_to|
15
+ %tr
16
+ %td= how_to.name
17
+ %td= how_to.description
18
+ %td= how_to.instructions
19
+ %td= link_to 'Show', how_to
20
+ %td= link_to 'Edit', edit_how_to_path(how_to)
21
+ %td= link_to 'Destroy', how_to, method: :delete, data: { confirm: 'Are you sure?' }
22
+
23
+ %br
24
+
25
+ = link_to 'New How to', new_how_to_path
@@ -0,0 +1,5 @@
1
+ %h1 New how_to
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', how_tos_path
@@ -0,0 +1,17 @@
1
+ %p#notice= notice
2
+
3
+ %p
4
+ %b Name:
5
+ = @how_to.name
6
+ %p
7
+ %b Description:
8
+ = @how_to.description
9
+ %p
10
+ %b Instructions:
11
+ = @how_to.instructions
12
+
13
+ = cookbook_used_in @how_to
14
+
15
+ = link_to 'Edit', edit_how_to_path(@how_to)
16
+ \|
17
+ = link_to 'Back', how_tos_path
@@ -0,0 +1,8 @@
1
+ -# frozen_string_literal: true
2
+ = simple_form_for(@ingredient, url: (@ingredient.new_record? ? ingredients_path : ingredient_path(@ingredient.id))) do |f|
3
+ = f.input :name
4
+ = f.input :description
5
+ = f.input :aisle
6
+ = f.input :store
7
+ = f.input :cost
8
+ .actions= f.button :submit, class: 'button-large button-action'