Class: ModularRoutes::Builder
- Inherits:
-
Object
- Object
- ModularRoutes::Builder
- Defined in:
- lib/modular_routes/builder.rb
Constant Summary collapse
- HTTP_METHODS =
[:post, :get, :put, :patch, :delete].freeze
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #collection(&block) ⇒ Object
- #concern(concern_name, **options, &block) ⇒ Object
- #concerns(names) ⇒ Object
-
#initialize(api_only:) ⇒ Builder
constructor
A new instance of Builder.
- #member(&block) ⇒ Object
- #namespace(namespace_name, **options, &block) ⇒ Object
- #new(&block) ⇒ Object
- #resource(resource_name, **options, &block) ⇒ Object
- #resources(resources_name, **options, &block) ⇒ Object
- #root ⇒ Object
- #scope(*args, **options, &block) ⇒ Object
Constructor Details
#initialize(api_only:) ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 13 |
# File 'lib/modular_routes/builder.rb', line 9 def initialize(api_only:) @api_only = api_only @scopes = [] @routes = [] end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
7 8 9 |
# File 'lib/modular_routes/builder.rb', line 7 def routes @routes end |
Instance Method Details
#collection(&block) ⇒ Object
41 42 43 |
# File 'lib/modular_routes/builder.rb', line 41 def collection(&block) apply_inner_scope(:collection, &block) end |
#concern(concern_name, **options, &block) ⇒ Object
57 58 59 |
# File 'lib/modular_routes/builder.rb', line 57 def concern(concern_name, **, &block) apply_scopable(:concern, concern_name, , &block) end |
#concerns(names) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/modular_routes/builder.rb', line 32 def concerns(names) raise SyntaxError, "You must call `concerns` inside of a resource block" unless current_scope Array(names).each do |name| concern = Routable.for(:concerns, name) current_scope.add(concern) end end |
#member(&block) ⇒ Object
45 46 47 |
# File 'lib/modular_routes/builder.rb', line 45 def member(&block) apply_inner_scope(:member, &block) end |
#namespace(namespace_name, **options, &block) ⇒ Object
53 54 55 |
# File 'lib/modular_routes/builder.rb', line 53 def namespace(namespace_name, **, &block) apply_scopable(:namespace, namespace_name, , &block) end |
#new(&block) ⇒ Object
49 50 51 |
# File 'lib/modular_routes/builder.rb', line 49 def new(&block) apply_inner_scope(:new, &block) end |
#resource(resource_name, **options, &block) ⇒ Object
69 70 71 |
# File 'lib/modular_routes/builder.rb', line 69 def resource(resource_name, **, &block) apply_scopable(:resource, resource_name, , &block) end |
#resources(resources_name, **options, &block) ⇒ Object
65 66 67 |
# File 'lib/modular_routes/builder.rb', line 65 def resources(resources_name, **, &block) apply_scopable(:resources, resources_name, , &block) end |
#root ⇒ Object
28 29 30 |
# File 'lib/modular_routes/builder.rb', line 28 def root(*, **) raise SyntaxError, "You must call `root` outside of `modular_routes` block" end |
#scope(*args, **options, &block) ⇒ Object
61 62 63 |
# File 'lib/modular_routes/builder.rb', line 61 def scope(*args, **, &block) apply_scopable(:scope, args, , &block) end |