Class: Slack6

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/schema.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_dynamic!(d) ⇒ Object



1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
# File 'lib/schema.rb', line 1931

def self.from_dynamic!(d)
  begin
    value = Slack3.from_dynamic!(d)
    return new(slack3: value, string: nil) if schema[:slack3].right.valid? value
  rescue StandardError
  end
  return new(string: d, slack3: nil) if schema[:string].right.valid? d

  raise "Invalid union"
end

.from_json!(json) ⇒ Object



1942
1943
1944
# File 'lib/schema.rb', line 1942

def self.from_json!(json)
  from_dynamic!(JSON.parse(json))
end

Instance Method Details

#to_dynamicObject



1946
1947
1948
1949
1950
1951
1952
# File 'lib/schema.rb', line 1946

def to_dynamic
  if !slack3.nil?
    slack3.to_dynamic
  elsif !string.nil?
    string
  end
end

#to_json(options = nil) ⇒ Object



1954
1955
1956
# File 'lib/schema.rb', line 1954

def to_json(options = nil)
  JSON.generate(to_dynamic, options)
end