rider-kick 0.0.1 → 0.0.3

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 (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -9
  3. data/lib/generators/rider_kick/USAGE +12 -0
  4. data/lib/generators/rider_kick/clean_arch_generator.rb +160 -0
  5. data/lib/generators/rider_kick/init_generator.rb +15 -0
  6. data/lib/generators/rider_kick/scaffold_generator.rb +125 -0
  7. data/lib/generators/rider_kick/structure_generator.rb +77 -0
  8. data/lib/generators/rider_kick/templates/.gitignore +57 -0
  9. data/lib/generators/rider_kick/templates/.rspec +5 -0
  10. data/lib/generators/rider_kick/templates/.rubocop.yml +1141 -0
  11. data/lib/generators/rider_kick/templates/README.md +69 -0
  12. data/lib/generators/rider_kick/templates/config/database.yml +21 -0
  13. data/lib/generators/rider_kick/templates/config/initializers/clean_archithecture.rb.tt +10 -0
  14. data/lib/generators/rider_kick/templates/config/initializers/generators.rb.tt +14 -0
  15. data/lib/generators/rider_kick/templates/config/initializers/hashie.rb.tt +16 -0
  16. data/lib/generators/rider_kick/templates/config/initializers/pagy.rb.tt +13 -0
  17. data/lib/generators/rider_kick/templates/config/initializers/rider_kick.rb +3 -0
  18. data/lib/generators/rider_kick/templates/config/initializers/version.rb.tt +6 -0
  19. data/lib/generators/rider_kick/templates/config/initializers/zeitwerk.rb.tt +3 -0
  20. data/lib/generators/rider_kick/templates/db/migrate/20220613145533_init_database.rb +5 -0
  21. data/lib/generators/rider_kick/templates/db/structures/example.yaml.tt +96 -0
  22. data/lib/generators/rider_kick/templates/domains/core/builders/builder.rb.tt +14 -0
  23. data/lib/generators/rider_kick/templates/domains/core/builders/error.rb.tt +5 -0
  24. data/lib/generators/rider_kick/templates/domains/core/builders/pagination.rb.tt +14 -0
  25. data/lib/generators/rider_kick/templates/domains/core/entities/entity.rb.tt +9 -0
  26. data/lib/generators/rider_kick/templates/domains/core/entities/error.rb.tt +7 -0
  27. data/lib/generators/rider_kick/templates/domains/core/entities/pagination.rb.tt +8 -0
  28. data/lib/generators/rider_kick/templates/domains/core/repositories/abstract_repository.rb.tt +51 -0
  29. data/lib/generators/rider_kick/templates/domains/core/repositories/create.rb.tt +15 -0
  30. data/lib/generators/rider_kick/templates/domains/core/repositories/destroy.rb.tt +16 -0
  31. data/lib/generators/rider_kick/templates/domains/core/repositories/fetch_by_id.rb.tt +13 -0
  32. data/lib/generators/rider_kick/templates/domains/core/repositories/list.rb.tt +19 -0
  33. data/lib/generators/rider_kick/templates/domains/core/repositories/update.rb.tt +23 -0
  34. data/lib/generators/rider_kick/templates/domains/core/use_cases/contract/default.rb.tt +17 -0
  35. data/lib/generators/rider_kick/templates/domains/core/use_cases/contract/pagination.rb.tt +15 -0
  36. data/lib/generators/rider_kick/templates/domains/core/use_cases/create.rb.tt +18 -0
  37. data/lib/generators/rider_kick/templates/domains/core/use_cases/destroy.rb.tt +18 -0
  38. data/lib/generators/rider_kick/templates/domains/core/use_cases/fetch_by_id.rb.tt +18 -0
  39. data/lib/generators/rider_kick/templates/domains/core/use_cases/get_version.rb.tt +17 -0
  40. data/lib/generators/rider_kick/templates/domains/core/use_cases/list.rb.tt +18 -0
  41. data/lib/generators/rider_kick/templates/domains/core/use_cases/update.rb.tt +18 -0
  42. data/lib/generators/rider_kick/templates/domains/core/utils/request_methods.rb.tt +81 -0
  43. data/lib/generators/rider_kick/templates/env.development +14 -0
  44. data/lib/generators/rider_kick/templates/env.production +14 -0
  45. data/lib/generators/rider_kick/templates/env.test +14 -0
  46. data/lib/generators/rider_kick/templates/spec/fixtures/sample.pdf +5 -0
  47. data/lib/generators/rider_kick/templates/spec/rails_helper.rb +87 -0
  48. data/lib/generators/rider_kick/templates/spec/support/file_stuber.rb +13 -0
  49. data/lib/generators/rider_kick/templates/spec/support/repository_stubber.rb +10 -0
  50. data/lib/rider-kick.rb +3 -3
  51. data/lib/rider_kick/builders/abstract_active_record_entity_builder.rb +23 -21
  52. data/lib/rider_kick/builders/abstract_active_record_entity_builder_spec.rb +116 -0
  53. data/lib/rider_kick/configuration.rb +29 -0
  54. data/lib/rider_kick/matchers/use_case_result_spec.rb +1 -0
  55. data/lib/rider_kick/types.rb +0 -3
  56. data/lib/rider_kick/version.rb +1 -1
  57. metadata +52 -4
  58. data/sig/rider_kick.rbs +0 -4
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Core::Utils::RequestMethods
4
+ include Dry::Monads[:result, :do]
5
+ DEFAULT_REQUEST_CONTENT_TYPE = 'application/json;charset=UTF-8'
6
+ private_constant :DEFAULT_REQUEST_CONTENT_TYPE
7
+
8
+ def delete(url:, body:, headers: nil, authorization: nil, is_ssl: false, timeout: 0)
9
+ headers = normalize_request_headers(headers, caller(1..1).first)
10
+ url = create_url(url)
11
+ create_request(:delete, url, headers: headers, auth: authorization, body: body, is_ssl: is_ssl, timeout: timeout)
12
+ end
13
+
14
+ def get(url:, body: nil, headers: nil, authorization: nil, is_ssl: false, timeout: 0)
15
+ headers = normalize_request_headers(headers, caller(1..1).first)
16
+ url = url + '?' + body.to_query if body.present?
17
+ url = create_url(url)
18
+ create_request(:get, url, headers: headers, auth: authorization, body: body, is_ssl: is_ssl, timeout: timeout)
19
+ end
20
+
21
+ def post(url:, body:, headers: nil, authorization: nil, is_ssl: false, timeout: 0)
22
+ headers = normalize_request_headers(headers, caller(1..1).first)
23
+ url = create_url(url)
24
+ create_request(:post, url, headers: headers, auth: authorization, body: body, is_ssl: is_ssl, timeout: timeout)
25
+ end
26
+
27
+ def put(url:, body:, headers: nil, authorization: nil, is_ssl: false, timeout: 0)
28
+ headers = normalize_request_headers(headers, caller(1..1).first)
29
+ url = create_url(url)
30
+ create_request(:put, url, headers: headers, auth: authorization, body: body, is_ssl: is_ssl, timeout: timeout)
31
+ end
32
+
33
+ def patch(url:, body:, headers: nil, authorization: nil, is_ssl: false, timeout: 0)
34
+ headers = normalize_request_headers(headers, caller(1..1).first)
35
+ url = create_url(url)
36
+ create_request(:patch, url, headers: headers, auth: authorization, body: body, is_ssl: is_ssl, timeout: timeout)
37
+ end
38
+
39
+ private
40
+
41
+ def normalize_request_headers(headers, caller_location = caller(1..1).first)
42
+ return headers unless headers.is_a?(Array)
43
+
44
+ warn "DEPRECATION WARNING: do not wrap request headers in an array. (called from #{caller_location})"
45
+ {}.merge!(*headers.select { |n| n.respond_to? :to_hash })
46
+ end
47
+
48
+ def create_url(url)
49
+ URI.parse(url)
50
+ end
51
+
52
+ def parse_response(response)
53
+ begin
54
+ res = JSON.parse(response.body)
55
+ rescue => e
56
+ return Failure e
57
+ end
58
+ unless ['200', '201', '202'].include?(response.code.to_s)
59
+ return Failure Hashie::Mash.new(res)
60
+ end
61
+ Success Hashie::Mash.new(res)
62
+ end
63
+
64
+ def create_request(method, url, headers: nil, auth: nil, body: nil, is_ssl: Rails.env.eql?('production'), timeout: 0)
65
+ request = Net::HTTP.const_get(method.to_s.classify).new(url)
66
+ request['Authorization'] = auth if auth.present?
67
+ request['Content-Type'] = DEFAULT_REQUEST_CONTENT_TYPE
68
+ request['Accept'] = DEFAULT_REQUEST_CONTENT_TYPE
69
+ headers&.each { |key, value| request[key] = value }
70
+ request.body = body.to_json unless body.nil?
71
+ http = Net::HTTP.new(url.host, url.port).tap do |http|
72
+ http.verify_mode = is_ssl ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
73
+ http.open_timeout = 60
74
+ http.read_timeout = 60
75
+ end
76
+ if is_ssl
77
+ http.use_ssl = true
78
+ end
79
+ http.request(request)
80
+ end
81
+ end
@@ -0,0 +1,14 @@
1
+ BASE_URL="http://localhost:3000"
2
+
3
+ # database primary
4
+ DATABASE_NAME=<%= Rails.application.class.module_parent_name.underscore %>_development
5
+ DATABASE_USERNAME=postgres
6
+ DATABASE_PASSWORD=bayangan
7
+ DATABASE_HOSTNAME=localhost
8
+ DATABASE_PORT="5433"
9
+ DATABASE_POOL="10"
10
+
11
+ RAILS_MAX_THREADS="5"
12
+ RAILS_ENV="development"
13
+ WEB_CONCURRENCY="5"
14
+ WORKER_TIMEOUT="3600"
@@ -0,0 +1,14 @@
1
+ BASE_URL="http://localhost:3000"
2
+
3
+ # database primary
4
+ DATABASE_NAME=<%= Rails.application.class.module_parent_name.underscore %>_development
5
+ DATABASE_USERNAME=postgres
6
+ DATABASE_PASSWORD=bayangan
7
+ DATABASE_HOSTNAME=localhost
8
+ DATABASE_PORT="5433"
9
+ DATABASE_POOL="10"
10
+
11
+ RAILS_MAX_THREADS="5"
12
+ RAILS_ENV="development"
13
+ WEB_CONCURRENCY="5"
14
+ WORKER_TIMEOUT="3600"
@@ -0,0 +1,14 @@
1
+ BASE_URL="http://localhost:3000"
2
+
3
+ # database primary
4
+ DATABASE_NAME=<%= Rails.application.class.module_parent_name.underscore %>_development
5
+ DATABASE_USERNAME=postgres
6
+ DATABASE_PASSWORD=bayangan
7
+ DATABASE_HOSTNAME=localhost
8
+ DATABASE_PORT="5433"
9
+ DATABASE_POOL="10"
10
+
11
+ RAILS_MAX_THREADS="5"
12
+ RAILS_ENV="development"
13
+ WEB_CONCURRENCY="5"
14
+ WORKER_TIMEOUT="3600"
@@ -0,0 +1,5 @@
1
+ %PDF-1.
2
+ 1 0 obj<</Pages 2 0 R>>endobj
3
+ 2 0 obj<</Kids[3 0 R]/Count 1>>endobj
4
+ 3 0 obj<</Parent 2 0 R>>endobj
5
+ trailer <</Root 1 0 R>>
@@ -0,0 +1,87 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ require 'spec_helper'
3
+ ENV['RAILS_ENV'] ||= 'test'
4
+ require_relative '../config/environment'
5
+ # Prevent database truncation if the environment is production
6
+ abort("The Rails environment is running in production mode!") if Rails.env.production?
7
+ # Uncomment the line below in case you have `--require rails_helper` in the `.rspec` file
8
+ # that will avoid rails generators crashing because migrations haven't been run yet
9
+ # return unless Rails.env.test?
10
+ require 'rspec/rails'
11
+
12
+ Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
13
+
14
+ Shoulda::Matchers.configure do |config|
15
+ config.integrate do |with|
16
+ with.test_framework :rspec
17
+ with.library :rails
18
+ end
19
+ end
20
+ # Add additional requires below this line. Rails is not loaded until this point!
21
+
22
+ # Requires supporting ruby files with custom matchers and macros, etc, in
23
+ # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
24
+ # run as spec files by default. This means that files in spec/support that end
25
+ # in _spec.rb will both be required and run as specs, causing the specs to be
26
+ # run twice. It is recommended that you do not name files matching this glob to
27
+ # end with _spec.rb. You can configure this pattern with the --pattern
28
+ # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
29
+ #
30
+ # The following line is provided for convenience purposes. It has the downside
31
+ # of increasing the boot-up time by auto-requiring all files in the support
32
+ # directory. Alternatively, in the individual `*_spec.rb` files, manually
33
+ # require only the support files necessary.
34
+ #
35
+ # Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
36
+
37
+ # Checks for pending migrations and applies them before tests are run.
38
+ # If you are not using ActiveRecord, you can remove these lines.
39
+ begin
40
+ #ActiveRecord::Migration.maintain_test_schema!
41
+ rescue ActiveRecord::PendingMigrationError => e
42
+ abort e.to_s.strip
43
+ end
44
+ RSpec.configure do |config|
45
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
46
+ config.fixture_paths = [
47
+ Rails.root.join('spec/fixtures')
48
+ ]
49
+
50
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
51
+ # examples within a transaction, remove the following line or assign false
52
+ # instead of true.
53
+ config.use_transactional_fixtures = true
54
+
55
+ # You can uncomment this line to turn off ActiveRecord support entirely.
56
+ # config.use_active_record = false
57
+
58
+ # RSpec Rails uses metadata to mix in different behaviours to your tests,
59
+ # for example enabling you to call `get` and `post` in request specs. e.g.:
60
+ #
61
+ # RSpec.describe UsersController, type: :request do
62
+ # # ...
63
+ # end
64
+ #
65
+ # The different available types are documented in the features, such as in
66
+ # https://rspec.info/features/7-0/rspec-rails
67
+ #
68
+ # You can also this infer these behaviours automatically by location, e.g.
69
+ # /spec/models would pull in the same behaviour as `type: :model` but this
70
+ # behaviour is considered legacy and will be removed in a future version.
71
+ #
72
+ # To enable this behaviour uncomment the line below.
73
+ # config.infer_spec_type_from_file_location!
74
+
75
+ # Filter lines from Rails gems in backtraces.
76
+ config.filter_rails_from_backtrace!
77
+ # arbitrary gems may also be filtered via:
78
+ # config.filter_gems_from_backtrace("gem name")
79
+
80
+ config.include FactoryBot::Syntax::Methods
81
+ config.include Dry::Monads[:result]
82
+ config.after :suite do
83
+ FileUtils.rm_rf(Dir[Rails.root.join('public', 'uploads')])
84
+ end
85
+ config.include FileStubber
86
+ config.include RepositoryStubber
87
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module FileStubber
4
+ def fixture_file(path, mime_type = nil, binary = false)
5
+ config = RSpec.configuration
6
+
7
+ if config.respond_to?(:fixture_paths) && config.fixture_paths && !File.exist?(path)
8
+ path = File.join(config.fixture_paths, path)
9
+ end
10
+
11
+ Rack::Test::UploadedFile.new(path, mime_type, binary)
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RepositoryStubber
4
+ def stub_repository(repository:, expected_output:, response: :success, params: nil)
5
+ monads = response.to_s.eql?('success') ? Dry::Monads::Success(expected_output) : Dry::Monads::Failure(expected_output)
6
+ expectation = allow(repository).to receive(:new)
7
+ expectation.with(params) if params
8
+ expectation.and_return(instance_double(repository, call: monads))
9
+ end
10
+ end
data/lib/rider-kick.rb CHANGED
@@ -5,10 +5,10 @@ require 'rider_kick/builders/abstract_active_record_entity_builder'
5
5
  require 'rider_kick/matchers/use_case_result'
6
6
  require 'rider_kick/use_cases/abstract_use_case'
7
7
  require 'rider_kick/use_cases/contract'
8
-
9
- require 'rider_kick/types'
8
+ require 'rider_kick/configuration'
10
9
  require 'rider_kick/version'
11
10
 
12
11
  module RiderKick
13
- class Error < StandardError; end
12
+ extend RiderKick::Configuration
13
+ define_setting :scope_owner_column, ''
14
14
  end
@@ -9,7 +9,7 @@ module RiderKick
9
9
  class AbstractActiveRecordEntityBuilder
10
10
  # @param [Class] A Dry::Struct based entity that this builder will construct instances of
11
11
  def self.acts_as_builder_for_entity(entity_class)
12
- @has_many_builders = []
12
+ @has_many_builders = []
13
13
  @belongs_to_builders = []
14
14
 
15
15
  define_singleton_method :has_many_builders do
@@ -36,8 +36,9 @@ module RiderKick
36
36
  end
37
37
 
38
38
  # @param [ActiveRecord::Base] An ActiveRecord model to map to the entity
39
- def initialize(params)
39
+ def initialize(params, *args)
40
40
  @params = params
41
+ @args = args
41
42
  end
42
43
 
43
44
  def build
@@ -47,25 +48,26 @@ module RiderKick
47
48
  private
48
49
 
49
50
  attr_reader :params
51
+ attr_reader :args
50
52
 
51
53
  def entity_attribute_names
52
54
  @entity_attributes ||= begin
53
- if entity_class.respond_to?(:schema) # Dry::Struct
54
- schema_keys = entity_class.schema.keys
55
- elsif entity_class.respond_to?(:decorator) # T::Struct
56
- schema_keys = entity_class.decorator.props.keys
57
- else
58
- raise 'Cannot determine schema format'
59
- end
60
- first_key = schema_keys.first
61
- if first_key.is_a?(Symbol)
62
- schema_keys
63
- elsif first_key.respond_to?(:name)
64
- schema_keys.map(&:name)
65
- else
66
- raise 'Cannot determine schema format'
67
- end
68
- end
55
+ if entity_class.respond_to?(:schema) # Dry::Struct
56
+ schema_keys = entity_class.schema.keys
57
+ elsif entity_class.respond_to?(:decorator) # T::Struct
58
+ schema_keys = entity_class.decorator.props.keys
59
+ else
60
+ raise 'Cannot determine schema format'
61
+ end
62
+ first_key = schema_keys.first
63
+ if first_key.is_a?(Symbol)
64
+ schema_keys
65
+ elsif first_key.respond_to?(:name)
66
+ schema_keys.map(&:name)
67
+ else
68
+ raise 'Cannot determine schema format'
69
+ end
70
+ end
69
71
  end
70
72
 
71
73
  def params_attributes
@@ -85,7 +87,7 @@ module RiderKick
85
87
  def attributes_for_belongs_to_relations
86
88
  self.class.belongs_to_builders.map do |belongs_to_builder_config|
87
89
  relation_name, builder_class = belongs_to_builder_config
88
- relation = @params.public_send(relation_name)
90
+ relation = @params.public_send(relation_name)
89
91
 
90
92
  [
91
93
  relation_name,
@@ -97,8 +99,8 @@ module RiderKick
97
99
  def attributes_for_has_many_relations
98
100
  self.class.has_many_builders.map do |has_many_builder_config|
99
101
  relation_name, builder_class = has_many_builder_config
100
- relations = @params.public_send(relation_name)
101
- built_relations = relations.map do |relation|
102
+ relations = @params.public_send(relation_name)
103
+ built_relations = relations.map do |relation|
102
104
  builder_class.new(relation).build
103
105
  end
104
106
 
@@ -0,0 +1,116 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe RiderKick::Builders::AbstractActiveRecordEntityBuilder do
6
+ let(:entity_class) do
7
+ Class.new(Dry::Struct) do
8
+ attribute :id, Types::String
9
+ attribute :name, Types::String
10
+ attribute :related_entities, Types::Array.of(Types::Hash).optional.default([].freeze)
11
+ attribute :other_entity, Types::Hash.optional.default(nil)
12
+ end
13
+ end
14
+
15
+ let(:builder_class) do
16
+ entity = entity_class
17
+ Class.new(described_class) do
18
+ acts_as_builder_for_entity(entity)
19
+ end
20
+ end
21
+
22
+ let(:params) { instance_double('ActiveRecord::Base', attributes: { 'id' => '123e4567-e89b-12d3-a456-426614174000', 'name' => 'Sample Name' }) }
23
+ let(:extra_param1) { 'extra1' }
24
+ let(:extra_param2) { 'extra2' }
25
+
26
+ subject(:builder) { builder_class.new(params, extra_param1, extra_param2) }
27
+
28
+ describe '#initialize' do
29
+ it 'initializes with params and extra arguments' do
30
+ expect { builder_class.new(params, extra_param1, extra_param2) }.not_to raise_error
31
+ expect(builder.instance_variable_get(:@params)).to eq(params)
32
+ expect(builder.instance_variable_get(:@args)).to eq([extra_param1, extra_param2])
33
+ end
34
+ end
35
+
36
+ describe '.acts_as_builder_for_entity' do
37
+ it 'sets entity class as a private method' do
38
+ expect(builder.send(:entity_class)).to eq(entity_class)
39
+ end
40
+ end
41
+
42
+ describe '.has_many' do
43
+ let(:related_entity_class) { double('RelatedEntityClass') }
44
+ let(:relation_name) { :related_entities }
45
+
46
+ before do
47
+ builder_class.has_many relation_name, use: related_entity_class
48
+ allow(params).to receive(relation_name).and_return([double('Relation')])
49
+ allow(related_entity_class).to receive(:new).and_return(double(build: { id: 'abc123', name: 'Related' }))
50
+ end
51
+
52
+ it 'adds to has_many_builders' do
53
+ expect(builder_class.has_many_builders).to include([relation_name, related_entity_class])
54
+ end
55
+
56
+ it 'builds has_many relations' do
57
+ result = builder.send(:attributes_for_has_many_relations)
58
+ expect(result[relation_name]).to eq([{ id: 'abc123', name: 'Related' }])
59
+ end
60
+ end
61
+
62
+ describe '.belongs_to' do
63
+ let(:other_entity_class) { double('OtherEntityClass') }
64
+ let(:relation_name) { :other_entity }
65
+
66
+ before do
67
+ builder_class.belongs_to relation_name, use: other_entity_class
68
+ allow(params).to receive(relation_name).and_return(double('Relation'))
69
+ allow(other_entity_class).to receive(:new).and_return(double(build: { id: 'xyz789', name: 'Other' }))
70
+ end
71
+
72
+ it 'adds to belongs_to_builders' do
73
+ expect(builder_class.belongs_to_builders).to include([relation_name, other_entity_class])
74
+ end
75
+
76
+ it 'builds belongs_to relation' do
77
+ result = builder.send(:attributes_for_belongs_to_relations)
78
+ expect(result[relation_name]).to eq({ id: 'xyz789', name: 'Other' })
79
+ end
80
+ end
81
+
82
+ describe '#build' do
83
+ let(:attributes) { { id: '123e4567-e89b-12d3-a456-426614174000', name: 'Sample Name' } }
84
+
85
+ it 'builds the entity with AR attributes' do
86
+ allow(builder).to receive(:ar_attributes_for_entity).and_return(attributes)
87
+ entity = builder.build
88
+ expect(entity.id).to eq('123e4567-e89b-12d3-a456-426614174000')
89
+ expect(entity.name).to eq('Sample Name')
90
+ end
91
+
92
+ context 'when has_many and belongs_to relations exist' do
93
+ let(:related_entity_class) { double('RelatedEntityClass') }
94
+ let(:other_entity_class) { double('OtherEntityClass') }
95
+
96
+ before do
97
+ builder_class.has_many :related_entities, use: related_entity_class
98
+ builder_class.belongs_to :other_entity, use: other_entity_class
99
+
100
+ allow(params).to receive(:related_entities).and_return([double('Relation')])
101
+ allow(params).to receive(:other_entity).and_return(double('Relation'))
102
+
103
+ allow(related_entity_class).to receive(:new).and_return(double(build: { id: 'abc123', name: 'Related' }))
104
+ allow(other_entity_class).to receive(:new).and_return(double(build: { id: 'xyz789', name: 'Other' }))
105
+ end
106
+
107
+ it 'builds the entity with all attributes' do
108
+ entity = builder.build
109
+ expect(entity.id).to eq('123e4567-e89b-12d3-a456-426614174000')
110
+ expect(entity.name).to eq('Sample Name')
111
+ expect(entity.related_entities).to eq([{ id: 'abc123', name: 'Related' }])
112
+ expect(entity.other_entity).to eq({ id: 'xyz789', name: 'Other' })
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RiderKick
4
+ module Configuration
5
+ def setup
6
+ yield self
7
+ end
8
+
9
+ def define_setting(name, default = nil)
10
+ class_variable_set("@@#{name}", default)
11
+
12
+ define_class_method "#{name}=" do |value|
13
+ class_variable_set("@@#{name}", value)
14
+ end
15
+
16
+ define_class_method name do
17
+ class_variable_get("@@#{name}")
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def define_class_method(name, &block)
24
+ (class << self; self; end).instance_eval do
25
+ define_method name, &block
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'spec_helper'
3
4
  require 'rider_kick/matchers/use_case_result'
4
5
 
5
6
  RSpec.describe RiderKick::Matchers::UseCaseResult do
@@ -2,9 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'dry-types'
5
-
6
5
  module Types
7
6
  include Dry.Types()
8
- # File = Types.Instance(::File) | Types.Instance(ActionDispatch::Http::UploadedFile)
9
- # public_constant :File
10
7
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RiderKick
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.3'
5
5
  public_constant :VERSION
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rider-kick
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kotaro Minami
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-01 00:00:00.000000000 Z
11
+ date: 2024-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-matcher
@@ -149,8 +149,57 @@ files:
149
149
  - LICENSE.txt
150
150
  - README.md
151
151
  - Rakefile
152
+ - lib/generators/rider_kick/USAGE
153
+ - lib/generators/rider_kick/clean_arch_generator.rb
154
+ - lib/generators/rider_kick/init_generator.rb
155
+ - lib/generators/rider_kick/scaffold_generator.rb
156
+ - lib/generators/rider_kick/structure_generator.rb
157
+ - lib/generators/rider_kick/templates/.gitignore
158
+ - lib/generators/rider_kick/templates/.rspec
159
+ - lib/generators/rider_kick/templates/.rubocop.yml
160
+ - lib/generators/rider_kick/templates/README.md
161
+ - lib/generators/rider_kick/templates/config/database.yml
162
+ - lib/generators/rider_kick/templates/config/initializers/clean_archithecture.rb.tt
163
+ - lib/generators/rider_kick/templates/config/initializers/generators.rb.tt
164
+ - lib/generators/rider_kick/templates/config/initializers/hashie.rb.tt
165
+ - lib/generators/rider_kick/templates/config/initializers/pagy.rb.tt
166
+ - lib/generators/rider_kick/templates/config/initializers/rider_kick.rb
167
+ - lib/generators/rider_kick/templates/config/initializers/version.rb.tt
168
+ - lib/generators/rider_kick/templates/config/initializers/zeitwerk.rb.tt
169
+ - lib/generators/rider_kick/templates/db/migrate/20220613145533_init_database.rb
170
+ - lib/generators/rider_kick/templates/db/structures/example.yaml.tt
171
+ - lib/generators/rider_kick/templates/domains/core/builders/builder.rb.tt
172
+ - lib/generators/rider_kick/templates/domains/core/builders/error.rb.tt
173
+ - lib/generators/rider_kick/templates/domains/core/builders/pagination.rb.tt
174
+ - lib/generators/rider_kick/templates/domains/core/entities/entity.rb.tt
175
+ - lib/generators/rider_kick/templates/domains/core/entities/error.rb.tt
176
+ - lib/generators/rider_kick/templates/domains/core/entities/pagination.rb.tt
177
+ - lib/generators/rider_kick/templates/domains/core/repositories/abstract_repository.rb.tt
178
+ - lib/generators/rider_kick/templates/domains/core/repositories/create.rb.tt
179
+ - lib/generators/rider_kick/templates/domains/core/repositories/destroy.rb.tt
180
+ - lib/generators/rider_kick/templates/domains/core/repositories/fetch_by_id.rb.tt
181
+ - lib/generators/rider_kick/templates/domains/core/repositories/list.rb.tt
182
+ - lib/generators/rider_kick/templates/domains/core/repositories/update.rb.tt
183
+ - lib/generators/rider_kick/templates/domains/core/use_cases/contract/default.rb.tt
184
+ - lib/generators/rider_kick/templates/domains/core/use_cases/contract/pagination.rb.tt
185
+ - lib/generators/rider_kick/templates/domains/core/use_cases/create.rb.tt
186
+ - lib/generators/rider_kick/templates/domains/core/use_cases/destroy.rb.tt
187
+ - lib/generators/rider_kick/templates/domains/core/use_cases/fetch_by_id.rb.tt
188
+ - lib/generators/rider_kick/templates/domains/core/use_cases/get_version.rb.tt
189
+ - lib/generators/rider_kick/templates/domains/core/use_cases/list.rb.tt
190
+ - lib/generators/rider_kick/templates/domains/core/use_cases/update.rb.tt
191
+ - lib/generators/rider_kick/templates/domains/core/utils/request_methods.rb.tt
192
+ - lib/generators/rider_kick/templates/env.development
193
+ - lib/generators/rider_kick/templates/env.production
194
+ - lib/generators/rider_kick/templates/env.test
195
+ - lib/generators/rider_kick/templates/spec/fixtures/sample.pdf
196
+ - lib/generators/rider_kick/templates/spec/rails_helper.rb
197
+ - lib/generators/rider_kick/templates/spec/support/file_stuber.rb
198
+ - lib/generators/rider_kick/templates/spec/support/repository_stubber.rb
152
199
  - lib/rider-kick.rb
153
200
  - lib/rider_kick/builders/abstract_active_record_entity_builder.rb
201
+ - lib/rider_kick/builders/abstract_active_record_entity_builder_spec.rb
202
+ - lib/rider_kick/configuration.rb
154
203
  - lib/rider_kick/entities/failure_details.rb
155
204
  - lib/rider_kick/matchers/use_case_result.rb
156
205
  - lib/rider_kick/matchers/use_case_result_spec.rb
@@ -158,7 +207,6 @@ files:
158
207
  - lib/rider_kick/use_cases/abstract_use_case.rb
159
208
  - lib/rider_kick/use_cases/contract.rb
160
209
  - lib/rider_kick/version.rb
161
- - sig/rider_kick.rbs
162
210
  homepage: https://github.com/kotaroisme/rider-kick
163
211
  licenses:
164
212
  - MIT
@@ -178,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
226
  - !ruby/object:Gem::Version
179
227
  version: '0'
180
228
  requirements: []
181
- rubygems_version: 3.5.18
229
+ rubygems_version: 3.5.22
182
230
  signing_key:
183
231
  specification_version: 4
184
232
  summary: Clean Architecture Framework.
data/sig/rider_kick.rbs DELETED
@@ -1,4 +0,0 @@
1
- module RiderKick
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end