ultra-pure-box 0.0.1

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 (42) hide show
  1. checksums.yaml +7 -0
  2. data/jbuilder-2.15.1/Appraisals +26 -0
  3. data/jbuilder-2.15.1/CONTRIBUTING.md +100 -0
  4. data/jbuilder-2.15.1/Gemfile +9 -0
  5. data/jbuilder-2.15.1/MIT-LICENSE +20 -0
  6. data/jbuilder-2.15.1/README.md +394 -0
  7. data/jbuilder-2.15.1/Rakefile +21 -0
  8. data/jbuilder-2.15.1/bin/release +14 -0
  9. data/jbuilder-2.15.1/bin/test +6 -0
  10. data/jbuilder-2.15.1/gemfiles/rails_7_0.gemfile +11 -0
  11. data/jbuilder-2.15.1/gemfiles/rails_7_1.gemfile +10 -0
  12. data/jbuilder-2.15.1/gemfiles/rails_7_2.gemfile +10 -0
  13. data/jbuilder-2.15.1/gemfiles/rails_8_0.gemfile +10 -0
  14. data/jbuilder-2.15.1/gemfiles/rails_8_1.gemfile +10 -0
  15. data/jbuilder-2.15.1/gemfiles/rails_head.gemfile +10 -0
  16. data/jbuilder-2.15.1/jbuilder.gemspec +35 -0
  17. data/jbuilder-2.15.1/lib/generators/rails/jbuilder_generator.rb +65 -0
  18. data/jbuilder-2.15.1/lib/generators/rails/scaffold_controller_generator.rb +24 -0
  19. data/jbuilder-2.15.1/lib/generators/rails/templates/api_controller.rb +69 -0
  20. data/jbuilder-2.15.1/lib/generators/rails/templates/controller.rb +86 -0
  21. data/jbuilder-2.15.1/lib/generators/rails/templates/index.json.jbuilder +1 -0
  22. data/jbuilder-2.15.1/lib/generators/rails/templates/partial.json.jbuilder +16 -0
  23. data/jbuilder-2.15.1/lib/generators/rails/templates/show.json.jbuilder +1 -0
  24. data/jbuilder-2.15.1/lib/jbuilder/blank.rb +13 -0
  25. data/jbuilder-2.15.1/lib/jbuilder/collection_renderer.rb +58 -0
  26. data/jbuilder-2.15.1/lib/jbuilder/errors.rb +26 -0
  27. data/jbuilder-2.15.1/lib/jbuilder/jbuilder.rb +3 -0
  28. data/jbuilder-2.15.1/lib/jbuilder/jbuilder_dependency_tracker.rb +75 -0
  29. data/jbuilder-2.15.1/lib/jbuilder/jbuilder_template.rb +264 -0
  30. data/jbuilder-2.15.1/lib/jbuilder/key_formatter.rb +32 -0
  31. data/jbuilder-2.15.1/lib/jbuilder/railtie.rb +34 -0
  32. data/jbuilder-2.15.1/lib/jbuilder/version.rb +5 -0
  33. data/jbuilder-2.15.1/lib/jbuilder.rb +384 -0
  34. data/jbuilder-2.15.1/test/jbuilder_dependency_tracker_test.rb +71 -0
  35. data/jbuilder-2.15.1/test/jbuilder_generator_test.rb +68 -0
  36. data/jbuilder-2.15.1/test/jbuilder_template_test.rb +469 -0
  37. data/jbuilder-2.15.1/test/jbuilder_test.rb +954 -0
  38. data/jbuilder-2.15.1/test/scaffold_api_controller_generator_test.rb +83 -0
  39. data/jbuilder-2.15.1/test/scaffold_controller_generator_test.rb +116 -0
  40. data/jbuilder-2.15.1/test/test_helper.rb +47 -0
  41. data/ultra-pure-box.gemspec +12 -0
  42. metadata +81 -0
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/jbuilder/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'jbuilder'
7
+ s.version = Jbuilder::VERSION
8
+ s.authors = 'David Heinemeier Hansson'
9
+ s.email = 'david@basecamp.com'
10
+ s.summary = 'Create JSON structures via a Builder-style DSL'
11
+ s.homepage = 'https://github.com/rails/jbuilder'
12
+ s.license = 'MIT'
13
+
14
+ s.required_ruby_version = '>= 3.0.0'
15
+
16
+ s.add_dependency 'activesupport', '>= 7.0.0'
17
+ s.add_dependency 'actionview', '>= 7.0.0'
18
+
19
+ if RUBY_ENGINE == 'rbx'
20
+ s.add_development_dependency('racc')
21
+ s.add_development_dependency('json')
22
+ s.add_development_dependency('rubysl')
23
+ end
24
+
25
+ s.files = `git ls-files`.split("\n")
26
+ s.test_files = `git ls-files -- test/*`.split("\n")
27
+
28
+ s.metadata = {
29
+ "bug_tracker_uri" => "https://github.com/rails/jbuilder/issues",
30
+ "changelog_uri" => "https://github.com/rails/jbuilder/releases/tag/v#{s.version}",
31
+ "mailing_list_uri" => "https://discuss.rubyonrails.org/c/rubyonrails-talk",
32
+ "source_code_uri" => "https://github.com/rails/jbuilder/tree/v#{s.version}",
33
+ "rubygems_mfa_required" => "true",
34
+ }
35
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/named_base'
4
+ require 'rails/generators/resource_helpers'
5
+
6
+ module Rails
7
+ module Generators
8
+ class JbuilderGenerator < NamedBase # :nodoc:
9
+ include Rails::Generators::ResourceHelpers
10
+
11
+ source_root File.expand_path('../templates', __FILE__)
12
+
13
+ argument :attributes, type: :array, default: [], banner: 'field:type field:type'
14
+
15
+ class_option :timestamps, type: :boolean, default: true
16
+
17
+ def create_root_folder
18
+ path = File.join('app/views', controller_file_path)
19
+ empty_directory path unless File.directory?(path)
20
+ end
21
+
22
+ def copy_view_files
23
+ %w(index show).each do |view|
24
+ filename = filename_with_extensions(view)
25
+ template filename, File.join('app/views', controller_file_path, filename)
26
+ end
27
+ template filename_with_extensions('partial'), File.join('app/views', controller_file_path, filename_with_extensions("_#{singular_table_name}"))
28
+ end
29
+
30
+
31
+ protected
32
+ def attributes_names
33
+ [:id] + super
34
+ end
35
+
36
+ def filename_with_extensions(name)
37
+ [name, :json, :jbuilder] * '.'
38
+ end
39
+
40
+ def full_attributes_list
41
+ if options[:timestamps]
42
+ attributes_list(attributes_names + %w(created_at updated_at))
43
+ else
44
+ attributes_list(attributes_names)
45
+ end
46
+ end
47
+
48
+ def attributes_list(attributes = attributes_names)
49
+ if self.attributes.any? {|attr| attr.name == 'password' && attr.type == :digest}
50
+ attributes = attributes.reject {|name| %w(password password_confirmation).include? name}
51
+ end
52
+
53
+ attributes.map { |a| ":#{a}"} * ', '
54
+ end
55
+
56
+ def virtual_attributes
57
+ attributes.select {|name| name.respond_to?(:virtual?) && name.virtual? }
58
+ end
59
+
60
+ def partial_path_name
61
+ [controller_file_path, singular_table_name].join("/")
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+ require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
5
+
6
+ module Rails
7
+ module Generators
8
+ class ScaffoldControllerGenerator
9
+ source_paths << File.expand_path('../templates', __FILE__)
10
+
11
+ hook_for :jbuilder, type: :boolean, default: true
12
+
13
+ private
14
+
15
+ def permitted_params
16
+ attributes_names.map { |name| ":#{name}" }.join(', ')
17
+ end unless private_method_defined? :permitted_params
18
+
19
+ def status_unprocessable_content
20
+ ::Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422) rescue :unprocessable_content
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,69 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= singular_table_name %>, only: %i[ show update destroy ]
8
+
9
+ # GET <%= route_url %>
10
+ # GET <%= route_url %>.json
11
+ def index
12
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
13
+ end
14
+
15
+ # GET <%= route_url %>/1
16
+ # GET <%= route_url %>/1.json
17
+ def show
18
+ end
19
+
20
+ # POST <%= route_url %>
21
+ # POST <%= route_url %>.json
22
+ def create
23
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
24
+
25
+ if @<%= orm_instance.save %>
26
+ render :show, status: :created, location: <%= "@#{singular_table_name}" %>
27
+ else
28
+ render json: <%= "@#{orm_instance.errors}" %>, status: :<%= status_unprocessable_content.to_s %>
29
+ end
30
+ end
31
+
32
+ # PATCH/PUT <%= route_url %>/1
33
+ # PATCH/PUT <%= route_url %>/1.json
34
+ def update
35
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
36
+ render :show, status: :ok, location: <%= "@#{singular_table_name}" %>
37
+ else
38
+ render json: <%= "@#{orm_instance.errors}" %>, status: :<%= status_unprocessable_content.to_s %>
39
+ end
40
+ end
41
+
42
+ # DELETE <%= route_url %>/1
43
+ # DELETE <%= route_url %>/1.json
44
+ def destroy
45
+ @<%= orm_instance.destroy %>
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_<%= singular_table_name %>
51
+ <%- if Rails::VERSION::MAJOR >= 8 -%>
52
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params.expect(:id)") %>
53
+ <%- else -%>
54
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
55
+ <%- end -%>
56
+ end
57
+
58
+ # Only allow a list of trusted parameters through.
59
+ def <%= "#{singular_table_name}_params" %>
60
+ <%- if attributes_names.empty? -%>
61
+ params.fetch(<%= ":#{singular_table_name}" %>, {})
62
+ <%- elsif Rails::VERSION::MAJOR >= 8 -%>
63
+ params.expect(<%= singular_table_name %>: [ <%= permitted_params %> ])
64
+ <%- else -%>
65
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>)
66
+ <%- end -%>
67
+ end
68
+ end
69
+ <% end -%>
@@ -0,0 +1,86 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= singular_table_name %>, only: %i[ show edit update destroy ]
8
+
9
+ # GET <%= route_url %> or <%= route_url %>.json
10
+ def index
11
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
12
+ end
13
+
14
+ # GET <%= route_url %>/1 or <%= route_url %>/1.json
15
+ def show
16
+ end
17
+
18
+ # GET <%= route_url %>/new
19
+ def new
20
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
21
+ end
22
+
23
+ # GET <%= route_url %>/1/edit
24
+ def edit
25
+ end
26
+
27
+ # POST <%= route_url %> or <%= route_url %>.json
28
+ def create
29
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
30
+
31
+ respond_to do |format|
32
+ if @<%= orm_instance.save %>
33
+ format.html { redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully created.") %> }
34
+ format.json { render :show, status: :created, location: <%= "@#{singular_table_name}" %> }
35
+ else
36
+ format.html { render :new, status: :<%= status_unprocessable_content.to_s %> }
37
+ format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :<%= status_unprocessable_content.to_s %> }
38
+ end
39
+ end
40
+ end
41
+
42
+ # PATCH/PUT <%= route_url %>/1 or <%= route_url %>/1.json
43
+ def update
44
+ respond_to do |format|
45
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
46
+ format.html { redirect_to <%= redirect_resource_name %>, notice: <%= %("#{human_name} was successfully updated.") %>, status: :see_other }
47
+ format.json { render :show, status: :ok, location: <%= "@#{singular_table_name}" %> }
48
+ else
49
+ format.html { render :edit, status: :<%= status_unprocessable_content.to_s %> }
50
+ format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :<%= status_unprocessable_content.to_s %> }
51
+ end
52
+ end
53
+ end
54
+
55
+ # DELETE <%= route_url %>/1 or <%= route_url %>/1.json
56
+ def destroy
57
+ @<%= orm_instance.destroy %>
58
+
59
+ respond_to do |format|
60
+ format.html { redirect_to <%= index_helper %>_path, notice: <%= %("#{human_name} was successfully destroyed.") %>, status: :see_other }
61
+ format.json { head :no_content }
62
+ end
63
+ end
64
+
65
+ private
66
+ # Use callbacks to share common setup or constraints between actions.
67
+ def set_<%= singular_table_name %>
68
+ <%- if Rails::VERSION::MAJOR >= 8 -%>
69
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params.expect(:id)") %>
70
+ <%- else -%>
71
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
72
+ <%- end -%>
73
+ end
74
+
75
+ # Only allow a list of trusted parameters through.
76
+ def <%= "#{singular_table_name}_params" %>
77
+ <%- if attributes_names.empty? -%>
78
+ params.fetch(<%= ":#{singular_table_name}" %>, {})
79
+ <%- elsif Rails::VERSION::MAJOR >= 8 -%>
80
+ params.expect(<%= singular_table_name %>: [ <%= permitted_params %> ])
81
+ <%- else -%>
82
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= permitted_params %>)
83
+ <%- end -%>
84
+ end
85
+ end
86
+ <% end -%>
@@ -0,0 +1 @@
1
+ json.array! @<%= plural_table_name %>, partial: "<%= partial_path_name %>", as: :<%= singular_table_name %>
@@ -0,0 +1,16 @@
1
+ json.extract! <%= singular_table_name %>, <%= full_attributes_list %>
2
+ json.url <%= singular_table_name %>_url(<%= singular_table_name %>, format: :json)
3
+ <%- virtual_attributes.each do |attribute| -%>
4
+ <%- if attribute.type == :rich_text -%>
5
+ json.<%= attribute.name %> <%= singular_table_name %>.<%= attribute.name %>.to_s
6
+ <%- elsif attribute.type == :attachment -%>
7
+ json.<%= attribute.name %> url_for(<%= singular_table_name %>.<%= attribute.name %>)
8
+ <%- elsif attribute.type == :attachments -%>
9
+ json.<%= attribute.name %> do
10
+ json.array!(<%= singular_table_name %>.<%= attribute.name %>) do |<%= attribute.singular_name %>|
11
+ json.id <%= attribute.singular_name %>.id
12
+ json.url url_for(<%= attribute.singular_name %>)
13
+ end
14
+ end
15
+ <%- end -%>
16
+ <%- end -%>
@@ -0,0 +1 @@
1
+ json.partial! "<%= partial_path_name %>", <%= singular_table_name %>: @<%= singular_table_name %>
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Jbuilder
4
+ class Blank
5
+ def ==(other)
6
+ super || Blank === other
7
+ end
8
+
9
+ def empty?
10
+ true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'delegate'
4
+ require 'action_view'
5
+ require 'action_view/renderer/collection_renderer'
6
+
7
+ class Jbuilder
8
+ class CollectionRenderer < ::ActionView::CollectionRenderer # :nodoc:
9
+ class ScopedIterator < ::SimpleDelegator # :nodoc:
10
+ include Enumerable
11
+
12
+ def initialize(obj, scope)
13
+ super(obj)
14
+ @scope = scope
15
+ end
16
+
17
+ def each_with_info
18
+ return enum_for(:each_with_info) unless block_given?
19
+
20
+ __getobj__.each_with_info do |object, info|
21
+ @scope.call { yield(object, info) }
22
+ end
23
+ end
24
+ end
25
+
26
+ private_constant :ScopedIterator
27
+
28
+ def initialize(lookup_context, options, &scope)
29
+ super(lookup_context, options)
30
+ @scope = scope
31
+ end
32
+
33
+ private
34
+
35
+ def build_rendered_template(content, template, layout = nil)
36
+ super(content || json.attributes!, template)
37
+ end
38
+
39
+ def build_rendered_collection(templates, _spacer)
40
+ json.merge!(templates.map(&:body))
41
+ end
42
+
43
+ def json
44
+ @options[:locals].fetch(:json)
45
+ end
46
+
47
+ def collection_with_template(view, template, layout, collection)
48
+ super(view, template, layout, ScopedIterator.new(collection, @scope))
49
+ end
50
+ end
51
+
52
+ class EnumerableCompat < ::SimpleDelegator
53
+ # Rails 6.1 requires this.
54
+ def size(*args, &block)
55
+ __getobj__.count(*args, &block)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jbuilder/version'
4
+
5
+ class Jbuilder
6
+ class NullError < ::NoMethodError
7
+ def self.build(key)
8
+ message = "Failed to add #{key.to_s.inspect} property to null object"
9
+ new(message)
10
+ end
11
+ end
12
+
13
+ class ArrayError < ::StandardError
14
+ def self.build(key)
15
+ message = "Failed to add #{key.to_s.inspect} property to an array"
16
+ new(message)
17
+ end
18
+ end
19
+
20
+ class MergeError < ::StandardError
21
+ def self.build(current_value, updates)
22
+ message = "Can't merge #{updates.inspect} into #{current_value.inspect}"
23
+ new(message)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jbuilder/version'
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Jbuilder::DependencyTracker
4
+ EXPLICIT_DEPENDENCY = /# Template Dependency: (\S+)/
5
+
6
+ # Matches:
7
+ # json.partial! "messages/message"
8
+ # json.partial!('messages/message')
9
+ #
10
+ DIRECT_RENDERS = /
11
+ \w+\.partial! # json.partial!
12
+ \(?\s* # optional parenthesis
13
+ (['"])([^'"]+)\1 # quoted value
14
+ /x
15
+
16
+ # Matches:
17
+ # json.partial! partial: "comments/comment"
18
+ # json.comments @post.comments, partial: "comments/comment", as: :comment
19
+ # json.array! @posts, partial: "posts/post", as: :post
20
+ # = render partial: "account"
21
+ #
22
+ INDIRECT_RENDERS = /
23
+ (?::partial\s*=>|partial:) # partial: or :partial =>
24
+ \s* # optional whitespace
25
+ (['"])([^'"]+)\1 # quoted value
26
+ /x
27
+
28
+ def self.call(name, template, view_paths = nil)
29
+ new(name, template, view_paths).dependencies
30
+ end
31
+
32
+ def initialize(name, template, view_paths = nil)
33
+ @name, @template, @view_paths = name, template, view_paths
34
+ end
35
+
36
+ def dependencies
37
+ direct_dependencies + indirect_dependencies + explicit_dependencies
38
+ end
39
+
40
+ private
41
+
42
+ attr_reader :name, :template
43
+
44
+ def direct_dependencies
45
+ source.scan(DIRECT_RENDERS).map(&:second)
46
+ end
47
+
48
+ def indirect_dependencies
49
+ source.scan(INDIRECT_RENDERS).map(&:second)
50
+ end
51
+
52
+ def explicit_dependencies
53
+ dependencies = source.scan(EXPLICIT_DEPENDENCY).flatten.uniq
54
+
55
+ wildcards, explicits = dependencies.partition { |dependency| dependency.end_with?("/*") }
56
+
57
+ (explicits + resolve_directories(wildcards)).uniq
58
+ end
59
+
60
+ def resolve_directories(wildcard_dependencies)
61
+ return [] unless @view_paths
62
+ return [] if wildcard_dependencies.empty?
63
+
64
+ # Remove trailing "/*"
65
+ prefixes = wildcard_dependencies.map { |query| query[0..-3] }
66
+
67
+ @view_paths.flat_map(&:all_template_paths).uniq.filter_map { |path|
68
+ path.to_s if prefixes.include?(path.prefix)
69
+ }.sort
70
+ end
71
+
72
+ def source
73
+ template.source
74
+ end
75
+ end