Class: MutationGenerator::GeneratedAttribute
- Inherits:
-
Object
- Object
- MutationGenerator::GeneratedAttribute
- Defined in:
- lib/generators/mutation/mutation_generator.rb
Constant Summary collapse
- FILTER_OPTIONS =
%w[string integer model hash array boolean date duck input symbol time].freeze
- INPUT_OPTIONS =
%w[required optional].freeze
Instance Attribute Summary collapse
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#input_type ⇒ Object
Returns the value of attribute input_type.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
- .parse(definition) ⇒ Object
- .validate_filter!(filter) ⇒ Object
- .validate_input_type!(input_type) ⇒ Object
Instance Method Summary collapse
-
#initialize(name, filter, input_type) ⇒ GeneratedAttribute
constructor
A new instance of GeneratedAttribute.
Constructor Details
#initialize(name, filter, input_type) ⇒ GeneratedAttribute
Returns a new instance of GeneratedAttribute.
74 75 76 77 78 |
# File 'lib/generators/mutation/mutation_generator.rb', line 74 def initialize(name, filter, input_type) @name = name @filter = filter || 'string' @input_type = input_type || 'required' end |
Instance Attribute Details
#filter ⇒ Object
Returns the value of attribute filter.
40 41 42 |
# File 'lib/generators/mutation/mutation_generator.rb', line 40 def filter @filter end |
#input_type ⇒ Object
Returns the value of attribute input_type.
40 41 42 |
# File 'lib/generators/mutation/mutation_generator.rb', line 40 def input_type @input_type end |
#name ⇒ Object
Returns the value of attribute name.
40 41 42 |
# File 'lib/generators/mutation/mutation_generator.rb', line 40 def name @name end |
Class Method Details
.parse(definition) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/generators/mutation/mutation_generator.rb', line 43 def parse(definition) name, filter, input_type = definition.split(':') raise 'name required' if name.nil? raise 'filter type required' if filter.nil? input_type ||= 'required' filter = validate_filter!(filter) input_type = validate_input_type!(input_type) name = name.to_sym new(name, filter, input_type) end |
.validate_filter!(filter) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/generators/mutation/mutation_generator.rb', line 65 def validate_filter!(filter) unless FILTER_OPTIONS.include?(filter) raise "invalid filter type must be one of #{FILTER_OPTIONS}" end filter end |
.validate_input_type!(input_type) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/generators/mutation/mutation_generator.rb', line 57 def validate_input_type!(input_type) unless INPUT_OPTIONS.include?(input_type) raise "invalid input type must be one of #{INPUT_OPTIONS}" end input_type end |