Class: BuildNotify1

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



168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/schema.rb', line 168

def self.from_dynamic!(d)
  d = Types::Hash[d]
  new(
    email: d["email"],
    build_notify_if: d["if"],
    basecamp_campfire: d["basecamp_campfire"],
    slack: d["slack"] ? Slack4.from_dynamic!(d["slack"]) : nil,
    webhook: d["webhook"],
    pagerduty_change_event: d["pagerduty_change_event"],
    github_commit_status: d["github_commit_status"] ? GithubCommitStatus1.from_dynamic!(d["github_commit_status"]) : nil,
    github_check: Types::Hash.optional[d["github_check"]]&.transform_values { |v| Types::Any[v] }
  )
end

.from_json!(json) ⇒ Object



182
183
184
# File 'lib/schema.rb', line 182

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

Instance Method Details

#to_dynamicObject



186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/schema.rb', line 186

def to_dynamic
  {
    "email" => email,
    "if" => build_notify_if,
    "basecamp_campfire" => basecamp_campfire,
    "slack" => slack&.to_dynamic,
    "webhook" => webhook,
    "pagerduty_change_event" => pagerduty_change_event,
    "github_commit_status" => github_commit_status&.to_dynamic,
    "github_check" => github_check
  }
end

#to_json(options = nil) ⇒ Object



199
200
201
# File 'lib/schema.rb', line 199

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