class Spectifly::Base::Builder

Public Class Methods

from_path(path, options = {}) click to toggle source
# File lib/spectifly/base/builder.rb, line 10
def from_path(path, options = {})
  new(Spectifly::Entity.parse(path), options)
end
module_name() click to toggle source
# File lib/spectifly/base/builder.rb, line 14
def module_name
  Spectifly::Support.get_module(self)
end
new(entity, options = {}) click to toggle source
# File lib/spectifly/base/builder.rb, line 19
def initialize(entity, options = {})
  @options = options
  @entity = entity
end

Public Instance Methods

association_class() click to toggle source
# File lib/spectifly/base/builder.rb, line 93
def association_class
  eval("#{self.class.module_name}::Association")
end
associations() click to toggle source
# File lib/spectifly/base/builder.rb, line 60
def associations
  @associations ||= begin
    associations = []
    @entity.relationships.each do |relationship_type, type_associations|
      relationship_type = Spectifly::Support.tokenize(relationship_type)
      type_associations.each do |name, attributes|
        associations << association_class.new(
          name.dup, attributes.dup.merge(:relationship => relationship_type)
        )
      end
    end
    associations
  end
end
build() click to toggle source
# File lib/spectifly/base/builder.rb, line 97
def build
  raise 'Subclass Responsibility'
end
custom_types() click to toggle source
# File lib/spectifly/base/builder.rb, line 46
def custom_types
  types - native_types - utilized_extended_types.keys
end
field_class() click to toggle source
# File lib/spectifly/base/builder.rb, line 89
def field_class
  eval("#{self.class.module_name}::Field")
end
fields() click to toggle source
# File lib/spectifly/base/builder.rb, line 50
def fields
  @fields ||= begin
    fields = []
    @entity.fields.each do |name, attributes|
      fields << field_class.new(name.dup, attributes.dup)
    end
    fields
  end
end
native_types() click to toggle source
# File lib/spectifly/base/builder.rb, line 33
def native_types
  @native_types ||= begin
    eval("#{self.class.module_name}::Types::Native")
  end
end
present_as(presenter_entity) click to toggle source
# File lib/spectifly/base/builder.rb, line 24
def present_as(presenter_entity)
  @entity = @entity.present_as(presenter_entity)
  self
end
root() click to toggle source
# File lib/spectifly/base/builder.rb, line 85
def root
  @entity.root
end
types() click to toggle source
# File lib/spectifly/base/builder.rb, line 29
def types
  [fields.map(&:type) + associations.map(&:type)].flatten.compact.uniq
end
utilized_extended_type_fields() click to toggle source
# File lib/spectifly/base/builder.rb, line 75
def utilized_extended_type_fields
  @utilized_extended_type_fields ||= begin
    fields = []
    utilized_extended_types.each do |name, attributes|
      fields << field_class.new(name.dup, attributes.dup)
    end
    fields
  end
end
utilized_extended_types() click to toggle source
# File lib/spectifly/base/builder.rb, line 39
def utilized_extended_types
  @utilized_extended_types ||= begin
    extended_types = eval("#{self.class.module_name}::Types::Extended")
    extended_types.select { |k, v| types.include?(k) }
  end
end