Autorest generate model classes in multiple files - swagger

Is there any way to generate multiple files with autorest?
I want to generate each model class in a separate file.
Thanks in advance,

Related

How to properly include code in .rb files into Rails architecture?

I am currently coding an application in Ruby that does some simple external API calls to Soundcloud's API.
I have developed a bunch of code inside a single .rb file and want to put this into the rails architecture. This Ruby file has the following classes:
class SoundcloudUser
class SoundcloudQuery
class SoundcloudFollowers
Currently I understand that I can put these classes into seperate .rb files, and then just put them into the /models/ folder which then gives me the ability to call these classes from elsewhere in my rails application (using require/include).
My question is simply, is this the correct way to go about this? I am familiar with rails, but I am new to transferring a Ruby developed project into the rails format. I tried searching best practices for this in the Ruby style guide but I didn't really find anything.
On a side note - I wanted to also create another class that acts as a ?service? wherein in checks my local database if an entry already exists in the database, and if not, then it will query new data. My side-question here would be similar - where would this .rb file for this 'service' live?
I hope I explained my question clearly enough, if not, I am happy to add some clarifications. Thank you for your time!
If in Rails, you can put them in either lib/ or somewhere in the main app directory. For example, you can create app/services and put them inside there, and when you restart the Rails server you should be able to call SoundcloudUser (provided you name them app/services/soundcloud_user.rb.
I always look at the Gitlab source code for this. It's a gigantic Rails app but look at this file: https://github.com/gitlabhq/gitlabhq/blob/master/app/services/gravatar_service.rb. Because it's inside an app/services (any name actually), GravatarService can be called from anywhere in Rails. If you want to have some namespacing, you have to put it in app/services/soundcloud/user.rb or lib/soundcloud/user.rb and name the class Soundcloud::User.
For the class that acts as a service, it seems like it orchestrates the logic of "check if (song?) exists, else scrape. Some people put it in a model class, I'd probably put it in a service class a la the Gitlab source code. Hope I helped.

Adding Helper Rails Methods to a Directory

I've created a pdfs directory in app/ for invoices and purchase orders (I'm using prawn). Naturally, I want the NumberHelper to be available. Whats the best way to do this?
You could
include ActionView::Helpers::NumberHelper
in the classes you use to generate the pdfs

Location for XSD file used for validation during RSpec test

I am building XML files inside my application and I would like to validate the generated XML's format against an XSD file. I am not sure where shall I put this schema.xsd file so that it can be easily retrieved inside an RSpec example.
I was thinking about putting it inside spec/support, but I am not sure about it.
I would suggest spec/fixtures, since it is part of your test suite, it's somewhat static data and it can be accessed easily via fixture_path (you can set any other *_path helper in your spec_helper file if you wish to).
I've ended up putting my .xsd file in spec/support/schemas/; it felt more natural for me, since it is a support file.

Rails Generator vs Create Files by Hand

I have notice that there are many files created by generators (not only scaffold, but rails generate in general) that I don't use.
So I came up with the following questions (about best practices):
Do you use generators or it is preferable to create by hand only files you need?
If you use generators, do you keep all generated files?
You can use generators specifically to help you build individual files. For instance, you could use
rails g model Video title:string link:string
to create a model file with those as attributes, but you don't need to use scaffolding to generate everything (if that's what you're referring to)
Personally I like to use a combination -- it really depends on the project. But I'd tell you not to have extra files that you aren't using, so definitely delete the ones you aren't using (or don't plan to use).
Hope this helps.
i do use the generators and just delete the files. It is probably because I am lazy but I find this easier.
Especially with models, because it includes the migration.
Honestly it all comes down to just preference. Just don't scaffold...

Rails - Using Paperclip to temporarily store files and then move to another model

How is this possible to do?
When a user upload files, I want to upload the file to an AttachmentTemp model using paperclip, and use some type of temp folder on S3.
Then in my delayed job, use that temp file, but save that file to the Attachment model paperclip where it can be processed via delayed_job.
Possible?
I haven't tried it, but how about the following?
First, run the Paperclip generator for both models, so both tables have the necessary columns in the database (post migration).
Then use the Temp model in your user-facing new action/view.
Later, in your delayed job, load up each AttachmentTemp instance (filtered on some status criterion) and copy each one to an Attachment instance. So you're just translating one to the other.
In your remaining user-facing actions, use Attachment instances (so AttachmentTemps are only used when first creating a record).

Resources