Class: ROM::SQL::Association::Name
- Inherits:
-
Object
- Object
- ROM::SQL::Association::Name
- Extended by:
- Cache
- Defined in:
- lib/rom/sql/association/name.rb
Instance Attribute Summary collapse
- #key ⇒ Object (also: #to_sym) readonly
- #relation_name ⇒ Object readonly
Class Method Summary collapse
Instance Method Summary collapse
- #aliased? ⇒ Boolean
- #dataset ⇒ Object
-
#initialize(relation_name, aliaz) ⇒ Name
constructor
A new instance of Name.
- #inspect ⇒ Object (also: #to_s)
- #relation ⇒ Object
- #sql_literal_append(ds, sql) ⇒ Object
Constructor Details
#initialize(relation_name, aliaz) ⇒ Name
Returns a new instance of Name.
37 38 39 40 41 |
# File 'lib/rom/sql/association/name.rb', line 37 def initialize(relation_name, aliaz) @relation_name = relation_name @aliased = relation_name.dataset != aliaz @key = aliased? ? aliaz : relation_name.dataset end |
Instance Attribute Details
#key ⇒ Object (readonly) Also known as: to_sym
15 16 17 |
# File 'lib/rom/sql/association/name.rb', line 15 def key @key end |
#relation_name ⇒ Object (readonly)
13 14 15 |
# File 'lib/rom/sql/association/name.rb', line 13 def relation_name @relation_name end |
Class Method Details
.[](*args) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rom/sql/association/name.rb', line 19 def self.[](*args) fetch_or_store(args) do rel, ds, aliaz = args if rel.is_a?(ROM::Relation::Name) new(rel, rel.dataset) elsif rel.is_a?(self) rel elsif aliaz new(ROM::Relation::Name[rel, ds], aliaz) elsif ds.nil? new(ROM::Relation::Name[rel], rel) else new(ROM::Relation::Name[rel, ds], ds) end end end |
Instance Method Details
#aliased? ⇒ Boolean
43 44 45 |
# File 'lib/rom/sql/association/name.rb', line 43 def aliased? @aliased end |
#dataset ⇒ Object
56 57 58 |
# File 'lib/rom/sql/association/name.rb', line 56 def dataset relation_name.dataset end |
#inspect ⇒ Object Also known as: to_s
47 48 49 50 51 52 53 |
# File 'lib/rom/sql/association/name.rb', line 47 def inspect if aliased? "#{self.class}(#{relation_name.to_s} as #{key})" else "#{self.class}(#{relation_name.to_s})" end end |
#relation ⇒ Object
60 61 62 |
# File 'lib/rom/sql/association/name.rb', line 60 def relation relation_name.relation end |
#sql_literal_append(ds, sql) ⇒ Object
64 65 66 |
# File 'lib/rom/sql/association/name.rb', line 64 def sql_literal_append(ds, sql) ds.literal_append(sql, dataset) end |