Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Soup in a Bag
Dec 4, 2009
Are you calling include inside a method definition? I don't think you can do that. It should work at the top level or as part of a Module/Class definition though.

But you don't have to use include. For example, if your TestModule contains a class called TestClass, you could use either:
code:
require 'lib/test_module'
obj = TestModule::TestClass.new
or:
code:
require 'lib/test_module'
include TestModule
obj = TestClass.new

Adbot
ADBOT LOVES YOU

Pardot
Jul 25, 2001




That is assuming that lib/test_module.rb looks like this:

code:
module TestModule
  class TestClass
    # stuff
  end
end

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Mental Filler posted:

So you have to require the file and then include the contents? That makes sense.

Kernel.load reads a file and executes its contents.
Kernel.require returns false if the file has been required already. If it hasn't been require, it loads it, adds it to the list of required files, and returns true. require also automatically puts .rb at the end of the file name for you.
Module.include adds the instance methods from the given Module to the current Module.

For example:
code:
#file1.rb
puts 'faaaaaaaart ~~~'

#file2.rb
require './file1'
require './file1'

#file3.rb
load './file1.rb'
load './file1.rb'
And running it:
code:
> ruby file1.rb 
faaaaaaaaaart ~~~
> ruby file2.rb 
faaaaaaaaaart ~~~
> ruby file3.rb 
faaaaaaaaaart ~~~
faaaaaaaaaart ~~~

hepatizon
Oct 27, 2010
If it's still not solved, just cut the the chase and post your loving code instead of making us infer what you're doing.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

hepatizon posted:

post your loving code

"I can't, it's company proprietary/Secret/PHI/has been found to cause cancer in California."

Make a reduced case that exhibits the same problems that you can make public. Making the reduced case will also help you reason about the specific problem instead of general malaise about your codebase.

Mental Filler
May 5, 2007

She can ride or walk
either leave it or love it
:stare: the problem was trying to use include inside a method. Sorry folks, I didn't mean to draw out what is a pretty dumb issue.

Thanks for the advice, I'm still new to ruby so it's little things like this that have been tripping me up.

Deus Rex
Mar 5, 2005

Has anybody here stopped using RVM in favor of rbenv? Any thoughts on the experience? Seeing the 20+ gemsets I have (one for each project!) has made me reconsider my continued use of RVM.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Deus Rex posted:

Has anybody here stopped using RVM in favor of rbenv? Any thoughts on the experience? Seeing the 20+ gemsets I have (one for each project!) has made me reconsider my continued use of RVM.

I haven't had any problems with rbenv, and have been using it since August and recommending it since September.

Even when I did use rvm I didn't use gemsets; bundler handles different gems for different projects quite well.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


When you recommend it, what do you list as its advantages?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Doc Hawkins posted:

When you recommend it, what do you list as its advantages?
Its advantages are in what it doesn't do.

Conceptually simpler, fewer features, no garish ascii art, shims work predictably in non-shell situations, doesn't block shells when you change directories out of some misplaced concept of "trust," doesn't randomly break due to un-tested midday patches.

And these are just the problems I've had.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Most important question: how do you pronounce it? (I'm partial to "ruh-BENV")

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Doc Hawkins posted:

