These are chat archives for Codcore/amethyst

1st
Jul 2015
Bar Hofesh
@bararchy
Jul 01 2015 11:26
@Codcore can you explain to me what does this macro suppose to do ?
  macro create_send
    case method
      {% methods = @type.methods %}
      {% for m in methods %}
      {% args = m.args %}
    when "{{m.name.id}}"
      raise WrongNumberOfArguments.new({{m.name.stringify}}, args.length, {{m.args.length}}) unless args.length == {{m.args.length}}
      {{m.name.id}}{% unless args.empty? %}(
      {% for arg in args %}{{arg.id}}=args[:{{arg.id}}],{% end %}){% end %}
      {% end %}
    else
      raise WrongInstanceMethod.new({{@type.name.stringify}}, "#{method}")
    end
  end
Andrej Yaroshuk
@Codcore
Jul 01 2015 13:25
@bararchy this macro iterates through object methods and creates case ... when instruction.So in send
method created code can be triggered with method name, and execute method passed as string to send method
If method has arguments it checks whether arguments where passed to send method, and also checks number of arguments. If all is OK, it call object method with passed arguments
Andrej Yaroshuk
@Codcore
Jul 01 2015 13:31
Understand? I'm on my way home, so soon I will be at the computer and will be coding :smile:
Bar Hofesh
@bararchy
Jul 01 2015 13:44
@Codcore I think I got it, I don't have any expirenace with macros so I wanted to see if I can figure out what it does, Thanks for the explanation :)
Andrej Yaroshuk
@Codcore
Jul 01 2015 13:45
@bararchy you can add strin {{debug()}} inside a macros to see what code it creates
@bararchy I'm already at home, so I will fix this macro rught now. Question is why you got an error.
@bararchy can you show your controller code that creates this error?
Bar Hofesh
@bararchy
Jul 01 2015 13:48
it says:
macro didn't expand to a valid program, it expanded to:

================================================================================
--------------------------------------------------------------------------------
  1.     case method
  2.       
  3.       
  4.     else
  5.       raise WrongInstanceMethod.new("Amethyst::Base::Controller+", "#{method}")
  6.     end
  7.   
--------------------------------------------------------------------------------
Syntax error in expanded macro: create_send:4: unexpected token: else (expecting when)

    else
    ^

================================================================================

    create_send
in compile time
@Codcore do you need to see my controller code for this ?
Andrej Yaroshuk
@Codcore
Jul 01 2015 13:51
@bararchy yes, i'd like to see it
Bar Hofesh
@bararchy
Jul 01 2015 21:24
@Codcore congratz on new version !!
I'll take all day to test everything