Class: Linkage::MetaObject
- Inherits:
-
Object
- Object
- Linkage::MetaObject
- Defined in:
- lib/linkage/meta_object.rb
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
- #side ⇒ Object
Instance Method Summary collapse
-
#collation ⇒ Symbol
Returns the collation of the underlying object.
- #database_type ⇒ Object
- #dataset ⇒ Object
- #dataset=(dataset) ⇒ Object
-
#datasets_equal?(other) ⇒ Boolean
Returns true if the argument has the same dataset as the instance.
-
#initialize(object, side = nil) ⇒ MetaObject
constructor
Creates a new MetaObject.
-
#merge(other) ⇒ Linkage::MergeField
Returns a MergeField if both objects are Data objects, otherwise, raises an exception.
-
#name ⇒ Symbol?
Return the name of the object for Data objects, nil for others.
-
#objects_equal?(other) ⇒ Boolean
Returns true if the argument has the same object as the instance.
-
#raw? ⇒ Boolean
Returns true if underlying object is not a subclass of Data.
-
#ruby_type ⇒ Hash
Returns the Ruby type of the underlying object.
- #static? ⇒ Boolean
-
#to_expr ⇒ Object
Returns an expression suitable for use in Sequel queries.
-
#to_identifier ⇒ Sequel::SQL::Identifier, Object
Returns a Sequel identifier for Data objects, or the object itself.
Constructor Details
#initialize(object, side = nil) ⇒ MetaObject
Creates a new MetaObject.
15 16 17 18 19 20 21 22 |
# File 'lib/linkage/meta_object.rb', line 15 def initialize(object, side = nil) @object = object @static = object.kind_of?(Linkage::Data) ? object.static? : true if !side.nil? && side != :lhs && side != :rhs raise ArgumentError, "invalid `side` argument, must be :lhs or :rhs" end @side = side end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/linkage/meta_object.rb', line 3 def object @object end |
#side ⇒ Object
24 25 26 27 28 29 |
# File 'lib/linkage/meta_object.rb', line 24 def side if !@static && @side.nil? raise RuntimeError, "Object is dynamic and side is not set" end @side end |
Instance Method Details
#collation ⇒ Symbol
Returns the collation of the underlying object.
126 127 128 129 130 131 132 |
# File 'lib/linkage/meta_object.rb', line 126 def collation if @object.kind_of?(Linkage::Data) @object.collation else nil end end |
#database_type ⇒ Object
43 44 45 46 |
# File 'lib/linkage/meta_object.rb', line 43 def database_type ds = dataset ds ? ds.database_type : nil end |
#dataset ⇒ Object
31 32 33 |
# File 'lib/linkage/meta_object.rb', line 31 def dataset @object.kind_of?(Linkage::Data) ? @object.dataset : nil end |
#dataset=(dataset) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/linkage/meta_object.rb', line 35 def dataset=(dataset) if @object.kind_of?(Linkage::Data) @object.dataset = dataset else raise RuntimeError, "You can't set the dataset of a non-data object." end end |
#datasets_equal?(other) ⇒ Boolean
Returns true if the argument has the same dataset as the instance.
64 65 66 |
# File 'lib/linkage/meta_object.rb', line 64 def datasets_equal?(other) other.is_a?(Linkage::MetaObject) && other.dataset == self.dataset end |
#merge(other) ⇒ Linkage::MergeField
Returns a Linkage::MergeField if both objects are Data objects, otherwise, raises an exception.
102 103 104 105 106 107 108 |
# File 'lib/linkage/meta_object.rb', line 102 def merge(other) if @object.kind_of?(Linkage::Data) && other.object.kind_of?(Linkage::Data) @object.merge(other.object) else raise ArgumentError, "Cannot merge a non-data object" end end |
#name ⇒ Symbol?
Return the name of the object for Data objects, nil for others.
90 91 92 93 94 95 96 |
# File 'lib/linkage/meta_object.rb', line 90 def name if @object.kind_of?(Linkage::Data) @object.name else nil end end |
#objects_equal?(other) ⇒ Boolean
Returns true if the argument has the same object as the instance.
56 57 58 |
# File 'lib/linkage/meta_object.rb', line 56 def objects_equal?(other) other.is_a?(Linkage::MetaObject) && other.object == self.object end |
#raw? ⇒ Boolean
Returns true if underlying object is not a subclass of Data.
135 136 137 |
# File 'lib/linkage/meta_object.rb', line 135 def raw? !@object.kind_of?(Linkage::Data) end |
#ruby_type ⇒ Hash
Returns the Ruby type of the underlying object.
115 116 117 118 119 120 121 |
# File 'lib/linkage/meta_object.rb', line 115 def ruby_type if @object.kind_of?(Linkage::Data) @object.ruby_type else {:type => @object.class} end end |
#static? ⇒ Boolean
48 49 50 |
# File 'lib/linkage/meta_object.rb', line 48 def static? @static end |
#to_expr ⇒ Object
Returns an expression suitable for use in Sequel queries.
70 71 72 73 74 75 76 |
# File 'lib/linkage/meta_object.rb', line 70 def to_expr if @object.kind_of?(Linkage::Data) @object.to_expr else @object end end |
#to_identifier ⇒ Sequel::SQL::Identifier, Object
Returns a Sequel identifier for Data objects, or the object itself.
80 81 82 83 84 85 86 |
# File 'lib/linkage/meta_object.rb', line 80 def to_identifier if @object.kind_of?(Linkage::Data) Sequel::SQL::Identifier.new(@object.to_expr) else @object end end |