Module: AmazingPrint::Sequel
- Included in:
- Formatter
- Defined in:
- lib/amazing_print/ext/sequel.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#awesome_sequel_dataset(dataset) ⇒ Object
Format Sequel Dataset object.
-
#awesome_sequel_document(object) ⇒ Object
Format Sequel Document object.
-
#awesome_sequel_model_class(object) ⇒ Object
Format Sequel Model class.
-
#cast_with_sequel(object, type) ⇒ Object
Add Sequel class names to the dispatcher pipeline.
Class Method Details
.included(base) ⇒ Object
10 11 12 13 |
# File 'lib/amazing_print/ext/sequel.rb', line 10 def self.included(base) base.send :alias_method, :cast_without_sequel, :cast base.send :alias_method, :cast, :cast_with_sequel end |
Instance Method Details
#awesome_sequel_dataset(dataset) ⇒ Object
Format Sequel Dataset object.
41 42 43 |
# File 'lib/amazing_print/ext/sequel.rb', line 41 def awesome_sequel_dataset(dataset) [awesome_array(dataset.to_a), amazing_print(dataset.sql)].join("\n") end |
#awesome_sequel_document(object) ⇒ Object
Format Sequel Document object.
31 32 33 34 35 36 37 |
# File 'lib/amazing_print/ext/sequel.rb', line 31 def awesome_sequel_document(object) data = object.values.sort_by(&:to_s).each_with_object({}) do |c, hash| hash[c[0].to_sym] = c[1] end data = { errors: object.errors, values: data } unless object.errors.empty? "#{object} #{awesome_hash(data)}" end |
#awesome_sequel_model_class(object) ⇒ Object
Format Sequel Model class.
47 48 49 50 51 52 53 |
# File 'lib/amazing_print/ext/sequel.rb', line 47 def awesome_sequel_model_class(object) data = object.db_schema.inject({}) { |h, (prop, defn)| h.merge(prop => defn[:db_type]) } name = "class #{awesome_simple(object.to_s, :class)}" base = "< #{awesome_simple(object.superclass.to_s, :class)}" [name, base, awesome_hash(data)].join(' ') end |
#cast_with_sequel(object, type) ⇒ Object
Add Sequel class names to the dispatcher pipeline.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/amazing_print/ext/sequel.rb', line 17 def cast_with_sequel(object, type) cast = cast_without_sequel(object, type) if defined?(::Sequel::Model) && object.is_a?(::Sequel::Model) cast = :sequel_document elsif defined?(::Sequel::Model) && object.is_a?(Class) && object.ancestors.include?(::Sequel::Model) && object&.name != 'Sequel::Model' cast = :sequel_model_class elsif defined?(::Sequel::Mysql2::Dataset) && object.class.ancestors.include?(::Sequel::Mysql2::Dataset) cast = :sequel_dataset end cast end |