brainstem 1.0.0.pre.1 → 1.0.0
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/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/README.md +383 -32
- data/bin/brainstem +6 -0
- data/brainstem.gemspec +2 -0
- data/docs/api_doc_generator.markdown +175 -0
- data/docs/brainstem_executable.markdown +32 -0
- data/docs/docgen.png +0 -0
- data/docs/docgen_ascii.txt +63 -0
- data/docs/executable.png +0 -0
- data/docs/executable_ascii.txt +10 -0
- data/lib/brainstem/api_docs.rb +146 -0
- data/lib/brainstem/api_docs/abstract_collection.rb +116 -0
- data/lib/brainstem/api_docs/atlas.rb +158 -0
- data/lib/brainstem/api_docs/builder.rb +167 -0
- data/lib/brainstem/api_docs/controller.rb +122 -0
- data/lib/brainstem/api_docs/controller_collection.rb +40 -0
- data/lib/brainstem/api_docs/endpoint.rb +234 -0
- data/lib/brainstem/api_docs/endpoint_collection.rb +58 -0
- data/lib/brainstem/api_docs/exceptions.rb +8 -0
- data/lib/brainstem/api_docs/formatters/abstract_formatter.rb +64 -0
- data/lib/brainstem/api_docs/formatters/markdown/controller_formatter.rb +76 -0
- data/lib/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter.rb +73 -0
- data/lib/brainstem/api_docs/formatters/markdown/endpoint_formatter.rb +169 -0
- data/lib/brainstem/api_docs/formatters/markdown/helper.rb +76 -0
- data/lib/brainstem/api_docs/formatters/markdown/presenter_formatter.rb +200 -0
- data/lib/brainstem/api_docs/introspectors/abstract_introspector.rb +100 -0
- data/lib/brainstem/api_docs/introspectors/rails_introspector.rb +232 -0
- data/lib/brainstem/api_docs/presenter.rb +225 -0
- data/lib/brainstem/api_docs/presenter_collection.rb +97 -0
- data/lib/brainstem/api_docs/resolver.rb +73 -0
- data/lib/brainstem/api_docs/sinks/abstract_sink.rb +37 -0
- data/lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb +93 -0
- data/lib/brainstem/api_docs/sinks/stdout_sink.rb +44 -0
- data/lib/brainstem/cli.rb +146 -0
- data/lib/brainstem/cli/abstract_command.rb +97 -0
- data/lib/brainstem/cli/generate_api_docs_command.rb +169 -0
- data/lib/brainstem/concerns/controller_dsl.rb +300 -0
- data/lib/brainstem/concerns/controller_param_management.rb +30 -9
- data/lib/brainstem/concerns/formattable.rb +38 -0
- data/lib/brainstem/concerns/inheritable_configuration.rb +3 -2
- data/lib/brainstem/concerns/optional.rb +43 -0
- data/lib/brainstem/concerns/presenter_dsl.rb +76 -15
- data/lib/brainstem/controller_methods.rb +6 -3
- data/lib/brainstem/dsl/association.rb +6 -3
- data/lib/brainstem/dsl/associations_block.rb +6 -3
- data/lib/brainstem/dsl/base_block.rb +2 -4
- data/lib/brainstem/dsl/conditional.rb +7 -3
- data/lib/brainstem/dsl/conditionals_block.rb +4 -4
- data/lib/brainstem/dsl/configuration.rb +184 -8
- data/lib/brainstem/dsl/field.rb +6 -3
- data/lib/brainstem/dsl/fields_block.rb +2 -3
- data/lib/brainstem/help_text.txt +8 -0
- data/lib/brainstem/presenter.rb +27 -6
- data/lib/brainstem/presenter_validator.rb +5 -2
- data/lib/brainstem/time_classes.rb +1 -1
- data/lib/brainstem/version.rb +1 -1
- data/spec/brainstem/api_docs/abstract_collection_spec.rb +156 -0
- data/spec/brainstem/api_docs/atlas_spec.rb +353 -0
- data/spec/brainstem/api_docs/builder_spec.rb +100 -0
- data/spec/brainstem/api_docs/controller_collection_spec.rb +92 -0
- data/spec/brainstem/api_docs/controller_spec.rb +225 -0
- data/spec/brainstem/api_docs/endpoint_collection_spec.rb +144 -0
- data/spec/brainstem/api_docs/endpoint_spec.rb +346 -0
- data/spec/brainstem/api_docs/formatters/abstract_formatter_spec.rb +30 -0
- data/spec/brainstem/api_docs/formatters/markdown/controller_formatter_spec.rb +126 -0
- data/spec/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter_spec.rb +85 -0
- data/spec/brainstem/api_docs/formatters/markdown/endpoint_formatter_spec.rb +261 -0
- data/spec/brainstem/api_docs/formatters/markdown/helper_spec.rb +100 -0
- data/spec/brainstem/api_docs/formatters/markdown/presenter_formatter_spec.rb +485 -0
- data/spec/brainstem/api_docs/introspectors/abstract_introspector_spec.rb +192 -0
- data/spec/brainstem/api_docs/introspectors/rails_introspector_spec.rb +170 -0
- data/spec/brainstem/api_docs/presenter_collection_spec.rb +84 -0
- data/spec/brainstem/api_docs/presenter_spec.rb +519 -0
- data/spec/brainstem/api_docs/resolver_spec.rb +72 -0
- data/spec/brainstem/api_docs/sinks/abstract_sink_spec.rb +16 -0
- data/spec/brainstem/api_docs/sinks/controller_presenter_multifile_sink_spec.rb +56 -0
- data/spec/brainstem/api_docs/sinks/stdout_sink_spec.rb +22 -0
- data/spec/brainstem/api_docs_spec.rb +58 -0
- data/spec/brainstem/cli/abstract_command_spec.rb +91 -0
- data/spec/brainstem/cli/generate_api_docs_command_spec.rb +125 -0
- data/spec/brainstem/cli_spec.rb +67 -0
- data/spec/brainstem/concerns/controller_dsl_spec.rb +471 -0
- data/spec/brainstem/concerns/controller_param_management_spec.rb +36 -16
- data/spec/brainstem/concerns/formattable_spec.rb +30 -0
- data/spec/brainstem/concerns/inheritable_configuration_spec.rb +104 -4
- data/spec/brainstem/concerns/optional_spec.rb +48 -0
- data/spec/brainstem/concerns/presenter_dsl_spec.rb +202 -31
- data/spec/brainstem/dsl/association_spec.rb +18 -2
- data/spec/brainstem/dsl/conditional_spec.rb +25 -2
- data/spec/brainstem/dsl/configuration_spec.rb +1 -1
- data/spec/brainstem/dsl/field_spec.rb +18 -2
- data/spec/brainstem/presenter_collection_spec.rb +10 -2
- data/spec/brainstem/presenter_spec.rb +32 -0
- data/spec/brainstem/presenter_validator_spec.rb +12 -7
- data/spec/dummy/rails.rb +49 -0
- data/spec/shared/atlas_taker.rb +18 -0
- data/spec/shared/formattable.rb +14 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/spec_helpers/db.rb +1 -1
- data/spec/spec_helpers/presenters.rb +20 -14
- metadata +106 -6
|
@@ -5,8 +5,24 @@ describe Brainstem::DSL::Association do
|
|
|
5
5
|
let(:name) { :user }
|
|
6
6
|
let(:target_class) { User }
|
|
7
7
|
let(:description) { "This object's user" }
|
|
8
|
-
let(:options) { { } }
|
|
9
|
-
let(:association) { Brainstem::DSL::Association.new(name, target_class,
|
|
8
|
+
let(:options) { { info: description } }
|
|
9
|
+
let(:association) { Brainstem::DSL::Association.new(name, target_class, options) }
|
|
10
|
+
|
|
11
|
+
describe 'description' do
|
|
12
|
+
context 'when `info` is specified in the options' do
|
|
13
|
+
it 'returns the value specified with the info key' do
|
|
14
|
+
expect(association.description).to eq(description)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context 'when `info` is not specified in the options' do
|
|
19
|
+
let(:options) { {} }
|
|
20
|
+
|
|
21
|
+
it 'returns nil' do
|
|
22
|
+
expect(association.description).to be_nil
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
10
26
|
|
|
11
27
|
describe "#run_on" do
|
|
12
28
|
let(:context) { { } }
|
|
@@ -2,8 +2,31 @@ require 'spec_helper'
|
|
|
2
2
|
require 'brainstem/dsl/conditional'
|
|
3
3
|
|
|
4
4
|
describe Brainstem::DSL::Conditional do
|
|
5
|
-
let(:conditional) { Brainstem::DSL::Conditional.new(name, type, action,
|
|
5
|
+
let(:conditional) { Brainstem::DSL::Conditional.new(name, type, action, options) }
|
|
6
6
|
let(:model) { Workspace.first }
|
|
7
|
+
let(:options) { { info: description } }
|
|
8
|
+
|
|
9
|
+
describe 'description' do
|
|
10
|
+
let(:name) { :title_is_hello }
|
|
11
|
+
let(:type) { :model }
|
|
12
|
+
let(:action) { lambda { |model| model.title == 'hello' } }
|
|
13
|
+
|
|
14
|
+
context 'when `info` is specified in the options' do
|
|
15
|
+
let(:description) { 'visible when the title is hello' }
|
|
16
|
+
|
|
17
|
+
it 'returns the value specified with the info key' do
|
|
18
|
+
expect(conditional.description).to eq(description)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context 'when `info` is not specified in the options' do
|
|
23
|
+
let(:options) { {} }
|
|
24
|
+
|
|
25
|
+
it 'returns nil' do
|
|
26
|
+
expect(conditional.description).to be_nil
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
7
30
|
|
|
8
31
|
describe '.matches?' do
|
|
9
32
|
context 'as a :model conditional' do
|
|
@@ -90,4 +113,4 @@ describe Brainstem::DSL::Conditional do
|
|
|
90
113
|
end
|
|
91
114
|
end
|
|
92
115
|
end
|
|
93
|
-
end
|
|
116
|
+
end
|
|
@@ -1 +1 @@
|
|
|
1
|
-
# This is tested in concerns/inheritable_configuration_spec.rb
|
|
1
|
+
# This is tested in concerns/inheritable_configuration_spec.rb
|
|
@@ -5,10 +5,26 @@ describe Brainstem::DSL::Field do
|
|
|
5
5
|
let(:name) { :title }
|
|
6
6
|
let(:type) { :string }
|
|
7
7
|
let(:description) { 'the title of this model' }
|
|
8
|
-
let(:options) { { } }
|
|
9
|
-
let(:field) { Brainstem::DSL::Field.new(name, type,
|
|
8
|
+
let(:options) { { info: description } }
|
|
9
|
+
let(:field) { Brainstem::DSL::Field.new(name, type, options) }
|
|
10
10
|
let(:model) { Workspace.first }
|
|
11
11
|
|
|
12
|
+
describe 'description' do
|
|
13
|
+
context 'when `info` is specified in the options' do
|
|
14
|
+
it 'returns the value specified with the info key' do
|
|
15
|
+
expect(field.description).to eq(description)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context 'when `info` is not specified in the options' do
|
|
20
|
+
let(:options) { {} }
|
|
21
|
+
|
|
22
|
+
it 'returns nil' do
|
|
23
|
+
expect(field.description).to be_nil
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
12
28
|
describe '#method_name' do
|
|
13
29
|
describe 'by default' do
|
|
14
30
|
it 'returns the name' do
|
|
@@ -615,14 +615,22 @@ describe Brainstem::PresenterCollection do
|
|
|
615
615
|
WorkspacePresenter.filter(:other_filter_with_default, default: true) { |scope, opt| scope }
|
|
616
616
|
|
|
617
617
|
provided_params = nil
|
|
618
|
+
|
|
618
619
|
WorkspacePresenter.filter :filter_with_param, :include_params => true do |scope, option, params|
|
|
619
620
|
provided_params = params
|
|
620
621
|
scope
|
|
621
622
|
end
|
|
622
623
|
|
|
623
|
-
@presenter_collection.presenting("workspaces", :params => {
|
|
624
|
+
@presenter_collection.presenting("workspaces", :params => {
|
|
625
|
+
:filter_with_param => "arg",
|
|
626
|
+
:other_filter => 'another_arg'
|
|
627
|
+
}) { Workspace.where(nil) }
|
|
624
628
|
|
|
625
|
-
expect(provided_params).to eq({
|
|
629
|
+
expect(provided_params).to eq({
|
|
630
|
+
"filter_with_param" => "arg",
|
|
631
|
+
"other_filter" => "another_arg",
|
|
632
|
+
"other_filter_with_default" => true
|
|
633
|
+
})
|
|
626
634
|
end
|
|
627
635
|
end
|
|
628
636
|
end
|
|
@@ -68,6 +68,38 @@ describe Brainstem::Presenter do
|
|
|
68
68
|
}).to raise_error(/Brainstem Presenter#presents now expects a Class instead of a class name/)
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
describe ".possible_brainstem_keys" do
|
|
74
|
+
let(:presented_class) { Class.new }
|
|
75
|
+
let(:other_presented_class) { Class.new }
|
|
76
|
+
let(:presenter_class) { Class.new(Brainstem::Presenter) }
|
|
77
|
+
|
|
78
|
+
before do
|
|
79
|
+
presenter_class.presents presented_class, other_presented_class
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
context "when has brainstem key" do
|
|
83
|
+
before do
|
|
84
|
+
presenter_class.brainstem_key "presented_class"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it "returns the set of only its brainstem key" do
|
|
88
|
+
expect(presenter_class.possible_brainstem_keys.to_a).to eq ["presented_class"]
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
context "when has no brainstem key" do
|
|
93
|
+
before do
|
|
94
|
+
stub(presented_class).table_name { "t1" }
|
|
95
|
+
stub(other_presented_class).table_name { "t2" }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it "returns the set of keys of its presented classes" do
|
|
99
|
+
expect(presenter_class.possible_brainstem_keys.to_a.sort).to eq ["t1", "t2"]
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
71
103
|
end
|
|
72
104
|
|
|
73
105
|
describe "#group_present" do
|
|
@@ -9,29 +9,34 @@ describe Brainstem::PresenterValidator do
|
|
|
9
9
|
preload :lead_user
|
|
10
10
|
|
|
11
11
|
conditionals do
|
|
12
|
-
model :title_is_hello, lambda { |model| model.title == 'hello' }, 'visible when the title is hello'
|
|
13
|
-
request :user_is_bob, lambda { current_user == 'bob' }, 'visible only to bob'
|
|
12
|
+
model :title_is_hello, lambda { |model| model.title == 'hello' }, info: 'visible when the title is hello'
|
|
13
|
+
request :user_is_bob, lambda { current_user == 'bob' }, info: 'visible only to bob'
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
fields do
|
|
17
17
|
field :title, :string
|
|
18
18
|
field :description, :string
|
|
19
19
|
field :updated_at, :datetime
|
|
20
|
-
field :secret, :string,
|
|
20
|
+
field :secret, :string,
|
|
21
|
+
info: 'a secret, via secret_info',
|
|
21
22
|
via: :secret_info,
|
|
22
23
|
if: [:user_is_bob, :title_is_hello]
|
|
23
24
|
|
|
24
25
|
with_options if: :user_is_bob do
|
|
25
|
-
field :bob_title, :string,
|
|
26
|
+
field :bob_title, :string,
|
|
27
|
+
info: 'another name for the title, only for Bob',
|
|
26
28
|
via: :title
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
associations do
|
|
31
|
-
association :tasks, Task,
|
|
33
|
+
association :tasks, Task,
|
|
34
|
+
info: 'The Tasks in this Workspace',
|
|
32
35
|
restrict_to_only: true
|
|
33
|
-
association :lead_user, User,
|
|
34
|
-
|
|
36
|
+
association :lead_user, User,
|
|
37
|
+
info: 'The user who runs this Workspace'
|
|
38
|
+
association :subtasks, Task,
|
|
39
|
+
info: 'Only Tasks in this Workspace that are subtasks',
|
|
35
40
|
dynamic: lambda { |workspace| workspace.tasks.where('parent_id IS NOT NULL') }
|
|
36
41
|
end
|
|
37
42
|
end
|
data/spec/dummy/rails.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# This is a dummy file which is used in the Introspector specs to simulate a
|
|
2
|
+
# loaded rails app.
|
|
3
|
+
silence_warnings do
|
|
4
|
+
FakeRailsApplication = Struct.new(:eager_load!, :routes)
|
|
5
|
+
FakeRailsRoutesObject = Struct.new(:routes)
|
|
6
|
+
FakeRailsRoutePathObject = Struct.new(:spec)
|
|
7
|
+
FakeRailsRoute = Struct.new(:name, :path, :defaults, :constraints)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Rails
|
|
12
|
+
def self.application
|
|
13
|
+
@application ||= begin
|
|
14
|
+
route_1 = FakeRailsRoute.new(
|
|
15
|
+
"fake_descendant",
|
|
16
|
+
FakeRailsRoutePathObject.new(spec: '/fake_descendant'),
|
|
17
|
+
{ controller: "fake_descendant", action: "show" },
|
|
18
|
+
{ :request_method => /^GET|POST$/ }
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
route_2 = FakeRailsRoute.new(
|
|
22
|
+
"route_with_no_controller",
|
|
23
|
+
FakeRailsRoutePathObject.new(spec: '/fake_descendant'),
|
|
24
|
+
{ },
|
|
25
|
+
{ :request_method => /^PATCH$/ }
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
route_3 = FakeRailsRoute.new(
|
|
29
|
+
"route_with_invalid_controller",
|
|
30
|
+
FakeRailsRoutePathObject.new(spec: '/fake_descendant'),
|
|
31
|
+
{ controller: "invalid_controller", action: "show" },
|
|
32
|
+
{ :request_method => /^GET$/ }
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
routes = FakeRailsRoutesObject.new([ route_1, route_2, route_3 ])
|
|
36
|
+
|
|
37
|
+
FakeRailsApplication.new(true, routes)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class FakeBasePresenter; end
|
|
44
|
+
class FakeDescendantPresenter < FakeBasePresenter; end
|
|
45
|
+
|
|
46
|
+
class FakeBaseController; end
|
|
47
|
+
class FakeDescendantController < FakeBaseController; end
|
|
48
|
+
|
|
49
|
+
class FakeNonDescendantController; end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
shared_examples "atlas taker" do
|
|
2
|
+
describe "#initialize" do
|
|
3
|
+
it "requires an atlas" do
|
|
4
|
+
expect { described_class.new }.to raise_error ArgumentError
|
|
5
|
+
expect { described_class.new(atlas) }.not_to raise_error
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe "#find_by_class" do
|
|
10
|
+
let(:klass) { Class.new }
|
|
11
|
+
|
|
12
|
+
it "delegates to the atlas" do
|
|
13
|
+
mock(atlas).find_by_class(klass)
|
|
14
|
+
subject.find_by_class(klass)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
shared_examples "formattable" do
|
|
2
|
+
describe "formatting" do
|
|
3
|
+
let(:formatter) { Object.new }
|
|
4
|
+
let(:formatters) { { markdown: formatter } }
|
|
5
|
+
let(:options) { { formatters: formatters } }
|
|
6
|
+
|
|
7
|
+
describe "#formatted_as" do
|
|
8
|
+
it "looks up the formatter and calls that" do
|
|
9
|
+
mock(formatter).call(subject, { test: true }) { "blah" }
|
|
10
|
+
expect(subject.formatted_as(:markdown, test: true)).to eq "blah"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/spec_helpers/db.rb
CHANGED
|
@@ -44,4 +44,4 @@ Attachments::TaskAttachment.create!(id: 2, subject: Task.first, filename: 'I am
|
|
|
44
44
|
# Show that the base class is always used as the brainstem_key for attachments as polymorphic association targets
|
|
45
45
|
|
|
46
46
|
# Use Group / Workspace as the polymorphic target of an association where we do not
|
|
47
|
-
# want the baseclass to be used as the brainstem_key (like line_items0)
|
|
47
|
+
# want the baseclass to be used as the brainstem_key (like line_items0)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class WorkspacePresenter < Brainstem::Presenter
|
|
1
|
+
class WorkspacePresenter < Brainstem::Presenter
|
|
2
2
|
presents Workspace
|
|
3
3
|
|
|
4
4
|
helper do
|
|
@@ -10,8 +10,8 @@ class WorkspacePresenter < Brainstem::Presenter
|
|
|
10
10
|
preload :lead_user
|
|
11
11
|
|
|
12
12
|
conditionals do
|
|
13
|
-
model :title_is_hello, lambda { |model| model.title == 'hello' }, 'visible when the title is hello'
|
|
14
|
-
request :user_is_bob, lambda { current_user == 'bob' }, 'visible only to bob'
|
|
13
|
+
model :title_is_hello, lambda { |model| model.title == 'hello' }, info: 'visible when the title is hello'
|
|
14
|
+
request :user_is_bob, lambda { current_user == 'bob' }, info: 'visible only to bob'
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
fields do
|
|
@@ -32,23 +32,26 @@ class WorkspacePresenter < Brainstem::Presenter
|
|
|
32
32
|
field :access_level, :integer, dynamic: lambda { 2 }
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
field :hello_title, :string,
|
|
35
|
+
field :hello_title, :string,
|
|
36
|
+
info: 'the title, when hello',
|
|
36
37
|
dynamic: lambda { 'title is hello' },
|
|
37
38
|
if: :title_is_hello
|
|
38
39
|
|
|
39
|
-
field :secret, :string,
|
|
40
|
+
field :secret, :string,
|
|
41
|
+
info: 'a secret, via secret_info',
|
|
40
42
|
via: :secret_info,
|
|
41
43
|
if: [:user_is_bob, :title_is_hello]
|
|
42
44
|
|
|
43
45
|
with_options if: :user_is_bob do
|
|
44
|
-
field :bob_title, :string,
|
|
46
|
+
field :bob_title, :string,
|
|
47
|
+
info: 'another name for the title, only for Bob',
|
|
45
48
|
via: :title
|
|
46
49
|
end
|
|
47
50
|
end
|
|
48
51
|
|
|
49
52
|
associations do
|
|
50
|
-
association :tasks, Task, 'The Tasks in this Workspace'
|
|
51
|
-
association :lead_user, User, 'The user who runs this Workspace'
|
|
53
|
+
association :tasks, Task, info: 'The Tasks in this Workspace'
|
|
54
|
+
association :lead_user, User, info: 'The user who runs this Workspace'
|
|
52
55
|
# association :subtasks, Task, 'Only Tasks in this Workspace that are subtasks',
|
|
53
56
|
# dynamic: lambda { |workspace| workspace.tasks.where('parent_id IS NOT NULL') },
|
|
54
57
|
# brainstem_key: 'sub_tasks'
|
|
@@ -63,7 +66,7 @@ class CheesePresenter < Brainstem::Presenter
|
|
|
63
66
|
end
|
|
64
67
|
|
|
65
68
|
associations do
|
|
66
|
-
association :user, User, 'The owner of the cheese'
|
|
69
|
+
association :user, User, info: 'The owner of the cheese'
|
|
67
70
|
end
|
|
68
71
|
end
|
|
69
72
|
|
|
@@ -75,7 +78,7 @@ class GroupPresenter < Brainstem::Presenter
|
|
|
75
78
|
end
|
|
76
79
|
|
|
77
80
|
associations do
|
|
78
|
-
association :tasks, Task, 'The Tasks in this Group'
|
|
81
|
+
association :tasks, Task, info: 'The Tasks in this Group'
|
|
79
82
|
end
|
|
80
83
|
end
|
|
81
84
|
|
|
@@ -88,10 +91,12 @@ class TaskPresenter < Brainstem::Presenter
|
|
|
88
91
|
|
|
89
92
|
associations do
|
|
90
93
|
association :sub_tasks, Task
|
|
91
|
-
association :other_tasks, Task,
|
|
94
|
+
association :other_tasks, Task,
|
|
95
|
+
info: 'another copy of the sub_tasks association',
|
|
92
96
|
via: :sub_tasks
|
|
93
97
|
association :workspace, Workspace
|
|
94
|
-
association :restricted, Task,
|
|
98
|
+
association :restricted, Task,
|
|
99
|
+
info: 'only available on only / show requests',
|
|
95
100
|
dynamic: lambda { |task| Task.last },
|
|
96
101
|
restrict_to_only: true
|
|
97
102
|
end
|
|
@@ -105,7 +110,8 @@ class UserPresenter < Brainstem::Presenter
|
|
|
105
110
|
end
|
|
106
111
|
|
|
107
112
|
associations do
|
|
108
|
-
association :odd_workspaces, Workspace,
|
|
113
|
+
association :odd_workspaces, Workspace,
|
|
114
|
+
info: 'only the odd numbered workspaces',
|
|
109
115
|
dynamic: lambda { |user| user.workspaces.select { |workspace| workspace.id % 2 == 1 } }
|
|
110
116
|
end
|
|
111
117
|
end
|
|
@@ -135,4 +141,4 @@ class AttachmentPresenter < Brainstem::Presenter
|
|
|
135
141
|
associations do
|
|
136
142
|
association :subject, :polymorphic
|
|
137
143
|
end
|
|
138
|
-
end
|
|
144
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: brainstem
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.0
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mavenlink
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-
|
|
11
|
+
date: 2017-07-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -168,7 +168,8 @@ description: Brainstem allows you to create rich API presenters that know how to
|
|
|
168
168
|
sort, and include associations.
|
|
169
169
|
email:
|
|
170
170
|
- opensource@mavenlink.com
|
|
171
|
-
executables:
|
|
171
|
+
executables:
|
|
172
|
+
- brainstem
|
|
172
173
|
extensions: []
|
|
173
174
|
extra_rdoc_files: []
|
|
174
175
|
files:
|
|
@@ -179,12 +180,48 @@ files:
|
|
|
179
180
|
- LICENSE
|
|
180
181
|
- README.md
|
|
181
182
|
- Rakefile
|
|
183
|
+
- bin/brainstem
|
|
182
184
|
- brainstem.gemspec
|
|
185
|
+
- docs/api_doc_generator.markdown
|
|
186
|
+
- docs/brainstem_executable.markdown
|
|
187
|
+
- docs/docgen.png
|
|
188
|
+
- docs/docgen_ascii.txt
|
|
189
|
+
- docs/executable.png
|
|
190
|
+
- docs/executable_ascii.txt
|
|
183
191
|
- lib/brainstem.rb
|
|
192
|
+
- lib/brainstem/api_docs.rb
|
|
193
|
+
- lib/brainstem/api_docs/abstract_collection.rb
|
|
194
|
+
- lib/brainstem/api_docs/atlas.rb
|
|
195
|
+
- lib/brainstem/api_docs/builder.rb
|
|
196
|
+
- lib/brainstem/api_docs/controller.rb
|
|
197
|
+
- lib/brainstem/api_docs/controller_collection.rb
|
|
198
|
+
- lib/brainstem/api_docs/endpoint.rb
|
|
199
|
+
- lib/brainstem/api_docs/endpoint_collection.rb
|
|
200
|
+
- lib/brainstem/api_docs/exceptions.rb
|
|
201
|
+
- lib/brainstem/api_docs/formatters/abstract_formatter.rb
|
|
202
|
+
- lib/brainstem/api_docs/formatters/markdown/controller_formatter.rb
|
|
203
|
+
- lib/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter.rb
|
|
204
|
+
- lib/brainstem/api_docs/formatters/markdown/endpoint_formatter.rb
|
|
205
|
+
- lib/brainstem/api_docs/formatters/markdown/helper.rb
|
|
206
|
+
- lib/brainstem/api_docs/formatters/markdown/presenter_formatter.rb
|
|
207
|
+
- lib/brainstem/api_docs/introspectors/abstract_introspector.rb
|
|
208
|
+
- lib/brainstem/api_docs/introspectors/rails_introspector.rb
|
|
209
|
+
- lib/brainstem/api_docs/presenter.rb
|
|
210
|
+
- lib/brainstem/api_docs/presenter_collection.rb
|
|
211
|
+
- lib/brainstem/api_docs/resolver.rb
|
|
212
|
+
- lib/brainstem/api_docs/sinks/abstract_sink.rb
|
|
213
|
+
- lib/brainstem/api_docs/sinks/controller_presenter_multifile_sink.rb
|
|
214
|
+
- lib/brainstem/api_docs/sinks/stdout_sink.rb
|
|
215
|
+
- lib/brainstem/cli.rb
|
|
216
|
+
- lib/brainstem/cli/abstract_command.rb
|
|
217
|
+
- lib/brainstem/cli/generate_api_docs_command.rb
|
|
218
|
+
- lib/brainstem/concerns/controller_dsl.rb
|
|
184
219
|
- lib/brainstem/concerns/controller_param_management.rb
|
|
185
220
|
- lib/brainstem/concerns/error_presentation.rb
|
|
221
|
+
- lib/brainstem/concerns/formattable.rb
|
|
186
222
|
- lib/brainstem/concerns/inheritable_configuration.rb
|
|
187
223
|
- lib/brainstem/concerns/lookup.rb
|
|
224
|
+
- lib/brainstem/concerns/optional.rb
|
|
188
225
|
- lib/brainstem/concerns/presenter_dsl.rb
|
|
189
226
|
- lib/brainstem/controller_methods.rb
|
|
190
227
|
- lib/brainstem/dsl/association.rb
|
|
@@ -195,6 +232,7 @@ files:
|
|
|
195
232
|
- lib/brainstem/dsl/configuration.rb
|
|
196
233
|
- lib/brainstem/dsl/field.rb
|
|
197
234
|
- lib/brainstem/dsl/fields_block.rb
|
|
235
|
+
- lib/brainstem/help_text.txt
|
|
198
236
|
- lib/brainstem/preloader.rb
|
|
199
237
|
- lib/brainstem/presenter.rb
|
|
200
238
|
- lib/brainstem/presenter_collection.rb
|
|
@@ -207,9 +245,37 @@ files:
|
|
|
207
245
|
- lib/brainstem/test_helpers.rb
|
|
208
246
|
- lib/brainstem/time_classes.rb
|
|
209
247
|
- lib/brainstem/version.rb
|
|
248
|
+
- spec/brainstem/api_docs/abstract_collection_spec.rb
|
|
249
|
+
- spec/brainstem/api_docs/atlas_spec.rb
|
|
250
|
+
- spec/brainstem/api_docs/builder_spec.rb
|
|
251
|
+
- spec/brainstem/api_docs/controller_collection_spec.rb
|
|
252
|
+
- spec/brainstem/api_docs/controller_spec.rb
|
|
253
|
+
- spec/brainstem/api_docs/endpoint_collection_spec.rb
|
|
254
|
+
- spec/brainstem/api_docs/endpoint_spec.rb
|
|
255
|
+
- spec/brainstem/api_docs/formatters/abstract_formatter_spec.rb
|
|
256
|
+
- spec/brainstem/api_docs/formatters/markdown/controller_formatter_spec.rb
|
|
257
|
+
- spec/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter_spec.rb
|
|
258
|
+
- spec/brainstem/api_docs/formatters/markdown/endpoint_formatter_spec.rb
|
|
259
|
+
- spec/brainstem/api_docs/formatters/markdown/helper_spec.rb
|
|
260
|
+
- spec/brainstem/api_docs/formatters/markdown/presenter_formatter_spec.rb
|
|
261
|
+
- spec/brainstem/api_docs/introspectors/abstract_introspector_spec.rb
|
|
262
|
+
- spec/brainstem/api_docs/introspectors/rails_introspector_spec.rb
|
|
263
|
+
- spec/brainstem/api_docs/presenter_collection_spec.rb
|
|
264
|
+
- spec/brainstem/api_docs/presenter_spec.rb
|
|
265
|
+
- spec/brainstem/api_docs/resolver_spec.rb
|
|
266
|
+
- spec/brainstem/api_docs/sinks/abstract_sink_spec.rb
|
|
267
|
+
- spec/brainstem/api_docs/sinks/controller_presenter_multifile_sink_spec.rb
|
|
268
|
+
- spec/brainstem/api_docs/sinks/stdout_sink_spec.rb
|
|
269
|
+
- spec/brainstem/api_docs_spec.rb
|
|
270
|
+
- spec/brainstem/cli/abstract_command_spec.rb
|
|
271
|
+
- spec/brainstem/cli/generate_api_docs_command_spec.rb
|
|
272
|
+
- spec/brainstem/cli_spec.rb
|
|
273
|
+
- spec/brainstem/concerns/controller_dsl_spec.rb
|
|
210
274
|
- spec/brainstem/concerns/controller_param_management_spec.rb
|
|
211
275
|
- spec/brainstem/concerns/error_presentation_spec.rb
|
|
276
|
+
- spec/brainstem/concerns/formattable_spec.rb
|
|
212
277
|
- spec/brainstem/concerns/inheritable_configuration_spec.rb
|
|
278
|
+
- spec/brainstem/concerns/optional_spec.rb
|
|
213
279
|
- spec/brainstem/concerns/presenter_dsl_spec.rb
|
|
214
280
|
- spec/brainstem/controller_methods_spec.rb
|
|
215
281
|
- spec/brainstem/dsl/association_spec.rb
|
|
@@ -223,6 +289,9 @@ files:
|
|
|
223
289
|
- spec/brainstem/query_strategies/filter_and_search_spec.rb
|
|
224
290
|
- spec/brainstem/query_strategies/filter_or_search_spec.rb
|
|
225
291
|
- spec/brainstem_spec.rb
|
|
292
|
+
- spec/dummy/rails.rb
|
|
293
|
+
- spec/shared/atlas_taker.rb
|
|
294
|
+
- spec/shared/formattable.rb
|
|
226
295
|
- spec/spec_helper.rb
|
|
227
296
|
- spec/spec_helpers/db.rb
|
|
228
297
|
- spec/spec_helpers/presenters.rb
|
|
@@ -243,19 +312,47 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
243
312
|
version: '0'
|
|
244
313
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
245
314
|
requirements:
|
|
246
|
-
- - "
|
|
315
|
+
- - ">="
|
|
247
316
|
- !ruby/object:Gem::Version
|
|
248
|
-
version:
|
|
317
|
+
version: '0'
|
|
249
318
|
requirements: []
|
|
250
319
|
rubyforge_project:
|
|
251
|
-
rubygems_version: 2.
|
|
320
|
+
rubygems_version: 2.5.2
|
|
252
321
|
signing_key:
|
|
253
322
|
specification_version: 4
|
|
254
323
|
summary: ActiveRecord presenters with a rich request API
|
|
255
324
|
test_files:
|
|
325
|
+
- spec/brainstem/api_docs/abstract_collection_spec.rb
|
|
326
|
+
- spec/brainstem/api_docs/atlas_spec.rb
|
|
327
|
+
- spec/brainstem/api_docs/builder_spec.rb
|
|
328
|
+
- spec/brainstem/api_docs/controller_collection_spec.rb
|
|
329
|
+
- spec/brainstem/api_docs/controller_spec.rb
|
|
330
|
+
- spec/brainstem/api_docs/endpoint_collection_spec.rb
|
|
331
|
+
- spec/brainstem/api_docs/endpoint_spec.rb
|
|
332
|
+
- spec/brainstem/api_docs/formatters/abstract_formatter_spec.rb
|
|
333
|
+
- spec/brainstem/api_docs/formatters/markdown/controller_formatter_spec.rb
|
|
334
|
+
- spec/brainstem/api_docs/formatters/markdown/endpoint_collection_formatter_spec.rb
|
|
335
|
+
- spec/brainstem/api_docs/formatters/markdown/endpoint_formatter_spec.rb
|
|
336
|
+
- spec/brainstem/api_docs/formatters/markdown/helper_spec.rb
|
|
337
|
+
- spec/brainstem/api_docs/formatters/markdown/presenter_formatter_spec.rb
|
|
338
|
+
- spec/brainstem/api_docs/introspectors/abstract_introspector_spec.rb
|
|
339
|
+
- spec/brainstem/api_docs/introspectors/rails_introspector_spec.rb
|
|
340
|
+
- spec/brainstem/api_docs/presenter_collection_spec.rb
|
|
341
|
+
- spec/brainstem/api_docs/presenter_spec.rb
|
|
342
|
+
- spec/brainstem/api_docs/resolver_spec.rb
|
|
343
|
+
- spec/brainstem/api_docs/sinks/abstract_sink_spec.rb
|
|
344
|
+
- spec/brainstem/api_docs/sinks/controller_presenter_multifile_sink_spec.rb
|
|
345
|
+
- spec/brainstem/api_docs/sinks/stdout_sink_spec.rb
|
|
346
|
+
- spec/brainstem/api_docs_spec.rb
|
|
347
|
+
- spec/brainstem/cli/abstract_command_spec.rb
|
|
348
|
+
- spec/brainstem/cli/generate_api_docs_command_spec.rb
|
|
349
|
+
- spec/brainstem/cli_spec.rb
|
|
350
|
+
- spec/brainstem/concerns/controller_dsl_spec.rb
|
|
256
351
|
- spec/brainstem/concerns/controller_param_management_spec.rb
|
|
257
352
|
- spec/brainstem/concerns/error_presentation_spec.rb
|
|
353
|
+
- spec/brainstem/concerns/formattable_spec.rb
|
|
258
354
|
- spec/brainstem/concerns/inheritable_configuration_spec.rb
|
|
355
|
+
- spec/brainstem/concerns/optional_spec.rb
|
|
259
356
|
- spec/brainstem/concerns/presenter_dsl_spec.rb
|
|
260
357
|
- spec/brainstem/controller_methods_spec.rb
|
|
261
358
|
- spec/brainstem/dsl/association_spec.rb
|
|
@@ -269,6 +366,9 @@ test_files:
|
|
|
269
366
|
- spec/brainstem/query_strategies/filter_and_search_spec.rb
|
|
270
367
|
- spec/brainstem/query_strategies/filter_or_search_spec.rb
|
|
271
368
|
- spec/brainstem_spec.rb
|
|
369
|
+
- spec/dummy/rails.rb
|
|
370
|
+
- spec/shared/atlas_taker.rb
|
|
371
|
+
- spec/shared/formattable.rb
|
|
272
372
|
- spec/spec_helper.rb
|
|
273
373
|
- spec/spec_helpers/db.rb
|
|
274
374
|
- spec/spec_helpers/presenters.rb
|