Class: Zuul::Context
- Inherits:
-
Struct
- Object
- Struct
- Zuul::Context
- Defined in:
- lib/zuul/context.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#id ⇒ Object
Returns the value of attribute id.
Class Method Summary collapse
Instance Method Summary collapse
- #class? ⇒ Boolean
- #instance? ⇒ Boolean (also: #object?)
- #nil? ⇒ Boolean
- #to_context ⇒ Object (also: #context)
- #type ⇒ Object
- #type_s ⇒ Object
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name
2 3 4 |
# File 'lib/zuul/context.rb', line 2 def class_name @class_name end |
#id ⇒ Object
Returns the value of attribute id
2 3 4 |
# File 'lib/zuul/context.rb', line 2 def id @id end |
Class Method Details
.parse(*args) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/zuul/context.rb', line 4 def self.parse(*args) if args.length >= 2 new(*args) elsif args[0].is_a?(self) return args[0] elsif args[0].is_a?(Class) new(args[0].name) elsif args[0].class.ancestors.include?(::ActiveRecord::Base) && args[0].respond_to?(:id) new(args[0].class.name, args[0].id) else new end end |
Instance Method Details
#class? ⇒ Boolean
23 24 25 |
# File 'lib/zuul/context.rb', line 23 def class? !class_name.nil? && id.nil? end |
#instance? ⇒ Boolean Also known as: object?
18 19 20 |
# File 'lib/zuul/context.rb', line 18 def instance? !class_name.nil? && !id.nil? end |
#nil? ⇒ Boolean
27 28 29 |
# File 'lib/zuul/context.rb', line 27 def nil? class_name.nil? && id.nil? end |
#to_context ⇒ Object Also known as: context
43 44 45 46 47 |
# File 'lib/zuul/context.rb', line 43 def to_context return nil if class_name.nil? return class_name.constantize if id.nil? class_name.constantize.find(id) end |
#type ⇒ Object
31 32 33 34 35 |
# File 'lib/zuul/context.rb', line 31 def type return :nil if class_name.nil? return :class if id.nil? :instance end |
#type_s ⇒ Object
37 38 39 40 41 |
# File 'lib/zuul/context.rb', line 37 def type_s return 'global' if class_name.nil? return class_name if id.nil? "#{class_name}(#{id})" end |