Most important question: how do you pronounce it? (I'm partial to "ruh-BENV")

I say "are-bee-env."

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Doc Hawkins posted:

Most important question: how do you pronounce it? (I'm partial to "ruh-BENV")

<sam> I personally say r-b-env
<sam> to cause confusion with rvm
<sam> josh peek says ruby-env

Pardot
Jul 25, 2001




I switched. The only thing I don't like is that you have to do rbenv rehash after you install a gem with binaires.

Also I've been saying arby env, but I like rue benv, so I'm going to start saying that now.

Also also rspec is respek :respek:

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Pardot posted:

I switched. The only thing I don't like is that you have to do rbenv rehash after you install a gem with binaires.

Also I've been saying arby env, but I like rue benv, so I'm going to start saying that now.

Also also rspec is respek :respek:

rspec is trash :colbert:

Newish project uses the default rails 3 minitest setup without even using shoulda and it's rather good.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

BonzoESC posted:

rspec is trash :colbert:

Them's fighting words!

Really though, I've only really ever used rspec, and I like it just fine, particularly once I grokked using subjects, contexts, and it a lot better. What does the newish stuff bring to the table?

Now cucumber, there's a thoroughly useless test framework.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

enki42 posted:

Them's fighting words!

Really though, I've only really ever used rspec, and I like it just fine, particularly once I grokked using subjects, contexts, and it a lot better. What does the newish stuff bring to the table?

Now cucumber, there's a thoroughly useless test framework.

I never liked rspec because I always had problems figuring out where underscores should go in should_not be_nil-type situations, and shoulda got me 90% of what subjects and contexts did.

MiniTest::Unit is just classic Test::Unit but a better implementation; it feels nicely straightforward with very little clever stuff happening under the hood.

Also, I like cucumber because I can mash out a high-level view of what I want working with the site to be without giving a flying gently caress about implementation, and I generally don't have to change the feature file once it's written; just implement steps and focus on changing failure messages or making it pass.

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!

BonzoESC posted:

Also, I like cucumber because I can mash out a high-level view of what I want working with the site to be without giving a flying gently caress about implementation, and I generally don't have to change the feature file once it's written; just implement steps and focus on changing failure messages or making it pass.

I find I can do the same with integration tests written in rspec - you get most of what you need with the capybara DSL and some sort of fixture loading / factories. Adding the seperation between test definition and implementation always felt like an unnecessary step that made grokking the tests more complicated, in my mind.

And yeah, I do agree that even if you understand how rspec works, most of it is just memorization about how you should structure things rather than reasoning about the system.

manero
Jan 30, 2006

BonzoESC posted:

I never liked rspec because I always had problems figuring out where underscores should go in should_not be_nil-type situations, and shoulda got me 90% of what subjects and contexts did.

MiniTest::Unit is just classic Test::Unit but a better implementation; it feels nicely straightforward with very little clever stuff happening under the hood.

Also, I like cucumber because I can mash out a high-level view of what I want working with the site to be without giving a flying gently caress about implementation, and I generally don't have to change the feature file once it's written; just implement steps and focus on changing failure messages or making it pass.

The problem I had with rspec is that the syntax is quite a bit magic. You basically have to know how rspec works (matchers etc) to actually be able to use it, where with something like Test::Unit, it's very obvious how to use the API. I used to hate on rspec, but I started using it for a project I've been working on since August and it's been a pleasure so far, and I like subject(), etc.

I've also gone back and forth on Cucumber. On previous projects, it was already setup with webkit-capybara, and all the parts were working together. On this app I've been working on, I started to use it and then gave up trying to get all the pieces to work. Fast-forward 4 months and I've gone back to writing Cucumber tests, if anything to make sure the app is working front to back.

Writing controller tests for RESTful controllers that use decent_exposure seems like kind of a waste, since each action is basically "respond_with some_model"


Edit: Also this is a really good read: http://blog.steveklabnik.com/posts/2011-12-30-active-record-considered-harmful

manero fucked around with this message at 17:20 on Dec 30, 2011

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

enki42 posted:

I find I can do the same with integration tests written in rspec - you get most of what you need with the capybara DSL and some sort of fixture loading / factories. Adding the seperation between test definition and implementation always felt like an unnecessary step that made grokking the tests more complicated, in my mind.

Keeping them separated means you can decide what you want long before you even think about how to test it, let alone implement it:
code:
Feature: Blog posting
  In order to make tokens useful
  Users should pay five tokens to create a blog

  Scenario: Fail to create a blog
    Given I have no tokens
    And I am on the new blog page
    When I create a blog
    Then I should see the ransom form to buy tokens

  Scenario: Ransom a blog
    Given I have a ransomed blog
    When I buy 5 tokens
    And I ransom my blog
    Then I should have 0 tokens
    And my blog should be published

  Scenario: Create a blog
    Given I have 5 tokens
    And I am on the new blog page
    When I create a blog
    Then I should have 0 tokens
    And my blog should be published
At this point, I don't know how these features will work internally, whether the ransom form will be an overlay or a new page, or how tokens will be stored. This feature was written before any code existed in the project, and it'll survive unchanged into production.

The key is that I'm not using the web_steps file from old versions of cucumber, so I don't have to worry about formulating the features to conform to that, and as a result I can make When I create a blog a nice high-level step instead of a laborious set of And I fill in 'butts' with 'dicks' steps.

Catalyst-proof
May 11, 2011

better waste some time with you
I understand, conceptually, that Bundler is supposed to act as a sort of 'virtualenv' for Ruby projects, and that it works alongside rbenv for this purpose, but I've never seen a setup of it in action (i.e., two projects, with different dependencies, and switching between them). Does anyone have anything useful to point me to to learn how to use it? The official webpage feels kind of sparse and after reading it a time or two I'm still no closer to understanding how to use it.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Fren posted:

I understand, conceptually, that Bundler is supposed to act as a sort of 'virtualenv' for Ruby projects, and that it works alongside rbenv for this purpose, but I've never seen a setup of it in action (i.e., two projects, with different dependencies, and switching between them). Does anyone have anything useful to point me to to learn how to use it? The official webpage feels kind of sparse and after reading it a time or two I'm still no closer to understanding how to use it.

Prefix commands with bundle exec to run them with the current bundle. alias be="bundle exec" will save time, as will bundle exec $SHELL

Pardot
Jul 25, 2001




Fren posted:

I understand, conceptually, that Bundler is supposed to act as a sort of 'virtualenv' for Ruby projects, and that it works alongside rbenv for this purpose, but I've never seen a setup of it in action (i.e., two projects, with different dependencies, and switching between them). Does anyone have anything useful to point me to to learn how to use it? The official webpage feels kind of sparse and after reading it a time or two I'm still no closer to understanding how to use it.

Not what you asked, but since you mentioned virtualenv I want to point out that bundler is 2 things. First virtualenv from python, but secondly a dependency resolver. It's easiest to show an example of the latter.

Let's say your project depends on library A and B.

Library A depends on library Y version >= 1.0 and <= 1.1
Library B depends on library Y version >= 1.1
Library Y has versions 1.0, 1.1, and 1.2

Obviously version 1.1 should be used. However, without bundler if library B gets loaded first, it will grab version 1.2, and then library A is hosed.

Bundler figures out all of the dependencies ahead of time, resolves situations like that, and then locks them down to the specific versions.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

BonzoESC posted:

Prefix commands with bundle exec to run them with the current bundle. alias be="bundle exec" will save time, as will bundle exec $SHELL

put this code from sam stephenson in your shell
code:
be() { [ "$1" = "a" ] && shift; bundle exec "$@"; }
now you can run
code:
> be a unicorn
> be a rake
> be a guard
> be a rails c

Oh My Science
Dec 29, 2008
I'll be looking at adding a cart to an existing clients site, and I would appreciate some feed back regarding spree. If I need a highly customized look, is spree simple enough to bend to my will? I took a look at the documentation, and they recommended against replacing the entire theme manually due to issues caused by future upgrades.

Also, is there anything else I should be looking at in terms of rails e-commerce. Spree seems to offer what the client wants, but I am eager to learn how to do this myself. Considering time is not an issue, are there some good (current) resources regarding creating your own simple(?) carts?

To clarify this is for an artists site, and all they really want to do is sell prints from their online portfolio. Ideally it would be nice to have the option of adding pieces to a store when they are uploaded to the portfolio, and define print size, prices, etc. all at the same time.

I need to be schooled in e-commerce please.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
Synchronization woes

I'm writing a Rails app that's similar to sites out there like Codepad and ideone that lets users submit code snippets to be compiled, executed, and view the output, but with some extra features I need. To prevent a large number of users from launching a ton of processes at once, I created a fixed number of threads that wait on a queue for jobs to run, and used AJAX to poll the server to find out when results were ready.

(Implementation note: Rather than use the built-in Queue class, I wrote my own queue using a mutex and condition variable because I needed to be able to prioritize jobs. I'm 100% confident that the behavior I'm seeing below is not due to bugs in this.)

This worked fine under Mongrel development, but when I moved the app over to nginx, this technique failed, because the requests occur in separate worker processes, because the process signaling the condvar isn't the one that started the job threads.

How can I make this work in a multi-process production environment? I want as lightweight a solution as possible -- I don't *need* to store these jobs or their results in the database, so I've avoided using the various job-queue gems out there. I suppose I can create a table for these jobs if the database is the best place to handle synchronization, but if that's the case, how do I have my worker threads wait for a row to appear in the table and make sure that no race conditions result when one thread takes a row and deletes it?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Flobbster posted:

How can I make this work in a multi-process production environment? I want as lightweight a solution as possible -- I don't *need* to store these jobs or their results in the database, so I've avoided using the various job-queue gems out there. I suppose I can create a table for these jobs if the database is the best place to handle synchronization, but if that's the case, how do I have my worker threads wait for a row to appear in the table and make sure that no race conditions result when one thread takes a row and deletes it?

Just use resque and store results in the database for 24 hours or something.

manero
Jan 30, 2006

BonzoESC posted:

Just use resque and store results in the database for 24 hours or something.

Seconding resque. It's ridiculously easy to get setup and running.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
Thanks! Resque hadn't come up in my searches but it looks like it may be a good solution to my problem, checking it out now.

Pardot
Jul 25, 2001




Alternatively suggesting https://github.com/ryandotsmith/queue_classic to avoid an extra dependency.

I've pushed a lot of jobs through it

quote:

select id from queue_classic_jobs limit 1;
id
-----------
591083164

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Pardot posted:

Alternatively suggesting https://github.com/ryandotsmith/queue_classic to avoid an extra dependency.

I've pushed a lot of jobs through it

That looks boss as hell; forwarding it to some people since I assume it works on Heroku Ronin.

Edit: "queue_classic handles over 3,000,000 jobs per day. It does this on Heroku's Ronin Database."

Frog Face
Nov 29, 2004
if im not better than God im the closest one
I posted this in the Android thread, but I think it might fit better here, so I'm reposting it.

I just finished the functional part of my first android application. I wrote three applications to get my idea to work. The first is a java web app, it grabs information from a website and puts it into a database on my hosted web server. The second is the web server, it is a ruby on rails application that just gives me basic REST and CRUD functionality. The third application is the android app, it grabs the information from my web server and then presents it in a easily readable format.

This is the first time I've ever done web development. My question is, how do I protect this information I've gathered on my web server, but still allow all the android devices to access it? What are the best practices I should be using, should I use encryption, authentication or both? Should I just set up one username and password that every devices uses? What should I do, so only my one web app can make modifications and not give that access to the devices?

After reading a little more and getting one response in the android thread, I think I should require authentication/authorization for creating/updating/deleting records on my webserver. I should make the reading public, but use some type of encryption, so only my android application can decrypt the data.

Does that sound like a good route to go? If so, does anyone have suggestions for authentication/authorization and encryption/decryption?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Frog Face posted:

Does that sound like a good route to go? If so, does anyone have suggestions for authentication/authorization and encryption/decryption?

What are you trying to do again?

Will users have to have accounts with your web service? That's authentication and authorization.

Will you use HTTPS? That's encryption.

Will you use encryption for at-rest data? Don't, it's a waste of time.

Pardot
Jul 25, 2001




If any of you are going to be in SF next week you should come to the heroku conference http://waza.heroku.com/

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


I'm so there.

hmm yes
Dec 2, 2000
College Slice
Topics look great, hopefully they post videos

Pardot
Jul 25, 2001




atastypie posted:

Topics look great, hopefully they post videos

I just asked and we're recording a bulk of them.

smug forum asshole
Jan 15, 2005

Pardot posted:

I just asked and we're recording a bulk of them.

:cool:

Frog Face
Nov 29, 2004
if im not better than God im the closest one

BonzoESC posted:

What are you trying to do again?

Will users have to have accounts with your web service? That's authentication and authorization.

Will you use HTTPS? That's encryption.

Will you use encryption for at-rest data? Don't, it's a waste of time.

In a nutshell, I want some one with my android app to have access to the records, but I don't want it to be accessible with just a browser, or any means other than my app. Then on top of that, I want the apps to just be able to read the records. I have another app, that I want to have creation/update/deletion capabilities.

Frog Face fucked around with this message at 05:15 on Jan 4, 2012

Adbot
ADBOT LOVES YOU

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Frog Face posted:

In a nutshell, I want some one with my android app to have access to the records, but I don't want it to be accessible with just a browser, or any means other than my app. Then on top of that, I want the apps to just be able to read the records. I have another app, that I want to have creation/update/deletion capabilities.

To keep out browsers, run the android app over https with http basic authentication and a hardcoded password. The https means that people will have to take five minutes to unzip and strings the apk to get your hardcoded password instead of thirty seconds to use wireshark.

Assuming the CRUD app is for your use only, just use a different http basic auth password and don't share it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply