# How can I omit slice component booting?

**URL:** <https://discourse.hanakai.org/t/how-can-i-omit-slice-component-booting/845>\
**Category:** general\
**Created:** [June 23, 2023, 3:40pm UTC](https://discourse.hanakai.org/t/how-can-i-omit-slice-component-booting/845 "2023-06-23T15:40:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MasanoriOnishi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/masanorionishi/32/573_2.png) [@MasanoriOnishi](https://discourse.hanakai.org/u/MasanoriOnishi)\
**Post date:** [June 23, 2023, 3:40pm UTC](https://discourse.hanakai.org/t/how-can-i-omit-slice-component-booting/845/1 "2023-06-23T15:40:24Z")

</div>

We are using Hanami 2.  
We have both a not-slice component and a slice component in our codebase.  
We would like to know how to boot only the not-slice component.

For example, even if our codebase contains both the not-slice component and the slice component, we want to boot only the not-slice component.  
How can we achieve this?

We have tried setting HANAMI\_SLICES=“” in the environment, but we encountered an error because even though our codebase has a slice component, the HANAMI\_SLICES environment variable is empty.

---

<div class="post-metadata">

**Author:** ![alassek](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/alassek/32/532_2.png) [@alassek](https://discourse.hanakai.org/u/alassek)\
**Post date:** [June 23, 2023, 4:15pm UTC](https://discourse.hanakai.org/t/how-can-i-omit-slice-component-booting/845/2 "2023-06-23T16:15:45Z")

</div>

Setting an empty `HANAMI_SLICES` will do this, see for instance my CI make target:

```make
.PHONY: ci
ci: export HANAMI_ENV := test
ci: ## setup database and run test suite
	$(RAKE) db:test:prepare
	HANAMI_SLICES= $(RSPEC) --tag ~slice
	HANAMI_SLICES=ciam $(RSPEC) --tag slice
	HANAMI_SLICES=oauth $(RSPEC) --tag slice
	HANAMI_SLICES=scim $(RSPEC) --tag slice

```

Can you provide some more detail about how your components are structured, and what is going wrong exactly?

---

<div class="post-metadata">

**Author:** ![MasanoriOnishi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/masanorionishi/32/573_2.png) [@MasanoriOnishi](https://discourse.hanakai.org/u/MasanoriOnishi)\
**Post date:** [June 24, 2023, 4:40am UTC](https://discourse.hanakai.org/t/how-can-i-omit-slice-component-booting/845/3 "2023-06-24T04:40:37Z")

</div>

Thank you for your fast reply！

And I’m sorry for my ambiguous question.

I want to talk about not test, but normal booting.

```auto
root/
 ├ app/
 │ └ actions/
 │ └ actions.rb
 ├ config/
 │ └ app.rb
 │ └ routes.rb
 ├ lib/
 ├ slices/
 │ └ admin/
 │ └ actions/

```

```auto

module Bookshelf
  class Routes < Hanami::Routes
    scope "v1" do
      use Rack::Auth::Basic
      get "/page" do
        "Some restricted content"
      end
    end

    slice :admin, at: "/admin" do
      use Rack::Auth::Basic

      get "/books", to: "books.index"
    end
  end
end

```

```auto
export HANAMI_SLICES=

```

When we access /v1/page, we got the following error.(We don’t get the error just after booting my app.)

```auto
Hanami::SliceLoadError: Slice 'admin' not found

```

```auto
bundle exec hanami c
> config.slices
=> []

```

---

<div class="post-metadata">

**Author:** ![alassek](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/alassek/32/532_2.png) [@alassek](https://discourse.hanakai.org/u/alassek)\
**Post date:** [June 26, 2023, 7:37pm UTC](https://discourse.hanakai.org/t/how-can-i-omit-slice-component-booting/845/4 "2023-06-26T19:37:44Z")

</div>

Ah yes, you are running into [this problem](https://discourse.hanakai.org/t/how-are-slice-routes-intended-to-interact-with-hanami-slices/797).

This is a reminder that I need to make the time to work on a resolution for this. In the meantime, you can follow the mitigation I used:

```ruby
require "hanami/slice/router"

class RouteResolver < Hanami::Slice::Routing::Resolver
  def excluding?(slice_name)
    if slices && slice_dirs.include?(slice_name)
      slice_name = slice_name.to_s
      slices.none? { _1 == slice_name }
    else
      false
    end
  end

  private

  def slices = slice.config.slices

  def slice_dirs
    @_slice_dirs ||=
      Dir[slice.root / "slices" / "*"]
      .select { |path| File.directory?(path) }
      .map { |path| File.basename(path).to_sym }
  end
end

module SliceRouting
  def slice(slice_name, ...)
    return if @resolver.excluding?(slice_name)

    super
  end
end

Hanami::Slice::Router.prepend SliceRouting

class App < Hanami::App
  config.router.resolver = RouteResolver
end

```

---

<div class="post-metadata">

**Author:** ![MasanoriOnishi](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/masanorionishi/32/573_2.png) [@MasanoriOnishi](https://discourse.hanakai.org/u/MasanoriOnishi)\
**Post date:** [July 2, 2023, 6:58am UTC](https://discourse.hanakai.org/t/how-can-i-omit-slice-component-booting/845/5 "2023-07-02T06:58:59Z")

</div>

@alassek

That’s right!

Thank you for your kind guidance.

I’ll wait for the fix!!

> [@How are slice routes intended to interact with HANAMI\_SLICES?](https://discourse.hanakai.org/t/how-are-slice-routes-intended-to-interact-with-hanami-slices/797):
>
> a.k.a A Really Complicated Slice Use-Case The ability the startup the application with certain slices switched off is a really neat feature, one that I was going to build myself right before discovering this in Hanami. Some Background I work on my company’s identity team responsible for IAM infrastructure for our customers, so our security requirements are pretty stringent. We also want to go above and beyond where possible. We have successfully moved our SAML integration API over to Hanami …
