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



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

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



1940
1941
1942
# File 'lib/schema.rb', line 1940

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

Instance Method Details

#to_dynamicObject



1944
1945
1946
1947
1948
1949
1950
# File 'lib/schema.rb', line 1944

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

#to_json(options = nil) ⇒ Object



1952
1953
1954
# File 'lib/schema.rb', line 1952

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