rage_arch 0.1.2 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/generators/rage_arch/ar_dep_generator.rb +1 -1
- data/lib/generators/rage_arch/dep_switch_generator.rb +16 -16
- data/lib/generators/rage_arch/install_generator.rb +1 -1
- data/lib/generators/rage_arch/scaffold_generator.rb +2 -2
- data/lib/rage_arch/container.rb +1 -1
- data/lib/rage_arch/deps/active_record.rb +1 -1
- data/lib/rage_arch/event_publisher.rb +1 -1
- data/lib/rage_arch/fake_event_publisher.rb +1 -1
- data/lib/rage_arch/rspec_matchers.rb +1 -1
- data/lib/rage_arch/version.rb +1 -1
- data/lib/rage_arch.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4be8aa2c59b8c0e1f4d15a2af2c9075a21a674cf80401ddd7e8ad655ce3a6f8
|
|
4
|
+
data.tar.gz: e2cccfe9fec1c8e630b2b3eff45eab25ec208075dcce4d54422f913693b1f14e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c03dd919d2b32226ec4ea0975c2d748d2e4f6049b44a5e635e192b9d5cecac120b68ec600151e2c08ca94e7b5f4a28a456ffb4cf92365c516f13de1ba250efa6
|
|
7
|
+
data.tar.gz: 2087a0af99636d741197191157c7f2c395ba81183363c656ead9e437fba232360f6d2072a428f2fb0a363ee4743c2646182e8c46dfa38075804680df22b11bf6
|
data/README.md
CHANGED
|
@@ -15,7 +15,7 @@ module RageArch
|
|
|
15
15
|
def create_ar_dep
|
|
16
16
|
@extra_methods = extra_methods
|
|
17
17
|
template "ar_dep.rb.tt", File.join("app/deps", module_dir, "#{dep_file_name}.rb")
|
|
18
|
-
say "Register in config/initializers/rage_arch.rb:
|
|
18
|
+
say "Register in config/initializers/rage_arch.rb: RageArch.register(:#{symbol_name}, #{full_class_name}.new)", :green
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
STANDARD_AR_METHODS = %i[build find save update destroy list].freeze
|
|
@@ -18,7 +18,7 @@ module RageArch
|
|
|
18
18
|
if options.empty?
|
|
19
19
|
say "No implementations found for :#{symbol}.", :red
|
|
20
20
|
say "Create a dep with: rails g rage_arch:dep #{symbol} [ClassName]"
|
|
21
|
-
say "Or add
|
|
21
|
+
say "Or add RageArch.register_ar(:#{symbol}, Model) in config/initializers/rage_arch.rb", :red
|
|
22
22
|
return
|
|
23
23
|
end
|
|
24
24
|
chosen = if class_name_arg.present?
|
|
@@ -48,19 +48,19 @@ module RageArch
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def initializer_path
|
|
51
|
-
File.join(destination_root, "config", "initializers", "
|
|
51
|
+
File.join(destination_root, "config", "initializers", "rage_arch.rb")
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def find_ar_registration(symbol)
|
|
55
55
|
path = initializer_path
|
|
56
56
|
return nil unless File.exist?(path)
|
|
57
57
|
content = File.read(path)
|
|
58
|
-
# Match active or commented:
|
|
58
|
+
# Match active or commented: RageArch.register_ar(:post_store, Post) or RageArch.register_ar :post_store, Post
|
|
59
59
|
content.each_line do |line|
|
|
60
60
|
stripped = line.strip
|
|
61
61
|
next if stripped.start_with?("#")
|
|
62
|
-
if stripped =~ /
|
|
63
|
-
stripped =~ /
|
|
62
|
+
if stripped =~ /RageArch\.register_ar\s*\(\s*:\s*#{Regexp.escape(symbol)}\s*,\s*(\w+)\s*\)/ ||
|
|
63
|
+
stripped =~ /RageArch\.register_ar\s+:\s*#{Regexp.escape(symbol)}\s*,\s*(\w+)/
|
|
64
64
|
return $1
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -68,8 +68,8 @@ module RageArch
|
|
|
68
68
|
content.each_line do |line|
|
|
69
69
|
stripped = line.strip.delete_prefix("#").strip
|
|
70
70
|
next if stripped.empty?
|
|
71
|
-
if stripped =~ /
|
|
72
|
-
stripped =~ /
|
|
71
|
+
if stripped =~ /RageArch\.register_ar\s*\(\s*:\s*#{Regexp.escape(symbol)}\s*,\s*(\w+)\s*\)/ ||
|
|
72
|
+
stripped =~ /RageArch\.register_ar\s+:\s*#{Regexp.escape(symbol)}\s*,\s*(\w+)/
|
|
73
73
|
return $1
|
|
74
74
|
end
|
|
75
75
|
end
|
|
@@ -160,20 +160,20 @@ module RageArch
|
|
|
160
160
|
content = comment_line_matching(content, symbol, :register_ar)
|
|
161
161
|
# Uncomment or add the chosen registration
|
|
162
162
|
chosen_line = option[:type] == :ar ?
|
|
163
|
-
"
|
|
164
|
-
"
|
|
163
|
+
"RageArch.register_ar(:#{symbol}, #{option[:model]})" :
|
|
164
|
+
"RageArch.register(:#{symbol}, #{option[:name]}.new)"
|
|
165
165
|
content = uncomment_or_add(content, symbol, option, chosen_line)
|
|
166
166
|
File.write(path, content)
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
def comment_line_matching(content, symbol, form)
|
|
170
170
|
if form == :register
|
|
171
|
-
content.gsub(/^(\s*)(
|
|
171
|
+
content.gsub(/^(\s*)(RageArch\.register\(:#{Regexp.escape(symbol)},\s*\S+\.new\))\s*$/, '\1# \2')
|
|
172
172
|
else
|
|
173
173
|
# register_ar with parens or with space
|
|
174
174
|
content
|
|
175
|
-
.gsub(/^(\s*)(
|
|
176
|
-
.gsub(/^(\s*)(
|
|
175
|
+
.gsub(/^(\s*)(RageArch\.register_ar\s*\(\s*:\s*#{Regexp.escape(symbol)}\s*,\s*\S+\s*\))\s*$/, '\1# \2')
|
|
176
|
+
.gsub(/^(\s*)(RageArch\.register_ar\s+:\s*#{Regexp.escape(symbol)}\s*,\s*\S+)\s*$/, '\1# \2')
|
|
177
177
|
end
|
|
178
178
|
end
|
|
179
179
|
|
|
@@ -182,18 +182,18 @@ module RageArch
|
|
|
182
182
|
model = option[:model]
|
|
183
183
|
# Uncomment if there is a commented register_ar line for this symbol and model
|
|
184
184
|
content = content.gsub(
|
|
185
|
-
/^(\s*)#\s*(
|
|
185
|
+
/^(\s*)#\s*(RageArch\.register_ar\s*\(\s*:\s*#{Regexp.escape(symbol)}\s*,\s*#{Regexp.escape(model)}\s*\))\s*$/,
|
|
186
186
|
'\1\2'
|
|
187
187
|
)
|
|
188
188
|
content = content.gsub(
|
|
189
|
-
/^(\s*)#\s*(
|
|
189
|
+
/^(\s*)#\s*(RageArch\.register_ar\s+:\s*#{Regexp.escape(symbol)}\s*,\s*#{Regexp.escape(model)})\s*$/,
|
|
190
190
|
'\1\2'
|
|
191
191
|
)
|
|
192
192
|
else
|
|
193
193
|
class_name = option[:name]
|
|
194
|
-
# Uncomment if there is a commented
|
|
194
|
+
# Uncomment if there is a commented RageArch.register line for this symbol and class
|
|
195
195
|
content = content.gsub(
|
|
196
|
-
/^(\s*)#\s*(
|
|
196
|
+
/^(\s*)#\s*(RageArch\.register\(:#{Regexp.escape(symbol)},\s*#{Regexp.escape(class_name)}\.new\))\s*$/,
|
|
197
197
|
'\1\2'
|
|
198
198
|
)
|
|
199
199
|
end
|
|
@@ -12,7 +12,7 @@ module RageArch
|
|
|
12
12
|
class_option :skip_model, type: :boolean, default: false, desc: "Skip model and migration (use when model already exists)"
|
|
13
13
|
class_option :api, type: :boolean, default: false, desc: "Generate API-only controller (JSON responses, no views)"
|
|
14
14
|
|
|
15
|
-
desc "Generate a full
|
|
15
|
+
desc "Generate a full RageArch CRUD: model, migration, use cases (list/show/create/update/destroy), dep (AR), controller, and routes. With --api: JSON responses only, no views."
|
|
16
16
|
def create_all
|
|
17
17
|
create_model_and_migration
|
|
18
18
|
create_use_cases
|
|
@@ -70,7 +70,7 @@ module RageArch
|
|
|
70
70
|
return unless File.exist?(initializer_path)
|
|
71
71
|
content = File.read(initializer_path)
|
|
72
72
|
return if content.include?("register_ar(:#{repo_symbol})")
|
|
73
|
-
inject_line = "
|
|
73
|
+
inject_line = " RageArch.register_ar(:#{repo_symbol}, #{model_class_name})\n"
|
|
74
74
|
content.sub!(/(Rails\.application\.config\.after_initialize do\s*\n)/m, "\\1#{inject_line}")
|
|
75
75
|
File.write(initializer_path, content)
|
|
76
76
|
say_status :inject, "config/initializers/rage_arch.rb (register_ar :#{repo_symbol})", :green
|
data/lib/rage_arch/container.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module RageArch
|
|
4
4
|
# Container to register and resolve dependencies by symbol.
|
|
5
|
-
# Usage:
|
|
5
|
+
# Usage: RageArch.register(:order_store, MyAdapter.new); RageArch.resolve(:order_store)
|
|
6
6
|
class Container
|
|
7
7
|
class << self
|
|
8
8
|
def register(symbol, implementation = nil, &block)
|
|
@@ -4,7 +4,7 @@ module RageArch
|
|
|
4
4
|
module Deps
|
|
5
5
|
# Helper to use an Active Record model as a dep (minimal adapter).
|
|
6
6
|
# Usage: RageArch::Deps::ActiveRecord.for(Order) → object exposing build, find, etc. on Order.
|
|
7
|
-
# In the container:
|
|
7
|
+
# In the container: RageArch.register(:order_store, RageArch::Deps::ActiveRecord.for(Order))
|
|
8
8
|
class ActiveRecord
|
|
9
9
|
def self.for(model_class)
|
|
10
10
|
new(model_class)
|
|
@@ -8,7 +8,7 @@ module RageArch
|
|
|
8
8
|
# Setup in config/initializers/rage_arch.rb:
|
|
9
9
|
# publisher = RageArch::EventPublisher.new
|
|
10
10
|
# RageArch::UseCase::Base.wire_subscriptions_to(publisher)
|
|
11
|
-
#
|
|
11
|
+
# RageArch.register(:event_publisher, publisher)
|
|
12
12
|
class EventPublisher
|
|
13
13
|
def initialize
|
|
14
14
|
@handlers = Hash.new { |h, k| h[k] = [] }
|
|
@@ -5,7 +5,7 @@ module RageArch
|
|
|
5
5
|
# Use it to assert that a use case (or code) published expected events.
|
|
6
6
|
#
|
|
7
7
|
# publisher = RageArch::FakeEventPublisher.new
|
|
8
|
-
#
|
|
8
|
+
# RageArch.register(:event_publisher, publisher)
|
|
9
9
|
# RageArch::UseCase::Base.build(:create_post).call(title: "Hi")
|
|
10
10
|
# expect(publisher.published).to include(
|
|
11
11
|
# hash_including(event: :post_created, post_id: kind_of(Integer))
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module RageArch
|
|
4
|
-
# RSpec matchers and helpers for testing
|
|
4
|
+
# RSpec matchers and helpers for testing RageArch use cases and results.
|
|
5
5
|
# In spec_helper.rb or rails_helper.rb add:
|
|
6
6
|
# require "rage_arch/rspec_matchers"
|
|
7
7
|
# Then use: expect(result).to succeed_with(post: post) or expect(result).to fail_with_errors(["error"])
|
data/lib/rage_arch/version.rb
CHANGED
data/lib/rage_arch.rb
CHANGED
|
@@ -16,7 +16,7 @@ module RageArch
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
# Registers a dep that uses Active Record for the given model.
|
|
19
|
-
# Example:
|
|
19
|
+
# Example: RageArch.register_ar(:user_store, User)
|
|
20
20
|
def register_ar(symbol, model_class)
|
|
21
21
|
register(symbol, Deps::ActiveRecord.for(model_class))
|
|
22
22
|
end
|