Class: LazyRecords::Definition

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, *columns) ⇒ Definition

Returns a new instance of Definition.



11
12
13
14
15
16
17
# File 'lib/definition.rb', line 11

def initialize(name, *columns)
  @name = name
  @columns = columns
  @client = none
  @add_exclusions = none
  @show_sql = false
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



9
10
11
# File 'lib/definition.rb', line 9

def columns
  @columns
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/definition.rb', line 9

def name
  @name
end

Instance Method Details

#add_exclusionsObject



27
28
29
# File 'lib/definition.rb', line 27

def add_exclusions
  option(@add_exclusions)
end

#add_exclusions=(*values) ⇒ Object



23
24
25
# File 'lib/definition.rb', line 23

def add_exclusions=(*values)
  @add_exclusions = sequence(values.flatten)
end

#columns_as_listObject



19
20
21
# File 'lib/definition.rb', line 19

def columns_as_list
  columns.first.map(&:name)
end

#suggest_keywords(connection) ⇒ Object



31
32
33
34
35
36
# File 'lib/definition.rb', line 31

def suggest_keywords(connection)
  fields = connection.fields(@name)
  keywords = fields.map { |field| "#{field} = keyword(:#{field})" }.join("\n")
  puts keywords
  puts "#{@name} = definition(:#{@name}, #{fields.join(', ')})"
end