1
0
Fork 0
mirror of https://github.com/awesome-print/awesome_print synced 2023-03-27 23:22:34 -04:00

Colorize ORM class names

This commit is contained in:
Alexey Zapparov 2016-02-12 00:50:31 +01:00 committed by Gerard Caulfield
parent 551bb9cd30
commit 43f856ea2e
No known key found for this signature in database
GPG key ID: 623B327128A9BEC3
8 changed files with 33 additions and 13 deletions

View file

@ -1,7 +1,8 @@
## master (unreleased)
- ActiveRecord: #joins now show the columns #select'ed [@adrianomitre] - [#211]
- Handles NoMethodError for IRB implicit `ai` [@jtnegrotto] - [#212]
- Replaced Fixnum reference with Integer
- Replaced Fixnum reference with Integer
- Colorize ORM class names [@ixti]
## 1.7.0
- Refactoring by extracting formatters into their own classes [@waldyr] - [#237]
@ -148,6 +149,7 @@
[@clonezone]: https://github.com/clonezone
[@cyberdelia]: https://github.com/cyberdelia
[@gerrywastaken]: https://github.com/gerrywastaken
[@ixti]: https://github.com/ixti
[@jtnegrotto]: https://github.com/jtnegrotto
[@kemmason]: https://github.com/kemmason
[@maurogeorge]: https://github.com/maurogeorge

View file

@ -66,7 +66,11 @@ module AwesomePrint
hash[c.name.to_sym] = c.type
hash
end
"class #{object} < #{object.superclass} " << awesome_hash(data)
name = "class #{awesome_simple(object.to_s, :class)}"
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
[name, base, awesome_hash(data)].join(' ')
end
end
end

View file

@ -49,7 +49,10 @@ module AwesomePrint
end
end
"class #{object} < #{object.superclass} " << awesome_hash(data)
name = "class #{awesome_simple(object.to_s, :class)}"
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
[name, base, awesome_hash(data)].join(' ')
end
# Format MongoMapper instance object.

View file

@ -36,7 +36,11 @@ module AwesomePrint
hash[c[1].name.to_sym] = (c[1].type || 'undefined').to_s.underscore.intern
hash
end
"class #{object} < #{object.superclass} " << awesome_hash(data)
name = "class #{awesome_simple(object.to_s, :class)}"
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
[name, base, awesome_hash(data)].join(' ')
end
# Format Mongoid Document object.

View file

@ -28,10 +28,15 @@ module AwesomePrint
# Format NoBrainer class object.
#------------------------------------------------------------------------------
def awesome_nobrainer_class(object)
name = "#{awesome_simple(object, :class)} < #{awesome_simple(object.superclass, :class)}"
data = Hash[object.fields.map do |field, options|
[field, (options[:type] || Object).to_s.underscore.to_sym]
end]
"class #{object} < #{object.superclass} " << awesome_hash(data)
name = "class #{awesome_simple(object.to_s, :class)}"
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
[name, base, awesome_hash(data)].join(' ')
end
# Format NoBrainer Document object.

View file

@ -60,11 +60,10 @@ module AwesomePrint
def awesome_ripple_document_class(object)
return object.inspect if !defined?(::ActiveSupport::OrderedHash) || !object.respond_to?(:properties)
data = object.properties.inject(::ActiveSupport::OrderedHash.new) do |hash, (name, defn)|
hash[name.to_sym] = defn.type.to_s.downcase.to_sym
hash
end
"class #{object} < #{object.superclass} " << awesome_hash(data)
name = "class #{awesome_simple(object.to_s, :class)}"
base = "< #{awesome_simple(object.superclass.to_s, :class)}"
[name, base, awesome_hash(data)].join(' ')
end
end
end

View file

@ -45,8 +45,11 @@ module AwesomePrint
# Format Sequel Model class.
#------------------------------------------------------------------------------
def awesome_sequel_model_class(object)
result = object.db_schema.inject({}) { |h, (name, data)| h.merge(name => data[:db_type]) }
"class #{object} < #{object.superclass} " << awesome_hash(result)
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
end

View file

@ -63,7 +63,7 @@ module AwesomePrint
awesome_simple(o, type, @inspector)
end
def awesome_simple(o, type, inspector)
def awesome_simple(o, type, inspector = @inspector)
AwesomePrint::Formatters::SimpleFormatter.new(o, type, inspector).format
end