class Spectifly::Base::EntityNode
Attributes
attributes[RW]
description[RW]
example[RW]
inherits_from[RW]
name[RW]
restrictions[RW]
validations[RW]
Public Class Methods
new(field_name, options = {})
click to toggle source
# File lib/spectifly/base/entity_node.rb, line 7 def initialize(field_name, options = {}) @field_name = field_name @tokens = @field_name.match(/(\W+)$/).to_s.scan(/./) @attributes = options extract_attributes extract_restrictions end
Public Instance Methods
display_type()
click to toggle source
# File lib/spectifly/base/entity_node.rb, line 42 def display_type type end
extract_attributes()
click to toggle source
# 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()
click to toggle source
# 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?()
click to toggle source
# File lib/spectifly/base/entity_node.rb, line 50 def required? @tokens.include? '*' end
type()
click to toggle source
# File lib/spectifly/base/entity_node.rb, line 38 def type Spectifly::Support.tokenize(@type) end
unique?()
click to toggle source
# File lib/spectifly/base/entity_node.rb, line 46 def unique? @restrictions['unique'] == true end