The Crystal programming language | http://crystal-lang.org | Fund Crystal's development: http://is.gd/X7PRtI | Docs: http://crystal-lang.org/docs/ | API: http://crystal-lang.org/api/
debug.cr
file that you put this stuff in
require "debug"
or whatever it's called
require "json"
require "yaml"
module Pyrite::Kubernetes
abstract class Spec
include ::JSON::Serializable
include ::YAML::Serializable
macro def_parser
macro finalized
{% if @type.abstract? %}
{% puts @type.subclasses %}
def self.new(pull : JSON::PullParser)
location = pull.location
{% begin %}
string = pull.read_raw
{% for subtype in @type.subclasses %}
begin
return {{type}}.from_json(string)
rescue JSON::ParseException
# Ignore
end
{% end %}
raise JSON::ParseException.new("Couldn't parse #{self} from #{string}", *location)
{% end %}
end
{% end %}
end
end
macro inherited
def_parser
end
def_parser
end
end
\{% puts @type.subclasses %}
❯ psykube status --cluster dev
NAME STATUS RESTARTS AGE
api-665c77fbb9-2dlk9 Running 0 23h2m
api-665c77fbb9-nwmx8 Running 0 23h1m
api-665c77fbb9-rjp6k Running 0 23h1m
def foo(&)
yield -1
end
foo do |v|
puts v.abs
end