Class: WorkflowTemplate::Action::Description::Validated
- Inherits:
-
Object
- Object
- WorkflowTemplate::Action::Description::Validated
- Defined in:
- lib/workflow_template/action/description/validated.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
Class Method Summary collapse
- .describe(action) ⇒ Object
- .describe_defaults(action) ⇒ Object
- .describe_state_transition_strategy(action) ⇒ Object
- .describe_validations(action) ⇒ Object
- .instance(action) ⇒ Object
Instance Method Summary collapse
- #format(level:) ⇒ Object
-
#initialize(action) ⇒ Validated
constructor
A new instance of Validated.
Constructor Details
#initialize(action) ⇒ Validated
Returns a new instance of Validated.
15 16 17 18 |
# File 'lib/workflow_template/action/description/validated.rb', line 15 def initialize(action) @action = action freeze end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
13 14 15 |
# File 'lib/workflow_template/action/description/validated.rb', line 13 def action @action end |
Class Method Details
.describe(action) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/workflow_template/action/description/validated.rb', line 24 def self.describe(action) extras = [ describe_defaults(action), describe_validations(action), describe_state_transition_strategy(action) ].compact return action.name if extras.empty? "#{action.name} #{extras.join(', ')}" end |
.describe_defaults(action) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/workflow_template/action/description/validated.rb', line 35 def self.describe_defaults(action) hash = action.defaults return if hash.nil? || hash.empty? "defaults: { #{hash.map { |key, value| "#{key}: #{value}" }.join(', ')} }" end |
.describe_state_transition_strategy(action) ⇒ Object
50 51 52 53 54 |
# File 'lib/workflow_template/action/description/validated.rb', line 50 def self.describe_state_transition_strategy(action) return if action.state_transition_strategy.nil? "state: #{action.state_transition_strategy}" end |
.describe_validations(action) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/workflow_template/action/description/validated.rb', line 42 def self.describe_validations(action) case action.validates when nil then nil when Array then "validates: #{action.validates.join(', ')}" unless action.validates.empty? else "validates: #{action.validates}" end end |
.instance(action) ⇒ Object
7 8 9 |
# File 'lib/workflow_template/action/description/validated.rb', line 7 def self.instance(action) new action end |
Instance Method Details
#format(level:) ⇒ Object
20 21 22 |
# File 'lib/workflow_template/action/description/validated.rb', line 20 def format(level:) ["#{' ' * level}#{self.class.describe(action)}"] end |