0

I am reading the documentation for the Tire gem and I am a confused about what it mean by the following paragraphs. Could someone explain it?

In fact, all this time you've been using only proxies to the real Tire methods, which live in the tire class and instance methods of your model. Only when not trampling on someone's foot — which is the majority of cases — will Tire bring its methods to the namespace of your class.

So, instead of writing Article.search, you could write Article.tire.search, and instead of @article.update_index you could write @article.tire.update_index, to be on the safe side. Let's have a look on an example with the mapping method:

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434

2 Answers2

1

It means just what it says: Tire tries hard not to drag methods into your model/namespace, and defines its methods only when they don't exist.

As a regular user, you don't have to care about it much. Whenever you call MyModel.search or MyModel.mapping you can also call MyModel.tire.search or MyModel.tire.mapping.

karmi
  • 14,059
  • 3
  • 33
  • 41
0

to piggy back off what Karmi has said, you might find this useful if for example your Model already has a search defined on it.

So if say, Post.search already does something in your rails app, you can just use Post.tire.search to do a tire search instead. I like to use it to signal to all developers who might work in the code after I do, that this is a tire method, so they (hopefully) don't spend time wondering where to find a search method in the Post model.

concept47
  • 30,257
  • 12
  • 52
  • 74