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
A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Bob Morales posted:

Gotcha. In this particular case they'd want ALL the evaluations for the promotion so I'm not sure why they would put 0-99. Ugh.

99 is a pretty big number they'd probably never need to go higher than that.

Adbot
ADBOT LOVES YOU

Pardot
Jul 25, 2001




A MIRACLE posted:

99 is a pretty big number they'd probably never need to go higher than that.

Also no one will ever need the first one, 0.

NotShadowStar
Sep 20, 2000

Bob Morales posted:

Gotcha. In this particular case they'd want ALL the evaluations for the promotion so I'm not sure why they would put 0-99. Ugh.

Because they have no idea what they're doing, but they think they do.

http://guides.rubyonrails.org/active_record_querying.html#retrieving-multiple-objects-in-batches

rugbert
Mar 26, 2003
yea, fuck you
What are your guys' recommendations for routing this:

I have a members section where members can browse (index?), view (show), edit their profile, delete their account, and upload/manage images.

I am however using devise which has already made a bunch of routes using /users so I was thinking I should namespace the members section. But if I do that then my routes are going to be crap like /members/users/edit/1 and /members/users/1/images/new where I would like them to be /members/edit/1 and members/images/new

so Ive tried using this module thing I read about but that makes the root /users/editblabhalbh and then I tried using namespace and then modules but that does the same thing.

edit - on a related note, why are some of my routes missing paths when I rake routes?

code:
    resources :images do
    end
rake routes >>
   images     GET    /images(.:format){:action=>"index", :controller=>"images"}
              POST   /images(.:format){:action=>"create", :controller=>"images"}
   new_image  GET    /images/new(.:format){:action=>"new", :controller=>"images"}
   edit_image GET    /images/:id/edit(.:format){:action=>"edit", :controller=>"images"}
   image      GET    /images/:id(.:format){:action=>"show", :controller=>"images"}
              PUT    /images/:id(.:format){:action=>"update", :controller=>"images"}
              DELETE /images/:id(.:format){:action=>"destroy", :controller=>"images"}

Molten Llama
Sep 20, 2006

rugbert posted:

I have a members section where members can browse (index?), view (show), edit their profile, delete their account, and upload/manage images.

Controllers have no knowledge of the model you're using; the scaffold controller naming is strictly convention. If you want a Members controller that interacts with User objects, there's nothing stopping you from making one. You can have a Members controller and a Users controller that interact with a User model in different ways.

