Class: Syphon::Schema
- Inherits:
-
Object
- Object
- Syphon::Schema
- Defined in:
- lib/syphon/schema.rb
Defined Under Namespace
Classes: DSL, Field, NestedField
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#group_clause ⇒ Object
Returns the value of attribute group_clause.
-
#having_clause ⇒ Object
Returns the value of attribute having_clause.
-
#joins ⇒ Object
readonly
Returns the value of attribute joins.
-
#relation ⇒ Object
Returns the value of attribute relation.
Instance Method Summary collapse
- #configure(&block) ⇒ Object
-
#initialize(&block) ⇒ Schema
constructor
A new instance of Schema.
- #properties ⇒ Object
- #query(options = {}) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Schema
Returns a new instance of Schema.
3 4 5 6 7 8 9 10 11 |
# File 'lib/syphon/schema.rb', line 3 def initialize(&block) @fields = {} @relation = nil @joins = [] @conditions = nil @group_clause = nil @having_clause = nil configure(&block) if block end |
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions.
14 15 16 |
# File 'lib/syphon/schema.rb', line 14 def conditions @conditions end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
13 14 15 |
# File 'lib/syphon/schema.rb', line 13 def fields @fields end |
#group_clause ⇒ Object
Returns the value of attribute group_clause.
14 15 16 |
# File 'lib/syphon/schema.rb', line 14 def group_clause @group_clause end |
#having_clause ⇒ Object
Returns the value of attribute having_clause.
14 15 16 |
# File 'lib/syphon/schema.rb', line 14 def having_clause @having_clause end |
#joins ⇒ Object (readonly)
Returns the value of attribute joins.
13 14 15 |
# File 'lib/syphon/schema.rb', line 13 def joins @joins end |
#relation ⇒ Object
Returns the value of attribute relation.
14 15 16 |
# File 'lib/syphon/schema.rb', line 14 def relation @relation end |
Instance Method Details
#configure(&block) ⇒ Object
16 17 18 |
# File 'lib/syphon/schema.rb', line 16 def configure(&block) DSL.new(self)._eval(&block) end |
#properties ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/syphon/schema.rb', line 41 def properties mapping = {} fields.each do |name, field| mapping[name] = field.properties end mapping end |
#query(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/syphon/schema.rb', line 20 def query( = {}) order = [:order] and order_by_fragment = "ORDER BY #{query_fragment(order)}" limit = [:limit] and limit_fragment = "LIMIT #{query_fragment(limit)}" select_fragment = [:select] || select_fragments where_fragment = where_fragment(.slice(:scope, :invert)) <<-EOS.strip.gsub(/\s+/, ' ') SELECT #{select_fragment} FROM #{query_fragment(relation)} #{joins_fragment} #{where_fragment} #{group_by_fragment} #{having_fragment} #{order_by_fragment} #{limit_fragment} EOS end |