trailblazer-future 2.1.0.rc1
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 +7 -0
- data/.gitignore +12 -0
- data/.travis.yml +6 -0
- data/CHANGES.md +4 -0
- data/LICENSE.txt +9 -0
- data/README.md +48 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gems.rb +3 -0
- data/lib/trailblazer/future.rb +9 -0
- data/lib/trailblazer/future/version.rb +5 -0
- data/lib/trailblazer/v2_1/activity.rb +123 -0
- data/lib/trailblazer/v2_1/activity/config.rb +37 -0
- data/lib/trailblazer/v2_1/activity/dsl/add_task.rb +22 -0
- data/lib/trailblazer/v2_1/activity/dsl/helper.rb +68 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic.rb +36 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder.rb +101 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/default_normalizer.rb +26 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/fast_track.rb +118 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/normalizer.rb +113 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/path.rb +105 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/railway.rb +97 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/builder/state.rb +58 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/finalizer.rb +51 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/generate.rb +62 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/merge.rb +16 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/process_options.rb +76 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/structure/alterations.rb +44 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/structure/plus_poles.rb +85 -0
- data/lib/trailblazer/v2_1/activity/dsl/magnetic/structure/polarization.rb +23 -0
- data/lib/trailblazer/v2_1/activity/dsl/record.rb +11 -0
- data/lib/trailblazer/v2_1/activity/dsl/schema/dependencies.rb +46 -0
- data/lib/trailblazer/v2_1/activity/dsl/schema/sequence.rb +46 -0
- data/lib/trailblazer/v2_1/activity/dsl/strategy/build_state.rb +32 -0
- data/lib/trailblazer/v2_1/activity/dsl/strategy/fast_track.rb +24 -0
- data/lib/trailblazer/v2_1/activity/dsl/strategy/path.rb +26 -0
- data/lib/trailblazer/v2_1/activity/dsl/strategy/plan.rb +36 -0
- data/lib/trailblazer/v2_1/activity/dsl/strategy/railway.rb +23 -0
- data/lib/trailblazer/v2_1/activity/interface.rb +16 -0
- data/lib/trailblazer/v2_1/activity/introspect.rb +167 -0
- data/lib/trailblazer/v2_1/activity/present.rb +95 -0
- data/lib/trailblazer/v2_1/activity/structures.rb +57 -0
- data/lib/trailblazer/v2_1/activity/task_builder.rb +41 -0
- data/lib/trailblazer/v2_1/activity/task_wrap.rb +40 -0
- data/lib/trailblazer/v2_1/activity/task_wrap/call_task.rb +19 -0
- data/lib/trailblazer/v2_1/activity/task_wrap/merge.rb +23 -0
- data/lib/trailblazer/v2_1/activity/task_wrap/runner.rb +62 -0
- data/lib/trailblazer/v2_1/activity/task_wrap/trace.rb +44 -0
- data/lib/trailblazer/v2_1/activity/task_wrap/variable_mapping.rb +162 -0
- data/lib/trailblazer/v2_1/activity/testing.rb +32 -0
- data/lib/trailblazer/v2_1/activity/trace.rb +97 -0
- data/lib/trailblazer/v2_1/circuit.rb +71 -0
- data/lib/trailblazer/v2_1/container_chain.rb +45 -0
- data/lib/trailblazer/v2_1/context.rb +79 -0
- data/lib/trailblazer/v2_1/deprecation/call.rb +46 -0
- data/lib/trailblazer/v2_1/deprecation/context.rb +43 -0
- data/lib/trailblazer/v2_1/dsl.rb +47 -0
- data/lib/trailblazer/v2_1/macro.rb +11 -0
- data/lib/trailblazer/v2_1/macro/contract.rb +5 -0
- data/lib/trailblazer/v2_1/operation.rb +91 -0
- data/lib/trailblazer/v2_1/operation/auto_inject.rb +47 -0
- data/lib/trailblazer/v2_1/operation/callable.rb +42 -0
- data/lib/trailblazer/v2_1/operation/class_dependencies.rb +25 -0
- data/lib/trailblazer/v2_1/operation/contract.rb +61 -0
- data/lib/trailblazer/v2_1/operation/deprecated_macro.rb +19 -0
- data/lib/trailblazer/v2_1/operation/deprecations.rb +21 -0
- data/lib/trailblazer/v2_1/operation/guard.rb +18 -0
- data/lib/trailblazer/v2_1/operation/heritage.rb +30 -0
- data/lib/trailblazer/v2_1/operation/inject.rb +36 -0
- data/lib/trailblazer/v2_1/operation/inspect.rb +79 -0
- data/lib/trailblazer/v2_1/operation/model.rb +50 -0
- data/lib/trailblazer/v2_1/operation/module.rb +29 -0
- data/lib/trailblazer/v2_1/operation/nested.rb +98 -0
- data/lib/trailblazer/v2_1/operation/persist.rb +14 -0
- data/lib/trailblazer/v2_1/operation/policy.rb +44 -0
- data/lib/trailblazer/v2_1/operation/public_call.rb +55 -0
- data/lib/trailblazer/v2_1/operation/pundit.rb +38 -0
- data/lib/trailblazer/v2_1/operation/railway.rb +32 -0
- data/lib/trailblazer/v2_1/operation/railway/fast_track.rb +13 -0
- data/lib/trailblazer/v2_1/operation/railway/macaroni.rb +23 -0
- data/lib/trailblazer/v2_1/operation/railway/normalizer.rb +58 -0
- data/lib/trailblazer/v2_1/operation/railway/task_builder.rb +37 -0
- data/lib/trailblazer/v2_1/operation/rescue.rb +42 -0
- data/lib/trailblazer/v2_1/operation/responder.rb +18 -0
- data/lib/trailblazer/v2_1/operation/result.rb +30 -0
- data/lib/trailblazer/v2_1/operation/test.rb +17 -0
- data/lib/trailblazer/v2_1/operation/trace.rb +46 -0
- data/lib/trailblazer/v2_1/operation/validate.rb +76 -0
- data/lib/trailblazer/v2_1/operation/wrap.rb +83 -0
- data/lib/trailblazer/v2_1/option.rb +78 -0
- data/lib/trailblazer/v2_1/rails.rb +12 -0
- data/lib/trailblazer/v2_1/rails/cell.rb +22 -0
- data/lib/trailblazer/v2_1/rails/controller.rb +66 -0
- data/lib/trailblazer/v2_1/rails/form.rb +21 -0
- data/lib/trailblazer/v2_1/rails/railtie.rb +31 -0
- data/lib/trailblazer/v2_1/rails/railtie/extend_application_controller.rb +28 -0
- data/lib/trailblazer/v2_1/rails/railtie/loader.rb +58 -0
- data/lib/trailblazer/v2_1/rails/test/integration.rb +6 -0
- data/lib/trailblazer/v2_1/versions.txt +7 -0
- data/test/rails5.0/.gitignore +17 -0
- data/test/rails5.0/Gemfile +21 -0
- data/test/rails5.0/Rakefile +3 -0
- data/test/rails5.0/app/concepts/artist/cell/dashboard.rb +7 -0
- data/test/rails5.0/app/concepts/artist/cell/show.rb +4 -0
- data/test/rails5.0/app/concepts/artist/view/dashboard.erb +4 -0
- data/test/rails5.0/app/concepts/artist/view/show.erb +1 -0
- data/test/rails5.0/app/concepts/params/operation/with_args.rb +5 -0
- data/test/rails5.0/app/concepts/song/contract/form.rb +6 -0
- data/test/rails5.0/app/concepts/song/operation/create.rb +15 -0
- data/test/rails5.0/app/concepts/song/operation/show.rb +3 -0
- data/test/rails5.0/app/concepts/song/operation/update.rb +15 -0
- data/test/rails5.0/app/controllers/application_controller.rb +46 -0
- data/test/rails5.0/app/controllers/args_controller.rb +5 -0
- data/test/rails5.0/app/controllers/artists_controller.rb +24 -0
- data/test/rails5.0/app/controllers/params_controller.rb +11 -0
- data/test/rails5.0/app/controllers/songs_controller.rb +35 -0
- data/test/rails5.0/app/models/artist.rb +2 -0
- data/test/rails5.0/app/models/song.rb +2 -0
- data/test/rails5.0/app/views/args/with_args.html.erb +1 -0
- data/test/rails5.0/app/views/layouts/application.html.erb +2 -0
- data/test/rails5.0/app/views/songs/edit.html.erb +4 -0
- data/test/rails5.0/app/views/songs/new.html.erb +5 -0
- data/test/rails5.0/app/views/songs/new_with_result.html.erb +3 -0
- data/test/rails5.0/app/views/songs/show.html.erb +3 -0
- data/test/rails5.0/bin/bundle +3 -0
- data/test/rails5.0/bin/rails +4 -0
- data/test/rails5.0/bin/rake +4 -0
- data/test/rails5.0/bin/setup +29 -0
- data/test/rails5.0/config.ru +4 -0
- data/test/rails5.0/config/application.rb +25 -0
- data/test/rails5.0/config/boot.rb +3 -0
- data/test/rails5.0/config/database.yml +21 -0
- data/test/rails5.0/config/environment.rb +5 -0
- data/test/rails5.0/config/environments/development.rb +41 -0
- data/test/rails5.0/config/environments/test.rb +42 -0
- data/test/rails5.0/config/initializers/assets.rb +11 -0
- data/test/rails5.0/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails5.0/config/initializers/cookies_serializer.rb +3 -0
- data/test/rails5.0/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/rails5.0/config/initializers/inflections.rb +16 -0
- data/test/rails5.0/config/initializers/mime_types.rb +4 -0
- data/test/rails5.0/config/initializers/session_store.rb +3 -0
- data/test/rails5.0/config/initializers/wrap_parameters.rb +14 -0
- data/test/rails5.0/config/locales/en.yml +23 -0
- data/test/rails5.0/config/routes.rb +15 -0
- data/test/rails5.0/config/secrets.yml +17 -0
- data/test/rails5.0/db/migrate/20161122145124_create_songs.rb +8 -0
- data/test/rails5.0/db/schema.rb +19 -0
- data/test/rails5.0/log/.keep +0 -0
- data/test/rails5.0/test/concepts/song/operation/create_test.rb +11 -0
- data/test/rails5.0/test/concepts/song/operation/update_test.rb +34 -0
- data/test/rails5.0/test/integration/.keep +0 -0
- data/test/rails5.0/test/integration/args_controller_test.rb +8 -0
- data/test/rails5.0/test/integration/artists_controller_test.rb +28 -0
- data/test/rails5.0/test/integration/params_controller_test.rb +8 -0
- data/test/rails5.0/test/integration/songs_controller_test.rb +40 -0
- data/test/rails5.0/test/test_helper.rb +7 -0
- data/test/test_helper.rb +5 -0
- data/trailblazer-future.gemspec +25 -0
- metadata +246 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Trailblazer::V2_1::Rails::Controller::Cell
|
|
2
|
+
private # rubocop:disable Lint/UselessAccessModifier
|
|
3
|
+
|
|
4
|
+
module Render
|
|
5
|
+
def render(cell = nil, options = {}, *, &block)
|
|
6
|
+
return super unless cell.kind_of?(::Cell::ViewModel)
|
|
7
|
+
|
|
8
|
+
render_cell(cell, options)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def render_cell(cell, options)
|
|
12
|
+
options = options.reverse_merge(layout: true)
|
|
13
|
+
|
|
14
|
+
# render the cell.
|
|
15
|
+
content = cell.()
|
|
16
|
+
|
|
17
|
+
render({html: content}.merge(options))
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
include Render unless method_defined?(:render_cell)
|
|
22
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module Trailblazer::V2_1::Rails
|
|
2
|
+
module Controller
|
|
3
|
+
def run_v21(operation, *dependencies)
|
|
4
|
+
result = if Rails.application.config.trailblazer.enable_tracing
|
|
5
|
+
_run_operation_v21(operation, :trace, *dependencies).tap { |r| _operation_trace(r) }
|
|
6
|
+
else
|
|
7
|
+
_run_operation_v21(operation, :call, *dependencies)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
_assign_trb_ivars(result)
|
|
11
|
+
|
|
12
|
+
yield(result) if result.success? && block_given?
|
|
13
|
+
|
|
14
|
+
@_result = result
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
alias run run_v21 unless method_defined?(:run)
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
# Override to tweak params. Not recommended.
|
|
22
|
+
# Use a deserializer instead.
|
|
23
|
+
def _run_params(params)
|
|
24
|
+
params
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# This is where we can inject Dry.RB containers and the like via dependencies.
|
|
28
|
+
def _run_runtime_options(ctx = {}, *dependencies)
|
|
29
|
+
[_run_options(ctx), *dependencies]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Override this to inject dependencies such as "current_user"
|
|
33
|
+
# into the runtime options.
|
|
34
|
+
def _run_options(ctx)
|
|
35
|
+
ctx
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def _run_operation_v21(operation, call_method, *dependencies)
|
|
39
|
+
operation.send(
|
|
40
|
+
call_method,
|
|
41
|
+
{params: _run_params(self.params)}.merge(*_run_runtime_options(*dependencies)) # rubocop:disable Style/RedundantSelf
|
|
42
|
+
)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def _operation_trace(result)
|
|
46
|
+
puts result.wtf?
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def _assign_trb_ivars(result)
|
|
50
|
+
@model = result[:model]
|
|
51
|
+
@form = _wrap_with_trb_form(result["contract.default"], @model.class)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def _wrap_with_trb_form(form, model)
|
|
55
|
+
Trailblazer::V2_1::Rails::Form.new(form, model)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
module Result
|
|
59
|
+
def result
|
|
60
|
+
@_result
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
include Result
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Trailblazer::V2_1
|
|
2
|
+
class Rails::Form < SimpleDelegator
|
|
3
|
+
def initialize(delegated, model_class)
|
|
4
|
+
super(delegated)
|
|
5
|
+
@model_class = model_class
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.name
|
|
9
|
+
# for whatever reason, validations climb up the inheritance tree and require _every_ class to have a name (4.1).
|
|
10
|
+
"Reform::Form"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def model_name
|
|
14
|
+
::ActiveModel::Name.new(self, nil, @model_class.to_s.camelize)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def to_model
|
|
18
|
+
self
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require "rails/railtie"
|
|
2
|
+
require "trailblazer/v2_1/loader"
|
|
3
|
+
require "trailblazer/v2_1/rails/railtie/extend_application_controller"
|
|
4
|
+
require "trailblazer/v2_1/rails/railtie/loader"
|
|
5
|
+
|
|
6
|
+
module Trailblazer::V2_1
|
|
7
|
+
class Railtie < ::Rails::Railtie
|
|
8
|
+
config.trailblazer = ActiveSupport::OrderedOptions.new
|
|
9
|
+
## Accept also an Array of controllers
|
|
10
|
+
config.trailblazer.application_controller ||= 'ActionController::Base'
|
|
11
|
+
config.trailblazer.enable_loader ||= true
|
|
12
|
+
config.trailblazer.use_loader ||= true # TODO: remove with next release
|
|
13
|
+
config.trailblazer.enable_tracing ||= false
|
|
14
|
+
|
|
15
|
+
include Loader
|
|
16
|
+
include ExtendApplicationController
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def reloader_class
|
|
21
|
+
# Rails 5.0.0.rc1 says:
|
|
22
|
+
# DEPRECATION WARNING: to_prepare is deprecated and will be removed from Rails 5.1
|
|
23
|
+
# (use ActiveSupport::Reloader.to_prepare instead)
|
|
24
|
+
if Gem.loaded_specs['activesupport'].version >= Gem::Version.new('5')
|
|
25
|
+
ActiveSupport::Reloader
|
|
26
|
+
else
|
|
27
|
+
ActionDispatch::Reloader
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "active_support/concern"
|
|
2
|
+
|
|
3
|
+
module Trailblazer::V2_1
|
|
4
|
+
class Railtie < ::Rails::Railtie
|
|
5
|
+
module ExtendApplicationController
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
initializer "trailblazer.application_controller", before: "finisher_hook" do
|
|
10
|
+
reloader_class.to_prepare do
|
|
11
|
+
ActiveSupport.on_load(:action_controller) do |app|
|
|
12
|
+
Trailblazer::V2_1::Railtie.extend_application_controller!(app)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def extend_application_controller!(app)
|
|
18
|
+
controllers = Array(::Rails.application.config.trailblazer.application_controller).map(&:to_s)
|
|
19
|
+
if controllers.include? app.to_s
|
|
20
|
+
app.send :include, Trailblazer::V2_1::Rails::Controller
|
|
21
|
+
app.send :include, Trailblazer::V2_1::Rails::Controller::Cell if defined?(::Cell)
|
|
22
|
+
end
|
|
23
|
+
app
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require "active_support/concern"
|
|
2
|
+
|
|
3
|
+
module Trailblazer::V2_1
|
|
4
|
+
class Railtie < ::Rails::Railtie
|
|
5
|
+
module Loader
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do # rubocop:disable Metrics/BlockLength
|
|
9
|
+
def self.load_concepts(app)
|
|
10
|
+
load_for(app)
|
|
11
|
+
|
|
12
|
+
engines.each { |engine| load_for(engine) }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.engines
|
|
16
|
+
::Rails.application.railties.select { |tie| tie.is_a?(::Rails::Engine) }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.load_for(app)
|
|
20
|
+
Trailblazer::V2_1::Loader.new.(prepend: AllModelFiles, root: app.root) { |file| require_dependency(file) }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Prepend model file, before the concept files like operation.rb get loaded.
|
|
24
|
+
ModelFile = lambda do |input, options|
|
|
25
|
+
model = "app/models/#{options[:name]}.rb"
|
|
26
|
+
File.exist?(model) ? [model] + input : input
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Load all model files before any TRB files.
|
|
30
|
+
AllModelFiles = lambda do |input, options|
|
|
31
|
+
Dir.glob("#{options[:root]}/app/models/**/*.rb").sort + input
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# This is to autoload Operation::Dispatch, etc. I'm simply assuming people find this helpful in Rails.
|
|
35
|
+
initializer "trailblazer.library_autoloading" do
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# thank you, http://stackoverflow.com/a/17573888/465070
|
|
39
|
+
initializer "trailblazer.install", after: "reform.form_extensions" do |app|
|
|
40
|
+
# the trb autoloading has to be run after initializers have been loaded, so we can tweak inclusion of features in
|
|
41
|
+
# initializers.
|
|
42
|
+
|
|
43
|
+
# TODO: remove me in the next version!
|
|
44
|
+
if config.trailblazer.use_loader.to_s.present?
|
|
45
|
+
warn "DEPRECATION WARNING [trailblazer-rails]: please use config.trailblazer.enable_loader" \
|
|
46
|
+
" to enable/disable the loader. config.trailblazer.use_loader will be removed from version > 2.1.6"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
if config.trailblazer.enable_loader || config.trailblazer.use_loader
|
|
50
|
+
reloader_class.to_prepare do
|
|
51
|
+
Trailblazer::V2_1::Railtie.load_concepts(app)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
|
2
|
+
#
|
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
|
6
|
+
|
|
7
|
+
# Ignore bundler config.
|
|
8
|
+
/.bundle
|
|
9
|
+
|
|
10
|
+
# Ignore the default SQLite database.
|
|
11
|
+
/db/*.sqlite3
|
|
12
|
+
/db/*.sqlite3-journal
|
|
13
|
+
|
|
14
|
+
# Ignore all logfiles and tempfiles.
|
|
15
|
+
/log/*
|
|
16
|
+
!/log/.keep
|
|
17
|
+
/tmp
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
|
+
|
|
3
|
+
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
|
4
|
+
gem 'rails', '~> 5.0.0'
|
|
5
|
+
# Use sqlite3 as the database for Active Record
|
|
6
|
+
gem 'sqlite3'
|
|
7
|
+
# Use SCSS for stylesheets
|
|
8
|
+
|
|
9
|
+
gem "trailblazer"
|
|
10
|
+
gem "trailblazer-future", path: '../../../trailblazer-future'
|
|
11
|
+
gem "trailblazer-rails"
|
|
12
|
+
|
|
13
|
+
gem "minitest-rails-capybara"
|
|
14
|
+
|
|
15
|
+
gem "trailblazer-cells"
|
|
16
|
+
gem "cells-rails"
|
|
17
|
+
gem "cells-erb"
|
|
18
|
+
|
|
19
|
+
gem "minitest-line"
|
|
20
|
+
|
|
21
|
+
gem "reform-rails"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<p><%= model["model"].inspect %>,<%= model["contract.default"].class.superclass %>,<%= options[:song].inspect %></p>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Song::New < Trailblazer::Operation
|
|
2
|
+
step Model( Song, :new )
|
|
3
|
+
step Contract::Build(constant: Song::Contract::Form)
|
|
4
|
+
step :set_current_user!
|
|
5
|
+
|
|
6
|
+
def set_current_user!(_options, model:, current_user:, **)
|
|
7
|
+
model.user_name = current_user
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Song::Create < Trailblazer::Operation
|
|
12
|
+
step Nested( Song::New )
|
|
13
|
+
step Contract::Validate()
|
|
14
|
+
step Contract::Persist()
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Song::Update < Trailblazer::V2_1::Operation
|
|
2
|
+
class Present < Trailblazer::V2_1::Operation
|
|
3
|
+
step Model(Song, :find_by)
|
|
4
|
+
step Contract::Build(constant: Song::Contract::Form)
|
|
5
|
+
step Policy::Guard(:policy)
|
|
6
|
+
|
|
7
|
+
def policy(_options, model:, current_user:, **)
|
|
8
|
+
model.user_name == current_user
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
step Nested(Present)
|
|
13
|
+
step Contract::Validate()
|
|
14
|
+
step Contract::Persist()
|
|
15
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
class ApplicationController < ActionController::Base
|
|
2
|
+
# Prevent CSRF attacks by raising an exception.
|
|
3
|
+
# For APIs, you may want to use :null_session instead.
|
|
4
|
+
protect_from_forgery with: :exception
|
|
5
|
+
|
|
6
|
+
def run(operation, params=self.params, *dependencies)
|
|
7
|
+
if operation < Trailblazer::Operation
|
|
8
|
+
super
|
|
9
|
+
else
|
|
10
|
+
result = operation.({params: _run_params(self.params) }.merge(*_run_runtime_options(*dependencies)))
|
|
11
|
+
|
|
12
|
+
@model = result[:model]
|
|
13
|
+
@form = Rails::Form.new( result[ "contract.default" ], @model.class )
|
|
14
|
+
|
|
15
|
+
yield(result) if result.success? && block_given?
|
|
16
|
+
|
|
17
|
+
@_result = result
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def _run_options(options)
|
|
24
|
+
options.merge("current_user" => "user_name" )
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Rails::Form < SimpleDelegator
|
|
28
|
+
def initialize(delegated, model_class)
|
|
29
|
+
super(delegated)
|
|
30
|
+
@model_class = model_class
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.name
|
|
34
|
+
# for whatever reason, validations climb up the inheritance tree and require _every_ class to have a name (4.1).
|
|
35
|
+
"Reform::Form"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def model_name
|
|
39
|
+
::ActiveModel::Name.new(self, nil, @model_class.to_s.camelize)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def to_model
|
|
43
|
+
self
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class ArtistsController < ApplicationController
|
|
2
|
+
def dashboard
|
|
3
|
+
model = Struct.new(:title).new("Dashboard")
|
|
4
|
+
render cell( Artist::Cell::Dashboard, model, theme: "cute" )
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def widget
|
|
8
|
+
model = Struct.new(:title).new("Dashboard")
|
|
9
|
+
render cell( Artist::Cell::Dashboard, model ), layout: false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
include Trailblazer::Rails::Controller::Result
|
|
13
|
+
|
|
14
|
+
def with_expose
|
|
15
|
+
run Song::New
|
|
16
|
+
render cell( Artist::Cell::Show, result )
|
|
17
|
+
# render cell( Artist::Cell::Show, expose(search: @search, %w{model contract.default}) )
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def with_expose_and_args
|
|
21
|
+
run Song::New
|
|
22
|
+
render cell( Artist::Cell::Show, result, song: @model )
|
|
23
|
+
end
|
|
24
|
+
end
|