Class: Momomoto::Base
- Inherits:
-
Object
- Object
- Momomoto::Base
- Defined in:
- lib/momomoto/base.rb
Overview
Momomoto base class for Table and Procedure
Class Method Summary collapse
- .initialize ⇒ Object
-
.logical_operator=(value) ⇒ Object
Set the default logical operator for constraints.
- .momomoto_attribute(name) ⇒ Object
- .momomoto_attribute_reader(name) ⇒ Object
Class Method Details
.initialize ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/momomoto/base.rb', line 125 def initialize return if initialized @schema_name ||= construct_schema_name( self.name ) @logical_operator ||= 'AND' self.initialized = true end |
.logical_operator=(value) ⇒ Object
Set the default logical operator for constraints. AND and OR are supported. See Table#select for usage of logical operators.
150 151 152 153 154 155 156 |
# File 'lib/momomoto/base.rb', line 150 def logical_operator=( value ) @logical_operator = case value when /and/i then "AND" when /or/i then "OR" else raise Momomoto::Error, "Unsupported logical operator" end end |
.momomoto_attribute(name) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/momomoto/base.rb', line 106 def momomoto_attribute( name ) singleton = self.instance_eval{class << self; self; end} varname = "@#{name}" settername = "#{name}=" # define getter method singleton.send(:define_method, name) do | *values | if values[0] send( settername, values[0] ) else initialize if not initialized instance_variable_get( varname ) end end # define setter method singleton.send(:define_method, settername) do | value | instance_variable_set( varname, value ) end end |
.momomoto_attribute_reader(name) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/momomoto/base.rb', line 96 def momomoto_attribute_reader( name ) singleton = self.instance_eval{class << self; self; end} varname = "@#{name}" # define getter method singleton.send(:define_method, name) do | *values | initialize if not initialized instance_variable_get( varname ) end end |