It's also transparent to the router. If you want REST and add a 'resources :members' to your routes.rb, it's just directing traffic to MembersController. (It'll make some REST fanatics blow a gasket because it's "wrong," but that's their problem.)

rugbert
Mar 26, 2003
yea, fuck you

Molten Llama posted:

Controllers have no knowledge of the model you're using; the scaffold controller naming is strictly convention. If you want a Members controller that interacts with User objects, there's nothing stopping you from making one. You can have a Members controller and a Users controller that interact with a User model in different ways.

It's also transparent to the router. If you want REST and add a 'resources :members' to your routes.rb, it's just directing traffic to MembersController. (It'll make some REST fanatics blow a gasket because it's "wrong," but that's their problem.)

Huh, in that case, if I wanted to nest my resources (members>images) I would just do

code:
resources :members do
   resources :images 
end
but how would I set the controller up for the members/images? Ive never nested my resources before? Im trying to set it up so each of my users has the ability to manage their own images. but I already have an image controller being used for something else, which is why I wanted to namespace it

skidooer
Aug 6, 2001

rugbert posted:

but how would I set the controller up for the members/images?
You don't have to really do anything special. The routes will provide, in your case, a member_id parameter from the URL (/members/:member_id/images) which you can do stuff with. Otherwise, it is just like writing a controller without nesting.
code:
class ImagesController < ApplicationController
  before_filter :set_member
  
  def index
    @images = @member.images
  end
  
  private
    def set_member
      @member = Member.find(params[:member_id])
    end
end

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

rugbert posted:

but how would I set the controller up for the members/images? Ive never nested my resources before? Im trying to set it up so each of my users has the ability to manage their own images. but I already have an image controller being used for something else, which is why I wanted to namespace it

Set up the routes first, run rake routes, and see what controller it expects them to route to?

(This is what I would try first, no idea if it works or not.)

rugbert
Mar 26, 2003
yea, fuck you

skidooer posted:

You don't have to really do anything special. The routes will provide, in your case, a member_id parameter from the URL (/members/:member_id/images) which you can do stuff with. Otherwise, it is just like writing a controller without nesting.
code:
class ImagesController < ApplicationController
  before_filter :set_member
  
  def index
    @images = @member.images
  end
  
  private
    def set_member
      @member = Member.find(params[:member_id])
    end
end

well I already have an image controller being used for something else (anonymous image submissions) and I need a separate controller for handling images by members. I guess I could make a second controller called "member_images" but its going to start looking gross.

code:
    resources :members, :except => [:new, :create] do
        resources :member_images
    end
code:
     member_member_images GET    /members/:member_id/member_images(.:format)          {:action=>"index", :controller=>"member_images"}
                          POST   /members/:member_id/member_images(.:format)          {:action=>"create", :controller=>"member_images"}
  new_member_member_image GET    /members/:member_id/member_images/new(.:format)      {:action=>"new", :controller=>"member_images"}
 edit_member_member_image GET    /members/:member_id/member_images/:id/edit(.:format) {:action=>"edit", :controller=>"member_images"}
      member_member_image GET    /members/:member_id/member_images/:id(.:format)      {:action=>"show", :controller=>"member_images"}
                          PUT    /members/:member_id/member_images/:id(.:format)      {:action=>"update", :controller=>"member_images"}
                          DELETE /members/:member_id/member_images/:id(.:format)      {:action=>"destroy", :controller=>"member_images"}
                  members GET    /members(.:format)                                   {:action=>"index", :controller=>"members"}
              edit_member GET    /members/:id/edit(.:format)                          {:action=>"edit", :controller=>"members"}
                   member GET    /members/:id(.:format)                               {:action=>"show", :controller=>"members"}
                          PUT    /members/:id(.:format)                               {:action=>"update", :controller=>"members"}
                          DELETE /members/:id(.:format)                               {:action=>"destroy", :controller=>"members"}

I dunno, Ill play around after dinner. thanks!

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

rugbert posted:

code:
     member_member_images GET    /members/:member_id/member_images(.:format)          {:action=>"index", :controller=>"member_images"}
                          POST   /members/:member_id/member_images(.:format)          {:action=>"create", :controller=>"member_images"}
  new_member_member_image GET    /members/:member_id/member_images/new(.:format)      {:action=>"new", :controller=>"member_images"}
 edit_member_member_image GET    /members/:member_id/member_images/:id/edit(.:format) {:action=>"edit", :controller=>"member_images"}
      member_member_image GET    /members/:member_id/member_images/:id(.:format)      {:action=>"show", :controller=>"member_images"}
                          PUT    /members/:member_id/member_images/:id(.:format)      {:action=>"update", :controller=>"member_images"}
                          DELETE /members/:member_id/member_images/:id(.:format)      {:action=>"destroy", :controller=>"member_images"}
                  members GET    /members(.:format)                                   {:action=>"index", :controller=>"members"}
              edit_member GET    /members/:id/edit(.:format)                          {:action=>"edit", :controller=>"members"}
                   member GET    /members/:id(.:format)                               {:action=>"show", :controller=>"members"}
                          PUT    /members/:id(.:format)                               {:action=>"update", :controller=>"members"}
                          DELETE /members/:id(.:format)                               {:action=>"destroy", :controller=>"members"}

I dunno, Ill play around after dinner. thanks!

It's okay to have multiple controllers that handle the same kind of resource, and it's okay to have routes that have path entries that aren't the controllers they route to.

skidooer
Aug 6, 2001

BonzoESC posted:

It's okay to have multiple controllers that handle the same kind of resource
Though it is also okay to have a single controller handle the same kind of resource in different ways. Personally, unless the way member images are handled is wildly different, I would probably keep everything in the images controller. Of course it is hard to make any recommendations without having knowledge of the entire problem domain.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

skidooer posted:

Though it is also okay to have a single controller handle the same kind of resource in different ways. Personally, unless the way member images are handled is wildly different, I would probably keep everything in the images controller. Of course it is hard to make any recommendations without having knowledge of the entire problem domain.

I'd rather have multiple (thin) controllers manipulating the same (fat) models than a single controller with a poo poo-ton of conditional logic based on routes manipulating the model. If this results in a lot of duplication, you should probably refactor more of your business logic into the model.

skidooer
Aug 6, 2001

BonzoESC posted:

I'd rather have multiple (thin) controllers manipulating the same (fat) models than a single controller with a poo poo-ton of conditional logic based on routes manipulating the model.
I don't feel something like this warrants a second controller.

code:
class ImagesController < ApplicationController
  def create
    @image = image_scope.create!(params[:image])
    head :created, :location => image_url(@image)
  end
  
  private
    def image_scope
      if params[:member_id]
        Member.find(params[:member_id]).images
      else
        Image
      end
    end
end

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
And in any case, you should be using inherited resources and let it do all the dirty nested route lifting for you:

code:
  class ImagesController < InheritedResources::Base
    belongs_to :user, :foo, :baz, :optional => true
  end

rugbert
Mar 26, 2003
yea, fuck you
Well Im still a noob so I have no idea what the last 3 posts meant.

Anyway, what I decide to do was nest the images controller in with the members section and then use my index controller to handle the anonymous image submissions for non-members.

So I have this:
code:
    root :to => "index#home"

    #public tattoo viewing and submissions
    match "/submit" => "index#new", :via => :get, :as => "submit"
    match "/submit" => "index#create", :via => :post
    match "/tattoo/:id" => "index#show", :via => :get, :as =>"tattoo"
    match "/tagged" => "index#tagged", :via => :get
    match "/tattoo/:id" => "index#destroy", :via => :delete
    match "/tattoos" => "index#index", :via => :get, :as => "tattoos"
I decided to match routes in my index controller instead of using resources so that way the urls look pretty.

I am running into an issue with my /submit page. It correctly uses the the index/new view but I get this error
code:
undefined method `images_path' for 

on teh line:
 <%= form_for @image, :html =>{:multipart => true} do |f| %>

and my index controller has:

  def new
    @image = Image.new
  end

images_path isnt used in any context around this, but the only way to make it work is this way:
code:
 <%= form_for :image, :html =>{:multipart => true} do |f| %>
Totally whack. Whatever it works now

Also - I set up my member nested routes like so:

code:
    resources :members, :except => [:new, :create] do
        resources :images
    end
and rake routes gives me
code:
 new_member_image GET    /members/:member_id/images/new(.:format)      {:action=>"new", :controller=>"images"}
buttt I get a routing error on the route saying no routes match :controller =>"images"

whew, routing is fun

rugbert fucked around with this message at 04:01 on Aug 14, 2011

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

What would be a good (or bad) way to add users to a system service (say email, that uses a plaintext config file for user info) from a Rails web interface? So if someone signs up, they get added to /etc/passwd and have an shell account? Is there something really, really wrong with just doing 'exec adduser -whatever username'?

Pardot
Jul 25, 2001




Bob Morales posted:

What would be a good (or bad) way to add users to a system service (say email, that uses a plaintext config file for user info) from a Rails web interface? So if someone signs up, they get added to /etc/passwd and have an shell account? Is there something really, really wrong with just doing 'exec adduser -whatever username'?

Make sure you sanitize the gently caress out of their username

NotShadowStar
Sep 20, 2000

Bob Morales posted:

What would be a good (or bad) way to add users to a system service (say email, that uses a plaintext config file for user info) from a Rails web interface? So if someone signs up, they get added to /etc/passwd and have an shell account? Is there something really, really wrong with just doing 'exec adduser -whatever username'?

Use LDAP, pam_ldap for system authentication and Net::LDAP in Ruby.
Seems like overkill, but if you're screwing around with system authentication, you should use a battle tested service instead of rolling your own and invariably loving it up.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

NotShadowStar posted:

Look at Padrino.

:woop:

How clean fresh tidy and snappy Padrino is. What is missing, that you guys are finding you use Rails instead?

Slow News Day
Jul 4, 2007

Quick question:

I installed Ruby 1.9.2-p290 using RVM.

But when I type "ruby -v" in terminal, it still says the version is 1.8.7, which is the default that OS X Lion ships with apparently. I assume this is because the Ruby that RVM installs is different fromt the one the operating system uses, or something.

Could someone explain this for me? I'm relatively new to OS X (and terminal) - AND I am also learning Ruby and RoR, so the learning curve is a lot steeper...

smug forum asshole
Jan 15, 2005

enraged_camel posted:

Quick question:

I installed Ruby 1.9.2-p290 using RVM.

But when I type "ruby -v" in terminal, it still says the version is 1.8.7, which is the default that OS X Lion ships with apparently. I assume this is because the Ruby that RVM installs is different fromt the one the operating system uses, or something.

Could someone explain this for me? I'm relatively new to OS X (and terminal) - AND I am also learning Ruby and RoR, so the learning curve is a lot steeper...

Type rvm use to see if rvm is being caught by bash, and what version it's set up to use.

If it says it's using version 1.8.7, rvm list will show the other installed versions of ruby you can choose from

If it doesn't recognize the rvm command, you might need to source ~/.profile -- you did add the line of code that rvm needs to be loaded into your shell session into your ~/.profile, didn't you?

Nybble
Jun 28, 2008

praise chuck, raise heck

enraged_camel posted:

Quick question:

I installed Ruby 1.9.2-p290 using RVM.

But when I type "ruby -v" in terminal, it still says the version is 1.8.7, which is the default that OS X Lion ships with apparently. I assume this is because the Ruby that RVM installs is different fromt the one the operating system uses, or something.

Could someone explain this for me? I'm relatively new to OS X (and terminal) - AND I am also learning Ruby and RoR, so the learning curve is a lot steeper...

You need to set which version you are using.

code:
$ rvm --default use 1.9.2
If you are looking to learn more, I'd suggest this tutorial: http://ruby.railstutorial.org/chapters/beginning

Or if you want a book: Agile Web Development with Rails, 4th edition is a decent resource to walk you through learning it.

Slow News Day
Jul 4, 2007

smug forum rear end in a top hat posted:

Type rvm use to see if rvm is being caught by bash, and what version it's set up to use.

If it says it's using version 1.8.7, rvm list will show the other installed versions of ruby you can choose from

If it doesn't recognize the rvm command, you might need to source ~/.profile -- you did add the line of code that rvm needs to be loaded into your shell session into your ~/.profile, didn't you?

When I type rvm use, it says it's using 1.9.2.

But why does ruby -v show 1.8.7?

What's the difference between the rvm ruby version and the "system" ruby version? What is the latter used for? If I'm doing Ruby development, do I need to worry about this discrepancy?

@Nybble: I already set 1.9.2 as the rvm default - thanks for the suggestion though. :) Also thanks for the links, I'll take a look.

Nybble
Jun 28, 2008

praise chuck, raise heck

enraged_camel posted:

When I type rvm use, it says it's using 1.9.2.

But why does ruby -v show 1.8.7?

What's the difference between the rvm ruby version and the "system" ruby version? What is the latter used for? If I'm doing Ruby development, do I need to worry about this discrepancy?

Go ahead and type in that command anyway (rvm use 1.9.2), and then try ruby -v. If you still see 1.8.7, then there is an issue I'm not sure about.

I'm just a few weeks ahead of you experience-wise, I just started learning myself, and those tutorials have been pretty helpful.

Molten Llama
Sep 20, 2006

enraged_camel posted:

When I type rvm use, it says it's using 1.9.2.

But why does ruby -v show 1.8.7?

Your PATH probably isn't getting set properly for some reason. After you 'rvm use 1.9.2', it should get updated to give the rvm version priority, and look similar to this:
code:
battlecat:~ $ rvm use 1.9.2
Using /Users/mlla/.rvm/gems/ruby-1.9.2-p290
battlecat:~ $ echo $PATH
/Users/mlla/.rvm/gems/ruby-1.9.2-p290/bin:[...]
Also, are you absolutely positively sure you're using bash? rvm will run but not work with tcsh or zsh. Make sure "echo $SHELL" returns /bin/bash.

If you're using a system that's been repeatedly migrated/upgraded, you may be on tcsh and not know it.

Molten Llama fucked around with this message at 01:06 on Aug 22, 2011

Pardot
Jul 25, 2001




Molten Llama posted:

Your PATH probably isn't getting set properly for some reason. After you 'rvm use 1.9.2', it should get updated to give the rvm version priority, and look similar to this:
code:
battlecat:~ $ rvm use 1.9.2
Using /Users/mlla/.rvm/gems/ruby-1.9.2-p290
battlecat:~ $ echo $PATH
/Users/mlla/.rvm/gems/ruby-1.9.2-p290/bin:[...]
Also, are you absolutely positively sure you're using bash? rvm will run but not work with tcsh or zsh. Make sure "echo $SHELL" returns /bin/bash.

While I can't speak for tcsh, I can 100% say that rvm works fine with zsh. Also unless you go out of your way to change it the default shell on os x is bash. (But using bash instead of zsh is like using mysql instead of postgres: poo poo)

The rvm initialization lines for enraged_camel are probably just not being ran, either they aren't in his .whatever file, or the one he has it in isn't being ran.

Molten Llama
Sep 20, 2006

Pardot posted:

While I can't speak for tcsh, I can 100% say that rvm works fine with zsh. Also unless you go out of your way to change it the default shell on os x is bash. (But using bash instead of zsh is like using mysql instead of postgres: poo poo)

Good to know. I gave it a super quick try with zsh and tcsh and neither one updated with rvm environment changes (but rvm's probably out of date on this system, it may work with something newer than I've got).

bash is the default shell on OS X today—until 10.3 it was tcsh, and depending how you've moved between releases and computers it's possible to still be on tcsh today. Unknowingly having the old school default bites longtime users on an occasional basis.

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Are there any good resources, free or otherwise, on making internal DSLs?

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Doc Hawkins posted:

Are there any good resources, free or otherwise, on making internal DSLs?

Have an example of what you want it to look like? There's several ways, including the Magic Pen style that I like.

NotShadowStar
Sep 20, 2000
There's lots and lots of ways and styles. I'm not a fan of the old style redundant do |obj|; obj.something; obj.another_thing; that Rake, AR migrations and such do to a single object. Instead I prefer what you see in a Gemfile, FactoryGirl or Mongoid

*theres a couple limitations on doing it that way that occasionally you need to do the do |something| syntax, so that's why we need to know what you're doing.

Lamont Cranston
Sep 1, 2006

how do i shot foam
I'm having a little time zone trouble.

So I get the idea that times stored in the DB are in UTC, and it's the app's responsibility to adjust for local timezones. I've set my timezone as Eastern in application.rb. My form uses a time_select.

So I submit the form with a time of, say, 13:00. My understanding is that it should go into the database as 18:00 UTC (as EST is UTC-5), but it doesn't, it goes in as 13:00 UTC. Is there somewhere else I need to be compensating for this before I send it to the database? What am I doing wrong here?


I had the types set in my schema as time instead of datetime. Changing that fixed it right up.

Lamont Cranston fucked around with this message at 22:57 on Aug 22, 2011

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

Rails noob here. Is there a "cleaner," less bulky way of extracting inner text XML with Nokogiri? Feel free to make fun of my awful code.
code:
xml_file = Nokogiri::XML(OpenURI::OpenRead("my_url"))
events = xml_file.xpath("//event")

events.each do |e|
  puts "Creating " + (e>"event_name").text + "..."
  # get the date (for readability)
  date_range = e>"date_range"
  start_date = DateTime.parse( (date_range>"start_date").text + 
                               (date_range>"start_time").text )
  end_date = DateTime.parse( (date_range>"end_date").text +
                             (date_range>"end_time").text )


  Event.create(
    :title => (e>"event_name").text,
    :unique_event_id => (e>"unique_event_id").text.to_i,
    :description => (e>"description").text ,
    :start_at => start_date,
    :end_at => end_date )
end

A MIRACLE fucked around with this message at 22:08 on Aug 22, 2011

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


NotShadowStar posted:

we need to know what you're doing.

Well, at the risk of being outed as one of those "nerd" people: http://www.github.com/njay/tabletop

It's one of those pointlessly ambitious geek proects: make it easier for people to make software tools for or versions of "pen and paper" games by making a DSL for them. Teach Yourself Ruby the Hard and Uncool Way.

There's a lot more I want to do, but I thought that a survey of resources about the field might help me make decisions about what sort of things I should want to do.

NotShadowStar
Sep 20, 2000
I don't see anything horrible but I cleaned it up slightly and made it a but more ruby-like. Don't be afraid to stack methods with ruby, you don't get the horrors of NullReferenceExceptions if something goes wrong like Java or C#.

code:
Nokogiri::XML(open "my_url").xpath("//event").each do |e|
  # get the date (for readability)
  date_range = e>"date_range"
  start_date = DateTime.parse( (date_range>"start_date").inner_text + 
                               (date_range>"start_time").inner_text )
  end_date = DateTime.parse( (date_range>"end_date").inner_text +
                             (date_range>"end_time").inner_text )


  Event.create(
    :title => (e>"event_name").inner_text,
    :unique_event_id => (e>"unique_event_id").inner_text.to_i,
    :description => (e>"description").inner_text ,
    :start_at => start_date,
    :end_at => end_date 
  )
end

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Doc Hawkins posted:

Well, at the risk of being outed as one of those "nerd" people: http://www.github.com/njay/tabletop

It's one of those pointlessly ambitious geek proects: make it easier for people to make software tools for or versions of "pen and paper" games by making a DSL for them. Teach Yourself Ruby the Hard and Uncool Way.

There's a lot more I want to do, but I thought that a survey of resources about the field might help me make decisions about what sort of things I should want to do.

Your die language is scrub-tier: https://github.com/bkerley/crapshoot & https://github.com/bkerley/triskelion

Mine's a Ragel-based implementation, so an external DSL.

Use it online at http://triskelion.heroku.com/

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


BonzoESC posted:

Your die language is scrub-tier:
Hahaha! Of that, I had no doubt. Hopefully, from such humble seeds the mighty oak yadda yadda. I mean, I do want it to be much more than a die language.


:stare: That's...really cool.

I like how terse it is, but I'm hoping to make something that's as natural-language as I can. The hope is that anyone who makes (or just likes) an RPG could figure out how to describe its rules and procedures with just a commands cheat-sheet and a few minutes thought. For that kind of purpose, I think that "drop_lowest" is kinder than "v". And also I need them to be able to do stuff like "tell me how many dice came up seven or higher, counting tens twice" or "count sets of die values, multiply the size of the largest set by ten, then add the value of the dice in that set" without needing to learn regular expressions.

The results object extending Int is an inspired idea. I thought about making a separate results object for a while, but it seemed like there was too much state to track: you only really know when it's stopped being a "roll" and started being a "result" when the player stops interacting with it, so I just piled everything into the Roll class. :sigh:

If there's no good short-cuts to understanding, I will soldier on.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Doc Hawkins posted:

I like how terse it is, but I'm hoping to make something that's as natural-language as I can. The hope is that anyone who makes (or just likes) an RPG could figure out how to describe its rules and procedures with just a commands cheat-sheet and a few minutes thought. For that kind of purpose, I think that "drop_lowest" is kinder than "v". And also I need them to be able to do stuff like "tell me how many dice came up seven or higher, counting tens twice" or "count sets of die values, multiply the size of the largest set by ten, then add the value of the dice in that set" without needing to learn regular expressions.
This is more of a requirements issue, but while we drop lowest/highest in D&D 3e all the time, we have never needed to count sets or do an automatic results chain during the flow of the game; we mostly wanted auditable rolls and a way to describe them out of band of the normal table conversation.

quote:

The results object extending Int is an inspired idea. I thought about making a separate results object for a while, but it seemed like there was too much state to track: you only really know when it's stopped being a "roll" and started being a "result" when the player stops interacting with it, so I just piled everything into the Roll class. :sigh:

This goes back to requirements; originally (November 2010) rolling was handled inside the rails app with regexes, but I broke it out (December 2010) so I could play with parsers. Making the Result delegate on top of Integer (January 2011) is just a hack, since the API returning an Integer was already in place, and I didn't want to re-engineer everything to allow getting a description for a past roll.

Your best bet for designing a DSL is to just write some poo poo with no implementation and see if you like it. If you do, figure out how to implement it. If not, try again. Here's a prototype DSL for a Twitter client framework that I never got around to making:
code:
require 'cookin'

Cookin.with 'miamirb' do |filter|
  filter.track '#miamirb' do |t|
    t.reply 'Thanks for mentioning #miamirb!'
  end

  filter.track 'miami ruby', 'miami rails' do |t|
    t.reply 'Have you asked anybody in the Miami Ruby Brigade?'
  end
  
  filter.follow 16413577 do |t|
    t.reply "I'll pass that on!"
    dm 'BonzoESC', "#{t[:user][:screen_name]} said something #{t.permalink}"
  end
end
More about why you want to make a mock-up before code to implement it: http://gettingreal.37signals.com/ch06_From_Idea_to_Implementation.php

Doc Hawkins
Jun 15, 2010

Dashing? But I'm not even moving!


Yeah, that's basically what I've done so far. BDD 4 lyffe.

I guess was hoping there were articles that could give me some tips like "Be sure to consider factor X, which might not occur to you until you've wasted a lot of time doing something dumb!" But all I found was an article explaining how to use instance_eval to avoid "do |o| o.stuff end" syntax.

I think I need to bring in some other stakeholders. Maybe I'll be able to harass some folks at PAX into doing a focus group.

Cocoa Crispies
Jul 20, 2001

Vehicular Manslaughter!

Pillbug

Doc Hawkins posted:

Yeah, that's basically what I've done so far. BDD 4 lyffe.

I guess was hoping there were articles that could give me some tips like "Be sure to consider factor X, which might not occur to you until you've wasted a lot of time doing something dumb!" But all I found was an article explaining how to use instance_eval to avoid "do |o| o.stuff end" syntax.

I think I need to bring in some other stakeholders. Maybe I'll be able to harass some folks at PAX into doing a focus group.
Don't worry about so much at the beginning. If you don't have "natural" stakeholders (friends that were interested in using the result and want to learn more Ruby, in my case), don't go recruiting any.

Would your DSL be useful for doing a D&D-style character sheet?
code:
Sheet 'Character' do
  s = '4d6v'
  str s
  dex s
  con s
  int s
  wis s
  cha s
end

doc = Sheet.for 'Character'
doc.str #=> 8
doc.str.description #=> "4 + 3 + 1 + 1 - 1"
I put the standard '4d6 drop lowest' into a variable s to cut down on the typing, and let the DSL turn the six attributes (that hit method_missing) into attributes on the sheet.

How about handling parameters for specific levels of classes?
code:
Sheet 'Fighter level' do
  parameter :level
  hp "#{level}d10"
end

allan = Sheet.for 'Fighter'
allan.hp # ParameterError: level not set
allan.level = 5
allan.hp #=> 30

brutus = Sheet.for 'Fighter', :level=>3
brutus.hp #=> 23
You can raise a few questions from this: would you handle composition and inheritance, so that a "Fighter level" subclasses a "Level," and a "Character" includes an array of "Levels" in its composition? Would you want your own syntax for it?

Don't answer those yet! Get something simple (the 'Character' example above maybe?) working, worry about the rest later.

Adbot
ADBOT LOVES YOU

A MIRACLE
Sep 17, 2007

All right. It's Saturday night; I have no date, a two-liter bottle of Shasta and my all-Rush mix-tape... Let's rock.

What are the differences between these?
code:
<% ... %>
# and
<% ... -%>

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