rails-domino 0.2.6 → 0.2.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91d31df154a4a2b9991d14df616392a400f3a994a2d30c738190eba77c3f9c5f
4
- data.tar.gz: dec5cee302281376609405eb333201ab4d2cdac1557e469363426e9fcc7b76b7
3
+ metadata.gz: 4a89a8cc5a58c6267e697b9bab148e0433e3c7e2bb8a59aea1f898edc3cb7709
4
+ data.tar.gz: e1dd4c34b4fd6c13ebc1d1281b20f42bb0dda46aee3fea37765d989a0737e375
5
5
  SHA512:
6
- metadata.gz: 3d47166bfebf8b2ba7a194b05bec7ad7c0b6c646b136076861b41a9245f86091993bc2dbba96b4ce7503ff4678b1e6e1741be8d9e5946031d4c7d74c391be850
7
- data.tar.gz: 838abb0597721c932bbd769c2e310b3ab2c2e730da10c1bbf8981cf2ca3cee8e770c9d8f299013d75c26fd640a133828179b951ba801ee71798b512c6b34822a
6
+ metadata.gz: fcc429d3542e4662687f1fe9f067b665c4442c47934c0f3a763b4a0c969edacd1c48ac40117cba6fc3ee2c145882ea40f85d2d8f736fb9955846f361d999e5c5
7
+ data.tar.gz: 15508023f770167c18caa07f9d752f1e59f62823f741b83a724e0371d27a11248cf2991bb644f64f4db98328cbd4a1c01f3c511f6819c61c1dc97ec4e006329c
@@ -24,9 +24,12 @@ module Domino
24
24
  class ScaffoldRunner
25
25
  def initialize(model_name, columns, namespace, generate_model)
26
26
  @model_name = model_name
27
+ @file_name = model_name.underscore
28
+ @plural_file_name = @file_name.pluralize
27
29
  @columns = columns
28
30
  @namespace = namespace
29
31
  @generate_model = generate_model
32
+ @fields = columns.map(&:name).reject { |c| c == "id" }
30
33
  end
31
34
 
32
35
  def run
@@ -52,7 +55,6 @@ module Domino
52
55
  raise "Missing template: #{template_path}" unless File.exist?(template_path)
53
56
 
54
57
  content = ERB.new(File.read(template_path)).result(binding)
55
-
56
58
  puts "Generating #{type} for #{@model_name}"
57
59
 
58
60
  folder = case type
@@ -65,9 +67,9 @@ module Domino
65
67
 
66
68
  filename = case type
67
69
  when "controller"
68
- "#{@model_name.underscore.pluralize}_controller.rb"
70
+ "#{@plural_file_name}_controller.rb"
69
71
  else
70
- "#{@model_name.underscore}_#{type}.rb"
72
+ "#{@file_name}_#{type}.rb"
71
73
  end
72
74
 
73
75
  FileUtils.mkdir_p(folder)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Domino
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.8"
5
5
  end
@@ -10,25 +10,33 @@ class DominoGenerator < Rails::Generators::NamedBase # rubocop:disable Style/Doc
10
10
 
11
11
  class_option :with_model, type: :boolean, default: false, desc: "Generate ActiveRecord model"
12
12
 
13
+ def initialize(*args)
14
+ super
15
+ @model_name = class_name
16
+ @file_name = file_name
17
+ @plural_file_name = file_name.pluralize
18
+ @fields = attributes.map { |a| a.split(":").first }.reject { |f| f == "id" }
19
+ end
20
+
13
21
  def create_model
14
22
  return unless options[:with_model]
15
23
 
16
- generate "model", "#{class_name} #{attributes.join(" ")}"
24
+ generate "model", "#{@model_name} #{attributes.join(" ")}"
17
25
  end
18
26
 
19
27
  def create_service
20
- template "service.rb.tt", File.join("app/services", "#{file_name}_service.rb")
28
+ template "service.rb.tt", File.join("app/services", "#{@file_name}_service.rb")
21
29
  end
22
30
 
23
31
  def create_repository
24
- template "repository.rb.tt", File.join("app/repositories", "#{file_name}_repository.rb")
32
+ template "repository.rb.tt", File.join("app/repositories", "#{@file_name}_repository.rb")
25
33
  end
26
34
 
27
35
  def create_blueprint
28
- template "blueprint.rb.tt", File.join("app/mappers", "#{file_name}_blueprint.rb")
36
+ template "blueprint.rb.tt", File.join("app/mappers", "#{@file_name}_blueprint.rb")
29
37
  end
30
38
 
31
39
  def create_controller
32
- template "controller.rb.tt", File.join("app/controllers", "#{file_name.pluralize}_controller.rb")
40
+ template "controller.rb.tt", File.join("app/controllers", "#{@plural_file_name}_controller.rb")
33
41
  end
34
42
  end
@@ -6,5 +6,5 @@ class <%= @model_name %>Blueprint < Blueprinter::Base
6
6
  identifier :id
7
7
 
8
8
  # Fields to expose
