Class: ActiveRecord::View::Introspection::Abstract Abstract Private

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks
Defined in:
lib/activerecord/view/introspection/abstract.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class is abstract.

Direct Known Subclasses

MySQL, Postgres, SQLite3

Instance Method Summary collapse

Instance Method Details

#arel_cast(value, type, quote_value: true, literalize_type: true) ⇒ Arel::Nodes::NamedFunction("CAST", [Arel::Nodes::As(Arel::Nodes::Quoted, Arel::Nodes::SqlLiteral)])

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build a SQL-compliant cast statement

Parameters:

  • value (String, Arel::Nodes::Quoted)
  • type (String, Arel::Nodes::SqlLiteral)

Returns:

  • (Arel::Nodes::NamedFunction("CAST", [Arel::Nodes::As(Arel::Nodes::Quoted, Arel::Nodes::SqlLiteral)]))


69
70
71
72
73
74
75
76
# File 'lib/activerecord/view/introspection/abstract.rb', line 69

def arel_cast(value, type, quote_value: true, literalize_type: true)
  value = arel_quoted(value)  if quote_value
  type  = Arel.sql(type)      if literalize_type

  as_expr = Arel::Nodes::As.new value, type

  arel_fn 'CAST', as_expr
end

#arel_fn(name, *args) ⇒ Arel::Nodes::NamedFunction

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build an Arel function

Returns:

  • (Arel::Nodes::NamedFunction)


81
82
83
# File 'lib/activerecord/view/introspection/abstract.rb', line 81

def arel_fn(name, *args)
  Arel::Nodes::NamedFunction.new(name, args)
end

#arel_quoted(value) ⇒ Arel::Nodes::Quoted

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Build a quoted string

Returns:

  • (Arel::Nodes::Quoted)


88
89
90
# File 'lib/activerecord/view/introspection/abstract.rb', line 88

def arel_quoted(value)
  arel_quoted?(value) ? value : Arel::Nodes.build_quoted(value)
end

#arel_quoted?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


92
93
94
# File 'lib/activerecord/view/introspection/abstract.rb', line 92

def arel_quoted?(value)
  value.kind_of? Arel::Nodes::Quoted
end

#default_connectionActiveRecord::ConnectionAdapters::AbstractAdapter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (ActiveRecord::ConnectionAdapters::AbstractAdapter)


98
99
100
101
102
# File 'lib/activerecord/view/introspection/abstract.rb', line 98

def default_connection
  # :nocov:
  ActiveRecord::Base.connection
  # :nocov:
end

#definition_for(view_name, **options) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • view_name (String)
  • options (Hash)

Options Hash (**options):

  • :pretty (Boolean)

    whether the SQL definition should be pretty-printed. Only works in postgres.

Returns:

  • (String)


27
28
29
30
31
32
33
34
35
# File 'lib/activerecord/view/introspection/abstract.rb', line 27

def definition_for(view_name, **options)
  run_callbacks :fetch_view_definition do
    result = select_value fetch_view_definition_query(view_name, **options)

    process_view_definition(result).tap do |processed|
      raise ActiveRecord::View::Error, 'Empty Definition' if raise_error? && processed.blank?
    end
  end
end

#fetch_view_definition_query(view_name, **options) ⇒ Arel::SelectManager

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is abstract.

Parameters:

  • view_name (String)

Returns:

  • (Arel::SelectManager)

Raises:

  • (NotImplementedError)


52
53
54
55
56
# File 'lib/activerecord/view/introspection/abstract.rb', line 52

def fetch_view_definition_query(view_name, **options)
  # :nocov:
  raise NotImplementedError, "Must implement for #{self.class}"
  # :nocov:
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



58
59
60
61
62
# File 'lib/activerecord/view/introspection/abstract.rb', line 58

def inspect
  # :nocov:
  "<#{self.class.name}(:raise_error => #{raise_error?})>"
  # :nocov:
end

#process_view_definition(result) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • (String)

Returns:

  • (String)


44
45
46
# File 'lib/activerecord/view/introspection/abstract.rb', line 44

def process_view_definition(result)
  result
end

#select_managerArel::SelectManager

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Arel::SelectManager)


38
39
40
# File 'lib/activerecord/view/introspection/abstract.rb', line 38

def select_manager
  Arel::SelectManager.new self
end

#views<ActiveRecord::View::Introspection::ViewDefinition>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method is abstract.


20
21
# File 'lib/activerecord/view/introspection/abstract.rb', line 20

def views
end