Module: Arcade::Support::Hash
- Included in:
- Hash
- Defined in:
- lib/arcade/support/conversions.rb
Instance Method Summary collapse
- #allocate_model(autoload = Config.autoload) ⇒ Object
- #from_db ⇒ Object
-
#to_db ⇒ Object
converts :abc => anything to “abc” => anything.
- #to_human ⇒ Object
-
#to_or ⇒ Object
converts a hash to a string appropiate to include in raw queries.
Instance Method Details
#allocate_model(autoload = Config.autoload) ⇒ Object
225 226 227 |
# File 'lib/arcade/support/conversions.rb', line 225 def allocate_model( autoload = Config.autoload ) _allocate_model( self , autoload ) end |
#from_db ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/arcade/support/conversions.rb', line 205 def from_db # populate the hash by converting keys: stings to symbols, values: preprocess through :from_db map do |k,v| orient_k = if k.to_s.to_i.to_s == k.to_s k.to_i else k.to_sym end [orient_k, v.from_db] end.to_h end |
#to_db ⇒ Object
converts :abc => anything to “abc” => anything
converts nn => anything to nn => anything
leaves “abc” => anything untouched
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/arcade/support/conversions.rb', line 191 def to_db # converts hast from activeorient to db map do | k, v| orient_k = case k when Numeric k when Symbol, String k.to_s else raise "not supported key: #{k} -- must a sting, symbol or number" end [orient_k, v.to_db] end.to_h end |
#to_human ⇒ Object
218 219 220 221 222 223 |
# File 'lib/arcade/support/conversions.rb', line 218 def to_human "< " + map do | k,v | vv = v.is_a?( Arcade::Base ) ? v.to_human[1..-2] : v.to_s k.to_s + ": " + vv end.join( "\n " ) + " >" end |
#to_or ⇒ Object
converts a hash to a string appropiate to include in raw queries
232 233 234 |
# File 'lib/arcade/support/conversions.rb', line 232 def to_or "{ " + to_db.map{|k,v| "#{k.to_or}: #{v.to_or}"}.join(',') + "}" end |