newbie issue

0 views
Skip to first unread message

Goran

unread,
May 19, 2008, 4:46:36 PM5/19/08
to Adhearsion
Hi all!

I'm kinda new to ruby and adhearsion and it is a probably stupid
question but I would appreciate if someone could help me with this one

I'm not very good at English so I think it would be the best if I show
you what's bothering me rather than I try to describe it.. :)
so here's the dummy application to show what I wanted to do:

contents of my 'dialplan.rb' file:

adhearsion{
case extension
when 5
myApp = new_my_application
myApp.start
end
}


contents of my 'my_application.rb' file:

class MyApplication

add_call_context :as => :call_context

def start
sc = SomeClass.new
sc.some_method
call_context.play 'hello'
end
end


contents of my 'some_class.rb' file:

class SomeClass
def some_method
call_context.play 'welcome'
end
end


so the 'hello' part is working fine but for the 'welcome' part I get
this error:

ERROR agi: #<NameError: undefined local variable or method
`call_context' for #<SomeClass:0xb76cdc18>>


please help!

Goran

jan....@gmail.com

unread,
May 20, 2008, 8:03:32 AM5/20/08
to Adhearsion
You'll need to make SomeClass aware of call_context as well. Simply
passing the variable seems to work:

-------
class SomeClass

attr_reader :call_context

def initialize(call_context)
@call_context = call_context
end

def some_method
call_context.play 'welcome'
end
end

sc = SomeClass.new(call_context)
-------

but there might be a better way to do it. I don't fully get the
extend_with_components_with_call_context! and
Adhearsion::Components::Behavior stuff yet so I'm not sure.
Anyone?


Jan

Goran

unread,
May 20, 2008, 8:26:31 AM5/20/08
to Adhearsion
thank you for the response Jan!

I knew solution could be as simple as that.. but as I said, I'm the
Ruby newbie, and i'm still exploring and learning stuff.. Though I
tried to include and extend
Adhearsion::Components::Behavior::ClassMethods module into the
SomeClass, it didn't work (maybe I did it wrong).. I't never occured
to me that I could just pass it like that :-/
because I wasn't sure what exactly 'call_context' is - a variable, a
symbol, a method or something else! :)

anyway it works fine now.. big thanks!

Thomas Howe

unread,
May 20, 2008, 10:20:49 AM5/20/08
to adhea...@googlegroups.com
Hi Goran -

Here's what's been recommended to me:

1) Take your code and include it in "startup.rb" It will now be
available whenever you need it in your code.
2) When you call your code, include a reference to call_context to
your calls, so you can mess with it yourself.

There's some issues with the module system as it is, and it's probably
going to change. Using this method clears up how you can get to the
call, and how you include it in the project.

Hope this helps,
Thomas

--
-----------------------------------------------
Thomas Howe
http://www.thomashowe.com
+1 (508) 364-9972

jan....@gmail.com

unread,
May 20, 2008, 3:05:00 PM5/20/08
to Adhearsion

OK figured out how this works.. You can do

----
class SomeClass

include Adhearsion::Components::Behavior

add_call_context :as => :call_context

def some_method
call_context.play 'welcome'
end
end
----

but then a special "initializer" (instantiate_with_call_context) needs
to be used and thus you need to call new_some_class to create the
instance. Which is defined on DialPlan instance, so:

-----
class MyApplication

add_call_context :as => :call_context

def start
sc = call_context.new_some_class
sc.some_method
call_context.play 'welcome'
end
end
------

I wouldn't say it's nicer or cleaner though..

Jan

Goran

unread,
May 20, 2008, 4:00:12 PM5/20/08
to Adhearsion
Well that's exactly what I was trying to do, except the 'sc =
call_context.new_some_class' part in MyApplication class.. thank you
for posting this, it made some things more clear to me now..

Anyway I did it with the use of reference, and this project I'm
working on isn't anything very serious, though it is for my graduate
project and I was curious about that because I wanted to seperate
parts of code into different files for the presentation purposes.

Once again big thanks to you and Thomas for the responses!
Reply all
Reply to author
Forward
0 new messages