Class: LcpRuby::Metadata::EventDefinition
- Inherits:
-
Object
- Object
- LcpRuby::Metadata::EventDefinition
- Defined in:
- lib/lcp_ruby/metadata/event_definition.rb
Constant Summary collapse
- VALID_TYPES =
%w[lifecycle field_change].freeze
- LIFECYCLE_EVENTS =
%w[after_create after_update before_destroy after_destroy after_discard after_undiscard].freeze
Instance Attribute Summary collapse
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #condition_hash? ⇒ Boolean
- #condition_string? ⇒ Boolean
- #field_change? ⇒ Boolean
-
#initialize(attrs = {}) ⇒ EventDefinition
constructor
A new instance of EventDefinition.
- #lifecycle? ⇒ Boolean
Constructor Details
#initialize(attrs = {}) ⇒ EventDefinition
Returns a new instance of EventDefinition.
9 10 11 12 13 14 15 16 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 9 def initialize(attrs = {}) @name = attrs[:name].to_s @type = (attrs[:type] || infer_type).to_s @field = attrs[:field]&.to_s @condition = attrs[:condition] validate! end |
Instance Attribute Details
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
7 8 9 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 7 def condition @condition end |
#field ⇒ Object (readonly)
Returns the value of attribute field.
7 8 9 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 7 def field @field end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 7 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 7 def type @type end |
Class Method Details
.from_hash(hash) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 26 def self.from_hash(hash) new( name: hash["name"], type: hash["type"], field: hash["field"], condition: hash["condition"] ) end |
Instance Method Details
#condition_hash? ⇒ Boolean
18 19 20 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 18 def condition_hash? @condition.is_a?(Hash) end |
#condition_string? ⇒ Boolean
22 23 24 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 22 def condition_string? @condition.is_a?(String) end |
#field_change? ⇒ Boolean
39 40 41 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 39 def field_change? type == "field_change" end |
#lifecycle? ⇒ Boolean
35 36 37 |
# File 'lib/lcp_ruby/metadata/event_definition.rb', line 35 def lifecycle? type == "lifecycle" end |