Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 01 13:26
    asterite synchronize #12551
  • Oct 01 12:27
    asterite review_requested #12551
  • Oct 01 12:27
    asterite review_requested #12551
  • Oct 01 12:27
    asterite labeled #12551
  • Oct 01 12:27
    asterite labeled #12551
  • Oct 01 12:26
    asterite opened #12551
  • Oct 01 11:19
    straight-shoota labeled #12542
  • Oct 01 11:19
    straight-shoota labeled #12542
  • Sep 30 20:54
    oprypin edited #12545
  • Sep 30 17:04
    straight-shoota edited #12530
  • Sep 30 16:06
    straight-shoota labeled #12550
  • Sep 30 16:03
    straight-shoota milestoned #12549
  • Sep 30 16:03
    straight-shoota milestoned #12549
  • Sep 30 16:01
    Hadeweka opened #12550
  • Sep 30 16:01
    Hadeweka labeled #12550
  • Sep 30 14:12
    straight-shoota labeled #12549
  • Sep 30 14:12
    straight-shoota labeled #12549
  • Sep 30 14:12
    straight-shoota labeled #12549
  • Sep 30 14:12
    straight-shoota opened #12549
  • Sep 30 13:54
    straight-shoota closed #12282
Johannes Müller
@straight-shoota
I'm currently working on refactoring Kemal to use encapsulation instead of global state. There I have a macro Kemal::Base.get and an instance method Kemal::Base#get. Currently, when I call get from inside a instance method, it calls the macro, but I would expect it to call the instance method. And it's ugly if you have to invoke the instance method with explicit receiver...
Ghost
@ghost~55586c4815522ed4b3e08557
you could use with my_obj yield to specify a strong implicit receiver
Johannes Müller
@straight-shoota
this only works with a block, not if you're directly inside a method
Ghost
@ghost~55586c4815522ed4b3e08557
what is the macro get for ?
Cris Ward
@crisward

@straight-shoota If you're doing that, FWIW perhaps look at how express.js does it. Ie.

var app=new Express();
app.get("/",function(res,res){
  res.send("hello")
})
app.listen(3000)

could become

app = Kemal.new
app.get "/" do |env|
  "hello"
end
app.run
Ghost
@ghost~55586c4815522ed4b3e08557
how do you want the users of your lib to use either the method or the macro?
The macros create a DSL at class scope, the method at instance scope
@crisward this is already possible in my branch
an alternative is
class MyApp < Kemal::Application
  get "/" do |env|
    "hello"
  end
end
MyApp.run
Ghost
@ghost~55586c4815522ed4b3e08557
should this call the macro or the method? can you show an example using the 2?
Johannes Müller
@straight-shoota
class MyApp < Kemal::Application
  get "/" do |env|
    "hello"
  end
  def initialize_instance_routes
    get "/foo" do |env|
      "bar"
    end
  def
end
app = MyApp.new
app.initialize_instance_routes
app.run
Line 2 targets the maro, line 6 the instance method
Ghost
@ghost~55586c4815522ed4b3e08557
I don't get the use case of instance routes, but an idea of impl could be:
class MyApp < Kemal::Application
  get "/" do |env|
    "hello"
  end

  # `instance_routes` could be a macro that will define the `initialize_instance_routes` method
  instance_routes do # Here using `with .. yield`, the instance routes can be configured with another DSL (could be methods, .. whatever)
    get "/foo" do |env|
      "bar"
    end
  end
end
app = MyApp.new
app.initialize_instance_routes
app.run
From IRC (bridge bot)
@FromIRC
<oprypin> removed really
From IRC (bridge bot)
@FromIRC
<Groogy> mersenne twister random generation isn't that good though :⁠/
Johannes Müller
@straight-shoota
Well the initialize_instance_routes method is not part of the DSL, it could be any method defined in a custom application subclass.
Ghost
@ghost~55586c4815522ed4b3e08557
I like the idea of macro only for class scope though!
Johannes Müller
@straight-shoota
The use case is that you might want to optionally add routes depending on configuration values or some other decision run-time
Ghost
@ghost~55586c4815522ed4b3e08557
but in this case, you should have a Router object, that you configure via methods or sth like that
Johannes Müller
@straight-shoota
The router is configured through the application
get method would actually call route_handler.add_route("GET", path, &block)
Ghost
@ghost~55586c4815522ed4b3e08557
like:
class App < Kemal::Application
  def some_method
    router.setup do
      get "kjhj" ...
    end
  end
end
Johannes Müller
@straight-shoota
I think the idea is to put these abstractions away
Bar Hofesh
@bararchy
Is there a PDF creator in Crystal ?
Cris Ward
@crisward
Int24 in crystal anyone?
From IRC (bridge bot)
@FromIRC
<oprypin> no
Yuri Vendruscolo da Silveira
@yvern
hello,
how can I get current working dir path (pwd) at run time?
basically I need to access other files that are going to be at the same folder, but if I either use "./file_name" or Dir.current+"/fie_name", crystal gets the path at compile time, and if I place this same folder anywhere else, it tries to look for those files at the dir I compiled it.
thanks!
Ghost
@ghost~55586c4815522ed4b3e08557
Dir.current should give you the runtime current working directory
Cris Ward
@crisward
Didn't think so...
Ghost
@ghost~55586c4815522ed4b3e08557
It calls internally getcwd which does just that
Peter Leitzen
@splattael
As Crystal 0.23.1 is out, is there a timeline to release 0.23.1 as a docker image on https://hub.docker.com/r/crystallang/crystal/?
Yuri Vendruscolo da Silveira
@yvern

I have compiled simply :

puts Dir.current

and I got:

Yuris-MacBook-Pro:~ yuri$ /Users/yuri/Desktop/test ; exit;
/Users/yuri

so even though I opened it from desktop, it gives me another path... ):

Ghost
@ghost~55586c4815522ed4b3e08557
Well, it gives you your current working directory, not the directory where the binary is. I can see in your prompt that you are in ~ which corresponds to your home, which is /Users/yuri.
The binary is in Desktop, but you launched it from your home directory
Yuri Vendruscolo da Silveira
@yvern
in that case, is there a way to get the dir where the binary is?
From IRC (bridge bot)
@FromIRC
<oprypin> @yvendruscolo, it's File.dirname(PROGRAM_NAME)
<oprypin> or the notorious crystal-lang/crystal#4715
Yuri Vendruscolo da Silveira
@yvern
thanks guys!
From IRC (bridge bot)
@FromIRC
<Papierkorb> $PROGRAM_NAME can be changed, by the running program, or by the program executing it
<oprypin> sorry what
<oprypin> this is the better alternative, but i dont get your comment about PROGRAM_NAME
<Papierkorb> program name is the name, which doesn't have to be the name of the binary.
<oprypin> demonstrate
MB
@marceloboeira
Hello Guys
From IRC (bridge bot)
@FromIRC
<Papierkorb> See exec(3).
MB
@marceloboeira
quick question, is it possible to get the real class/type of a object from a macro?
From IRC (bridge bot)
@FromIRC
<oprypin> @marceloboeira, {{ @type }}
MB
@marceloboeira
hmm, not sure. the type of a given parameter of a macro
macro foo(value)
      MyGenericClass({{value.class_name.id}}).new
end

foo("hello")