Class: CommaHeaven::Sqler::Columns
- Inherits:
-
Array
- Object
- Array
- CommaHeaven::Sqler::Columns
- Defined in:
- lib/comma-heaven/sqler/columns.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#model ⇒ Object
Returns the value of attribute model.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
-
#initialize(model, export, options = {}) ⇒ Columns
constructor
A new instance of Columns.
- #join_clause ⇒ Object
- #joins ⇒ Object
- #prefix ⇒ Object
- #select ⇒ Object
- #sql_as ⇒ Object
- #table ⇒ Object
- #table_alias(method = :pluralize) ⇒ Object
Constructor Details
#initialize(model, export, options = {}) ⇒ Columns
Returns a new instance of Columns.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/comma-heaven/sqler/columns.rb', line 6 def initialize(model, export, = {}) @model = model @export = export @options = # Fill the array fill! # Sort by position # sort! { |a, b| a.position <=> b.position } end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
4 5 6 |
# File 'lib/comma-heaven/sqler/columns.rb', line 4 def index @index end |
#model ⇒ Object
Returns the value of attribute model.
4 5 6 |
# File 'lib/comma-heaven/sqler/columns.rb', line 4 def model @model end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/comma-heaven/sqler/columns.rb', line 4 def @options end |
#parent ⇒ Object
Returns the value of attribute parent.
4 5 6 |
# File 'lib/comma-heaven/sqler/columns.rb', line 4 def parent @parent end |
Instance Method Details
#join_clause ⇒ Object
49 50 51 |
# File 'lib/comma-heaven/sqler/columns.rb', line 49 def join_clause return '' end |
#joins ⇒ Object
22 23 24 |
# File 'lib/comma-heaven/sqler/columns.rb', line 22 def joins map(&:joins).compact.uniq.join(" ").gsub(/\n/, '').squeeze(' ') end |
#prefix ⇒ Object
45 46 47 |
# File 'lib/comma-heaven/sqler/columns.rb', line 45 def prefix return '' end |
#select ⇒ Object
18 19 20 |
# File 'lib/comma-heaven/sqler/columns.rb', line 18 def select map(&:select).reject { |e| e.empty? }.join(', ') end |
#sql_as ⇒ Object
26 27 28 |
# File 'lib/comma-heaven/sqler/columns.rb', line 26 def sql_as map(&:sql_as).flatten end |
#table ⇒ Object
30 31 32 |
# File 'lib/comma-heaven/sqler/columns.rb', line 30 def table model.table_name end |
#table_alias(method = :pluralize) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/comma-heaven/sqler/columns.rb', line 34 def table_alias(method = :pluralize) t = case method when :pluralize model.table_name else model.name.underscore end return prefix + [((parent && parent.parent) ? parent.table_alias(method) : nil), t, index].compact.join('_') end |