Class: Syphon::Schema::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/syphon/schema.rb

Direct Known Subclasses

NestedField

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, name, type, expression, options = {}) ⇒ Field

Returns a new instance of Field.



87
88
89
90
91
92
93
94
# File 'lib/syphon/schema.rb', line 87

def initialize(schema, name, type, expression, options = {})
  @schema = schema
  @name = name.to_sym
  @type = type
  @expression = expression
  @properties = options.merge(type: type)
  @multi = options[:multi]
end

Instance Attribute Details

#expressionObject (readonly)

Returns the value of attribute expression.



96
97
98
# File 'lib/syphon/schema.rb', line 96

def expression
  @expression
end

#nameObject (readonly)

Returns the value of attribute name.



96
97
98
# File 'lib/syphon/schema.rb', line 96

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



96
97
98
# File 'lib/syphon/schema.rb', line 96

def properties
  @properties
end

#schemaObject (readonly)

Returns the value of attribute schema.



96
97
98
# File 'lib/syphon/schema.rb', line 96

def schema
  @schema
end

#typeObject (readonly)

Returns the value of attribute type.



96
97
98
# File 'lib/syphon/schema.rb', line 96

def type
  @type
end

Instance Method Details

#multi?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/syphon/schema.rb', line 98

def multi?
  @multi
end

#select(outer = nil) ⇒ Object



102
103
104
105
# File 'lib/syphon/schema.rb', line 102

def select(outer = nil)
  name = outer ? "#{outer}[#{self.name}]" : self.name
  "#{schema.send(:query_fragment, expression)} AS `#{name}`"
end