Class: Spectifly::Base::EntityNode
- Inherits:
-
Object
- Object
- Spectifly::Base::EntityNode
- Defined in:
- lib/spectifly/base/entity_node.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#description ⇒ Object
Returns the value of attribute description.
-
#example ⇒ Object
Returns the value of attribute example.
-
#inherits_from ⇒ Object
Returns the value of attribute inherits_from.
-
#name ⇒ Object
Returns the value of attribute name.
-
#restrictions ⇒ Object
Returns the value of attribute restrictions.
-
#validations ⇒ Object
Returns the value of attribute validations.
Instance Method Summary collapse
- #display_type ⇒ Object
- #extract_attributes ⇒ Object
- #extract_restrictions ⇒ Object
-
#initialize(field_name, options = {}) ⇒ EntityNode
constructor
A new instance of EntityNode.
- #required? ⇒ Boolean
- #type ⇒ Object
- #unique? ⇒ Boolean
Constructor Details
#initialize(field_name, options = {}) ⇒ EntityNode
Returns a new instance of EntityNode.
7 8 9 10 11 12 13 |
# File 'lib/spectifly/base/entity_node.rb', line 7 def initialize(field_name, = {}) @field_name = field_name @tokens = @field_name.match(/(\W+)$/).to_s.scan(/./) @attributes = extract_attributes extract_restrictions end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/spectifly/base/entity_node.rb', line 4 def attributes @attributes end |
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/spectifly/base/entity_node.rb', line 4 def description @description end |
#example ⇒ Object
Returns the value of attribute example.
4 5 6 |
# File 'lib/spectifly/base/entity_node.rb', line 4 def example @example end |
#inherits_from ⇒ Object
Returns the value of attribute inherits_from.
4 5 6 |
# File 'lib/spectifly/base/entity_node.rb', line 4 def inherits_from @inherits_from end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/spectifly/base/entity_node.rb', line 4 def name @name end |
#restrictions ⇒ Object
Returns the value of attribute restrictions.
4 5 6 |
# File 'lib/spectifly/base/entity_node.rb', line 4 def restrictions @restrictions end |
#validations ⇒ Object
Returns the value of attribute validations.
4 5 6 |
# File 'lib/spectifly/base/entity_node.rb', line 4 def validations @validations end |
Instance Method Details
#display_type ⇒ Object
42 43 44 |
# File 'lib/spectifly/base/entity_node.rb', line 42 def display_type type end |
#extract_attributes ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/spectifly/base/entity_node.rb', line 15 def extract_attributes @description = @attributes.delete('Description') @example = @attributes.delete('Example') @type = @attributes.delete('Type') @inherits_from = @attributes.delete('Inherits From') @validations = [@attributes.delete('Validations')].compact.flatten end |
#extract_restrictions ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/spectifly/base/entity_node.rb', line 23 def extract_restrictions @restrictions = {} unique_validation = @validations.reject! { |v| v =~ /must be unique/i } unique_attribute = @attributes.delete("Unique") if (unique_validation && unique_attribute.nil?) ^ (unique_attribute.to_s == "true") @restrictions['unique'] = true elsif unique_validation && !["true", ""].include?(unique_attribute.to_s) raise "Field/association #{name} has contradictory information about uniqueness." end end |
#required? ⇒ Boolean
50 51 52 |
# File 'lib/spectifly/base/entity_node.rb', line 50 def required? @tokens.include? '*' end |
#type ⇒ Object
38 39 40 |
# File 'lib/spectifly/base/entity_node.rb', line 38 def type Spectifly::Support.tokenize(@type) end |
#unique? ⇒ Boolean
46 47 48 |
# File 'lib/spectifly/base/entity_node.rb', line 46 def unique? @restrictions['unique'] == true end |