librelist archives

« back to archive

Console to use with Nesta?

Console to use with Nesta?

From:
James Abbott
Date:
2012-12-09 @ 12:26
Hello all,

I'm about to code some stuff in Nesta, mostly for enhancing my site's
information architecture. I'd be nice to have a console for accessing the
app state, the way Rails has its rails c. I've searched around and found
tux and irb:

http://tagaholic.me/2011/04/10/tux-a-sinatra-console.html
http://mikeebert.tumblr.com/post/29941784481/running-a-sinatra-console

Any suggestions as to what to use? Nesta is installed as a gem, so I've
tried the irb approach with:

require '/Users/me/.rvm/gems/ruby-1.9.3-p0/gems/nesta-0.9.13/lib/nesta.rb

but it doesn't seem to work.

Thanks,
James

Re: [nesta] Console to use with Nesta?

From:
Graham Ashton
Date:
2012-12-10 @ 18:36
On 9 Dec 2012, at 12:26, James Abbott <abbottjam@gmail.com> wrote:

> Any suggestions as to what to use? Nesta is installed as a gem, so I've 
tried the irb approach with:
> 
> require '/Users/me/.rvm/gems/ruby-1.9.3-p0/gems/nesta-0.9.13/lib/nesta.rb

Try this:

$ bundle exec irb -r 'nesta/app'
irb(main):001:0> Nesta::Page
=> Nesta::Page
irb(main):002:0> Nesta::Page.find_by_path('ruby')
=> #<Nesta::Page:0x007fb3be23e730 
@filename="content/pages/ruby/index.mdown", @format=:mdown, [snip]

If you've also got a local app.rb file that you want to load, this'll do it:

$ bundle exec irb -r 'nesta/app' -r ./app

I've not fiddled with it beyond that. If you're using a non-standard 
application root you'll probably want to load nesta/env prior to 
nesta/app, the same way that it happens in config.ru.

--
Graham Ashton
Founder, The Agile Planner
http://www.theagileplanner.com | @agileplanner | @grahamashton



Re: [nesta] Console to use with Nesta?

From:
James Abbott
Date:
2012-12-12 @ 12:33
Awesome, thanks! Just what I needed. I don't have an app.rb right now, but
I will - that's where the new code will go - so having that option as well
is great.

Is this what I need to read to understand how it works?
https://github.com/gma/bundler-exec

Cheers,
James


On Mon, Dec 10, 2012 at 7:36 PM, Graham Ashton <graham@effectif.com> wrote:

> Nesta::Page.find_by_path('ruby')
>

Re: [nesta] Console to use with Nesta?

From:
Graham Ashton
Date:
2012-12-12 @ 12:56
On 12 Dec 2012, at 12:33, James Abbott <abbottjam@gmail.com> wrote:

> Awesome, thanks! Just what I needed. I don't have an app.rb right now, 
but I will - that's where the new code will go - so having that option as 
well is great.
> 
> Is this what I need to read to understand how it works?
> https://github.com/gma/bundler-exec

I doubt it, it's unrelated. Which bit would you like to understand, specifically?

Re: [nesta] Console to use with Nesta?

From:
James Abbott
Date:
2012-12-12 @ 13:23
>
> Which bit would you like to understand, specifically?
>

1) What's the role of bundle exec, which as far I have understood, is a gem
management mechanism (
http://blog.davidchelimsky.net/2011/07/18/stop-typing-bundle-exec/), in
allowing one to access Nesta's app state. I suspect it really is irb that
enables the console, but bundle exec?

2) If there is code or documentation somewhere for 1) that one could read
to wise up.

/J.


On Wed, Dec 12, 2012 at 1:56 PM, Graham Ashton <graham@effectif.com> wrote:

