Class: ModularRoutes::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/modular_routes/builder.rb

Constant Summary collapse

HTTP_METHODS =
[:post, :get, :put, :patch, :delete].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#routesObject (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, **options, &block)
  apply_scopable(:concern, concern_name, options, &block)
end

#concerns(names) ⇒ Object

Raises:

  • (SyntaxError)


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, **options, &block)
  apply_scopable(:namespace, namespace_name, options, &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, **options, &block)
  apply_scopable(:resource, resource_name, options, &block)
end

#resources(resources_name, **options, &block) ⇒ Object



65
66
67
# File 'lib/modular_routes/builder.rb', line 65

def resources(resources_name, **options, &block)
  apply_scopable(:resources, resources_name, options, &block)
end

#rootObject

Raises:

  • (SyntaxError)


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, **options, &block)
  apply_scopable(:scope, args, options, &block)
end