9
- fields :name, :created_at, :updated_at
9
+ fields <%= @fields.map { |f| ":#{f}" }.join(", ") %>
10
10
  end
@@ -3,24 +3,34 @@
3
3
  class <%= @model_name.pluralize %>Controller < ApplicationController
4
4
  include Import['<%= @model_name.underscore %>_service']
5
5
 
6
+ # GET /<%= @plural_file_name %>
7
+ # @return [JSON]
6
8
  def index
7
9
  render json: <%= @model_name %>Blueprint.render(@<%= @model_name.underscore %>_service.all)
8
10
  end
9
11
 
12
+ # GET /<%= @plural_file_name %>/:id
13
+ # @return [JSON]
10
14
  def show
11
15
  render json: <%= @model_name %>Blueprint.render(@<%= @model_name.underscore %>_service.get(params[:id]))
12
16
  end
13
17
 
18
+ # POST /<%= @plural_file_name %>
19
+ # @return [JSON]
14
20
  def create
15
21
  obj = @<%= @model_name.underscore %>_service.create(resource_params)
16
22
  render json: <%= @model_name %>Blueprint.render(obj), status: :created
17
23
  end
18
24
 
25
+ # PATCH/PUT /<%= @plural_file_name %>/:id
26
+ # @return [JSON]
19
27
  def update
20
28
  obj = @<%= @model_name.underscore %>_service.update(params[:id], resource_params)
21
29
  render json: <%= @model_name %>Blueprint.render(obj)
22
30
  end
23
31
 
32
+ # DELETE /<%= @plural_file_name %>/:id
33
+ # @return [NoContent]
24
34
  def destroy
25
35
  success = @<%= @model_name.underscore %>_service.delete(params[:id])
26
36
  head(success ? :no_content : :not_found)
@@ -28,6 +38,7 @@ class <%= @model_name.pluralize %>Controller < ApplicationController
28
38
 
29
39
  private
30
40
 
41
+ # @return [ActionController::Parameters]
31
42
  def resource_params
32
43
  params.require(:<%= @model_name.underscore %>).permit(:name)
33
44
  end
@@ -7,24 +7,35 @@
7
7
  # repo.find_by_id(1)
8
8
  #
9
9
  class <%= @model_name %>Repository < BaseRepository
10
+ # @param id [Integer]
11
+ # @return [<%= @model_name %>, nil]
10
12
  def find_by_id(id)
11
13
  <%= @model_name %>.find_by(id: id)
12
14
  end
13
15
 
16
+ # @return [Array<<%= @model_name %>>]
14
17
  def all
15
18
  <%= @model_name %>.all
16
19
  end
17
20
 
21
+
22
+ # @param attrs [Hash]
23
+ # @return [<%= @model_name %>]
18
24
  def create(attrs)
19
25
  <%= @model_name %>.create(attrs)
20
26
  end
21
27
 
28
+ # @param id [Integer]
29
+ # @param attrs [Hash]
30
+ # @return [<%= @model_name %>, nil]
22
31
  def update(id, attrs)
23
32
  record = <%= @model_name %>.find_by(id: id)
24
33
  record.update(attrs) if record
25
34
  record
26
35
  end
27
36
 
37
+ # @param id [Integer]
38
+ # @return [<%= @model_name %>, nil]
28
39
  def delete(id)
29
40
  record = <%= @model_name %>.find_by(id: id)
30
41
  record&.destroy
@@ -7,26 +7,37 @@
7
7
  class <%= @model_name %>Service < BaseService
8
8
  include Import['<%= @model_name.underscore %>_repository']
9
9
 
10
+ # @param <%= @file_name %>_repository [<%= @model_name %>Repository]
10
11
  def initialize(<%= @model_name.underscore %>_repository:)
11
12
  @<%= @model_name.underscore %>_repository = <%= @model_name.underscore %>_repository
12
13
  end
13
14
 
15
+ # @param id [Integer]
16
+ # @return [<%= @model_name %>, nil]
14
17
  def get(id)
15
18
  @<%= @model_name.underscore %>_repository.find_by_id(id)
16
19
  end
17
20
 
21
+ # @param attrs [Hash]
22
+ # @return [<%= @model_name %>]
18
23
  def create(attrs)
19
24
  @<%= @model_name.underscore %>_repository.create(attrs)
20
25
  end
21
26
 
27
+ # @param id [Integer]
28
+ # @param attrs [Hash]
29
+ # @return [<%= @model_name %>, nil]
22
30
  def update(id, attrs)
23
31
  @<%= @model_name.underscore %>_repository.update(id, attrs)
24
32
  end
25
33
 
34
+ # @param id [Integer]
35
+ # @return [Boolean]
26
36
  def delete(id)
27
37
  !!@<%= @model_name.underscore %>_repository.delete(id)
28
38
  end
29
39
 
40
+ # @return [Array<<%= @model_name %>>]
30
41
  def all
31
42
  @<%= @model_name.underscore %>_repository.all
32
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-domino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - kiebor81