> On 12 Dec 2012, at 12:33, James Abbott <abbottjam@gmail.com> wrote:
>
> Awesome, thanks! Just what I needed. I don't have an app.rb right now, but
> I will - that's where the new code will go - so having that option as well
> is great.
>
> Is this what I need to read to understand how it works?
>
> https://github.com/gma/bundler-exec
>
>
> I doubt it, it's unrelated. Which bit would you like to understand,
> specifically?
>

Re: [nesta] Console to use with Nesta?

From:
Graham Ashton
Date:
2012-12-12 @ 13:33
On 12 Dec 2012, at 13:23, James Abbott <abbottjam@gmail.com> wrote:

> 1) What's the role of bundle exec, which as far I have understood, is a 
gem management mechanism 
(http://blog.davidchelimsky.net/2011/07/18/stop-typing-bundle-exec/), in 
allowing one to access Nesta's app state. I suspect it really is irb that 
enables the console, but bundle exec?

Bundler has improved a lot over the last couple of years. If you set 
yourself up to use it properly (e.g. with --binstubs), you could argue 
that you don't need bundler-exec. In fact, many people do argue that.

All bundle-exec does is try and automate the insertion of `bundle exec` in
front of any commands that ship with your bundled gems, to ensure that the
correct version of the installed gems is loaded by that command.

It hasn't really got anything to do with nesta, which will work with/without it.

> 2) If there is code or documentation somewhere for 1) that one could 
read to wise up. 

There's the README which you'll have seen, and a blog post somewhere on 
effectif.com.

So what's happening when you run `irb -rnesta/app`?

The -rlibrary switch will require the library immediately after startup, 
so it's just requiring a file out of the gem. It's probably not requiring 
the one in your bundle (unless you have bundler-exec configured to 
intercept irb, which it sounds like you might have).

-- 
Graham Ashton
Founder, The Agile Planner
http://theagileplanner.com | @agileplanner | @grahamashton

Re: [nesta] Console to use with Nesta?

From:
James Abbott
Date:
2012-12-12 @ 14:57
Ah, that makes sense. So bundle exec is an explicit command for a script
that should run implicitly, by default.

I tried the console without bundle exec (irb -r 'nesta/app') and it works
identically to the one invoked with bundle exec. So I guess it is
intercepting, unless I'm misinterpreting the output of 'type irb' (as
explained in your README):

$ type irb
irb is /Users/me/.rvm/rubies/ruby-1.9.3-p0/bin/irb

/J.



On Wed, Dec 12, 2012 at 2:33 PM, Graham Ashton <graham@effectif.com> wrote:

> On 12 Dec 2012, at 13:23, James Abbott <abbottjam@gmail.com> wrote:
>
> 1) What's the role of bundle exec, which as far I have understood, is a
> gem management mechanism (
> http://blog.davidchelimsky.net/2011/07/18/stop-typing-bundle-exec/), in
> allowing one to access Nesta's app state. I suspect it really is irb that
> enables the console, but bundle exec?
>
>
> Bundler has improved a lot over the last couple of years. If you set
> yourself up to use it properly (e.g. with --binstubs), you could argue that
> you don't need bundler-exec. In fact, many people do argue that.
>
> All bundle-exec does is try and automate the insertion of `bundle exec` in
> front of any commands that ship with your bundled gems, to ensure that the
> correct version of the installed gems is loaded by that command.
>
> It hasn't really got anything to do with nesta, which will work
> with/without it.
>
> 2) If there is code or documentation somewhere for 1) that one could read
> to wise up.
>
>
> There's the README which you'll have seen, and a blog post somewhere on
> effectif.com.
>
> So what's happening when you run `irb -rnesta/app`?
>
> The -rlibrary switch will require the library immediately after startup,
> so it's just requiring a file out of the gem. It's probably not requiring
> the one in your bundle (unless you have bundler-exec configured to
> intercept irb, which it sounds like you might have).
>
> --
> Graham Ashton
> Founder, The Agile Planner
> http://theagileplanner.com | @agileplanner | @grahamashton
>
>