Questions tagged [service-object]

49 questions
38
votes
3 answers

How does Ruby's .() operator work?

I recently came across some code using a method call consisting of the format object.(arg1, arg2) without seeing a good explanation of how it works. See this sample code: class TestServiceObject def call 'method' …
fruchtose
  • 1,270
  • 2
  • 13
  • 16
23
votes
4 answers

Rails - Where (directories) to put Models that are not Active Record

We are building out apps that have Models that are not database components. We are curious to learn what others are doing in the rails community to address this subject. We are struggling with where to put them. Should we…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
4
votes
2 answers

Rails 4 Include Helper inside Service Object

I am currently trying to use a Devise helper inside a service object class ServiceObject include Devise::Controllers::Helpers But I get undefined method `helper_method' for ServiceObject:Class Any idea how to use such a helper inside the…
stefano_cdn
  • 1,362
  • 2
  • 15
  • 29
3
votes
1 answer

How to display flash messages in rails service object

I want to add service objects in to my controller. Is there any chance to include flash messages in to this service object? user_stocks_controller class UserStocksController < ApplicationController def create @user_stock =…
mr_muscle
  • 2,536
  • 18
  • 61
3
votes
2 answers

Rails service object returning 'No Method error'

To begin: This is my first attempt at getting business logic out of the Model/controller space. Here is some initial logic I'm trying to abstract. The path is app/services/Date_calc.rb. class Date_calc require User require Report def…
greyoxide
  • 1,197
  • 1
  • 17
  • 45
3
votes
1 answer

Rails, service objects: pass entire object or just an ID

I'm refactoring an application into service objects to keep the models smaller and the actual code files more organized. To that end, I'm utilizing service objects that perform actions on a given object. However, one of the dilemmas I'm facing is…
Dan L
  • 4,319
  • 5
  • 41
  • 74
2
votes
1 answer

Rails using private and protected methods in a Service object

I'm trying to move some business logic out of one of my controllers, StoreController and into a new Store::CreateService service object. Learning about services recently, it doesn't seem to be much of an established pattern for implementing them.…
VegaStudios
  • 378
  • 1
  • 4
  • 22
2
votes
1 answer

Installing service object for pos .net device

Im a newbie to this and trying to access a motorola ds4208 scanner through my c# program. All i researched says that I need OPOS drivers installed and "SERVICE OBJECT " to be installed for the device to be listed. Once its listed I can call…
ashish g
  • 429
  • 1
  • 7
  • 16
1
vote
1 answer

Rails: Uninitialized constant - can not access to another class from controller

search_handlers_controller.rb class SearchHandlersController < ApplicationController def match @string = 'string' @result = case params['search_style'] when 'match' MatchService.call(@string) ... …
Vitalina
  • 51
  • 9
1
vote
1 answer

Rails destroy action doesn't delete

I want to add service objects in to my controller. However destroy action seems didn't work properly - basically it doesn't delete anything just redirect to the page without flash message. user_stock_destroyer.rb class UserStocksDestroyer def…
mr_muscle
  • 2,536
  • 18
  • 61
1
vote
1 answer

How do I pass data from my service object to my controller?

This is the code from my service object app/services/grab_feed_from_jse.rb: class GrabFeedFromJSE def initialize(url) require 'oga' require 'net/http' body = Net::HTTP.get(URI.parse(url)) document = Oga.parse_html(body) …
marcamillion
  • 32,933
  • 55
  • 189
  • 380
1
vote
1 answer

Testing a service object job with rspec

I have the following job: class Test::MooJob < ApplicationJob queue_as :onboarding def perform avariable = Test::AragornService.build("a").call if avariable.status == true puts "job succeeded" end end end and the…
EnderWiggins
  • 390
  • 5
  • 17
1
vote
1 answer

Service Object returning status

I am making a rails json api which uses service objects in controllers actions and basing on what happend in service I have to render proper json. The example looks like this. star_service.rb class Place::StarService def initialize(params, user) …
Marek Michalik
  • 79
  • 3
  • 10