Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 12:51
    straight-shoota closed #12224
  • 12:51
    straight-shoota closed #13034
  • 12:15
    straight-shoota milestoned #12921
  • 12:15
    straight-shoota milestoned #12921
  • 10:44
    straight-shoota edited #12921
  • 02:39
    cyangle synchronize #12921
  • 01:08
    cyangle synchronize #12921
  • 01:08
    cyangle synchronize #12921
  • Feb 03 22:11
    straight-shoota labeled #12794
  • Feb 03 22:11
    straight-shoota assigned #12794
  • Feb 03 22:07
    straight-shoota synchronize #12959
  • Feb 03 21:38
    straight-shoota milestoned #12983
  • Feb 03 21:38
    straight-shoota milestoned #12983
  • Feb 03 17:37
    straight-shoota milestoned #13045
  • Feb 03 17:37
    straight-shoota milestoned #13045
  • Feb 03 16:49
    straight-shoota review_requested #13045
  • Feb 03 16:49
    straight-shoota review_requested #13045
  • Feb 03 16:49
    straight-shoota demilestoned #13045
  • Feb 03 16:49
    straight-shoota demilestoned #13045
  • Feb 03 16:49
    straight-shoota edited #13045
manveru
@manveru:matrix.org
[m]
sure, but def initialize(@nomad_base_url : URI) is pretty much the same and less confusing
George Dietrich
@Blacksmoke16
exactly :)
this is a case of macro over complicating something that is simple
manveru
@manveru:matrix.org
[m]
i'm mostly exploring macros at this point, so was just wondering how recursive it can get :)
George Dietrich
@Blacksmoke16
I think there's away you can get this to work, but it's not recommended, give me a sec
manveru
@manveru:matrix.org
[m]
i could generate Nomad::Config when creating Common::Config though, that should cause less problems i think
George Dietrich
@Blacksmoke16
module Common::Config
  CONFIGS = {} of _ => _

  macro config(type_decl)
    {% CONFIGS[type_decl.var.id] = type_decl %}

    getter {{type_decl}}
  end

  config some_value : String
  config some_id : Int32
end

macro options_from(type, *configs)
  def initialize(
    {% for config in configs %}
      {% config = Common::Config::CONFIGS[config.id] %}
      @{{config}},
    {% end %}
    ); end
  {{debug}}
end

struct Some::Config
  options_from Common::Config, some_id, some_value
end

Some::Config.new 10, "foo" # => Some::Config(@some_id=10, @some_value="foo")
manveru
@manveru:matrix.org
[m]
just trying to reduce the number of places to change when i change options, while giving sub-commands only the minimum set of options they need for easier testing and invocation, while avoiding accidental dependencies
oh, that is kinda cool :)
didn't know => was a thing
George Dietrich
@Blacksmoke16
hm?
i will say, yes it works but im not a fan at all of this mutable concept approach
imo it still over complicates the process of just defining a constructor manually
manveru
@manveru:matrix.org
[m]
yeah
i'll try one other idea i just had though
George Dietrich
@Blacksmoke16
Mmk
manveru
@manveru:matrix.org
[m]
i think it'd be beneficial to encode the hierarchy in a single pass instead of throwing it all over the code
not sure if i'll like the result, but gotta try it anyway :)
George Dietrich
@Blacksmoke16
Fwiw, constructors are inherited
manveru
@manveru:matrix.org
[m]
yeah
George Dietrich
@Blacksmoke16
:ok_hand:
manveru
@manveru:matrix.org
[m]
atm i have for example a server that needs options [a,b,c], and it calls sub-components that require options [b] or [a,c], or [c,d] etc...
each sub-component can be called without the server, in which case you would only need to pass their specific options
so inheritance is a bit weird there...
George Dietrich
@Blacksmoke16
Are these like config values, or like unique types
manveru
@manveru:matrix.org
[m]
mostly configs
should be immutable after initial parsing
George Dietrich
@Blacksmoke16
Have you considered passing in a single config obj versus specific values?
manveru
@manveru:matrix.org
[m]
yeah
but that means i'd need to make the value types either optional, or use totally wrong default values...
George Dietrich
@Blacksmoke16
How so?
manveru
@manveru:matrix.org
[m]
or the user has to pass 50 options even if that command would only need 2 or so
George Dietrich
@Blacksmoke16
How are the values provided?
manveru
@manveru:matrix.org
[m]
either config file, cli flags, url params, default values, or env vars
George Dietrich
@Blacksmoke16
Gotcha
manveru
@manveru:matrix.org
[m]
so that pass-the-full config approach is what i had before, and it sucked :)
when you wanna run db migrations, all you need is the db url, for example
but it will fail for not finding a github token...
George Dietrich
@Blacksmoke16
You could use lazy getters maybe
manveru
@manveru:matrix.org
[m]
at that point it may fail at runtime, which also sucks
George Dietrich
@Blacksmoke16
Only would try to load when called, but would raise if not available
Or really, maybe even getter! Would be sufficient here
manveru
@manveru:matrix.org
[m]
anw, i gotta get some sleep, thanks for the feedback :)
George Dietrich
@Blacksmoke16
o/
postmodern
@postmodern:matrix.org
[m]
@didactic-drunk: should we add Process.fork to crystal-posix? @kevinsjoberg was asking about lack of Process.fork. https://gist.github.com/postmodern/a98e68dff96163b5f234cd9de1c5c75d
2 replies
mfiano
@mjfiano:matrix.org
[m]
I'm trying to solve a visibility issue.
I have private class method self.foo at the module level in one file, and in another file I have a struct defined in the same module. I would like some of the instance methods of the struct to be able to use the private foo method at the module level, but I cannot fully qualify it, and it is not part of the struct so I'm not sure if this is possible. I'm trying to write a file of private helper methods that are used in several other files/structs
mfiano
@mjfiano:matrix.org
[m]
Cancel that. I seemed to have figured out the right incantation to extend the module with private methods according to crystal doc.
From IRC (bridge bot)
@FromIRC
<kevinsjoberg> @postmodern, great idea!
George Dietrich
@Blacksmoke16
@mjfiano:matrix.org could you just make it protected