Class: Bparity::Adapter::Definition
- Inherits:
-
Object
- Object
- Bparity::Adapter::Definition
- Defined in:
- lib/bparity/adapter.rb
Instance Attribute Summary collapse
-
#externals ⇒ Object
readonly
Returns the value of attribute externals.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
-
#subjects ⇒ Object
readonly
Returns the value of attribute subjects.
-
#waivers ⇒ Object
readonly
Returns the value of attribute waivers.
Instance Method Summary collapse
- #external(mapping, &block) ⇒ Object
-
#initialize(spec: nil) ⇒ Definition
constructor
A new instance of Definition.
- #subject(name, &block) ⇒ Object
- #waive(id, reason:, approved_by:, approved_at:) ⇒ Object
Constructor Details
#initialize(spec: nil) ⇒ Definition
Returns a new instance of Definition.
77 78 79 80 81 82 |
# File 'lib/bparity/adapter.rb', line 77 def initialize(spec: nil) @spec = spec @subjects = {} @waivers = {} @externals = [] end |
Instance Attribute Details
#externals ⇒ Object (readonly)
Returns the value of attribute externals.
75 76 77 |
# File 'lib/bparity/adapter.rb', line 75 def externals @externals end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
75 76 77 |
# File 'lib/bparity/adapter.rb', line 75 def spec @spec end |
#subjects ⇒ Object (readonly)
Returns the value of attribute subjects.
75 76 77 |
# File 'lib/bparity/adapter.rb', line 75 def subjects @subjects end |
#waivers ⇒ Object (readonly)
Returns the value of attribute waivers.
75 76 77 |
# File 'lib/bparity/adapter.rb', line 75 def waivers @waivers end |
Instance Method Details
#external(mapping, &block) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/bparity/adapter.rb', line 107 def external(mapping, &block) source, target = mapping.first item = External.new(source, target) item.instance_eval(&block) if block externals << item end |
#subject(name, &block) ⇒ Object
84 85 86 87 88 |
# File 'lib/bparity/adapter.rb', line 84 def subject(name, &block) item = Subject.new(name) item.instance_eval(&block) if block subjects[name] = item end |
#waive(id, reason:, approved_by:, approved_at:) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/bparity/adapter.rb', line 90 def waive(id, reason:, approved_by:, approved_at:) values = { "id" => id, "reason" => reason, "approved_by" => approved_by, "approved_at" => approved_at } missing = values.filter_map { |name, value| name if value.to_s.strip.empty? } unless missing.empty? raise ConfigurationError, "Waiver metadata is missing #{missing.join(', ')}. Add an ID, reason, approver, and approval date." end begin Date.iso8601(approved_at.to_s) rescue Date::Error raise ConfigurationError, "Waiver #{id} has an invalid approval date. Use YYYY-MM-DD." end waivers[id] = Waiver.new(id:, reason:, approved_by:, approved_at:) end |