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
- #<=(kontext) ⇒ Object
- #==(kontext) ⇒ Object
- #>=(kontext) ⇒ Object
- #class? ⇒ Boolean
- #global? ⇒ Boolean (also: #nil?)
- #instance? ⇒ Boolean (also: #object?)
- #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
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/zuul/context.rb', line 5 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
#<=(kontext) ⇒ Object
37 38 39 |
# File 'lib/zuul/context.rb', line 37 def <=(kontext) kontext.global? || (class_name == kontext.class_name && (kontext.id.nil? || id == kontext.id)) end |
#==(kontext) ⇒ Object
33 34 35 |
# File 'lib/zuul/context.rb', line 33 def ==(kontext) class_name == kontext.class_name && id == kontext.id end |
#>=(kontext) ⇒ Object
41 42 43 |
# File 'lib/zuul/context.rb', line 41 def >=(kontext) kontext <= self end |
#class? ⇒ Boolean
24 25 26 |
# File 'lib/zuul/context.rb', line 24 def class? !class_name.nil? && id.nil? end |
#global? ⇒ Boolean Also known as: nil?
28 29 30 |
# File 'lib/zuul/context.rb', line 28 def global? class_name.nil? && id.nil? end |
#instance? ⇒ Boolean Also known as: object?
19 20 21 |
# File 'lib/zuul/context.rb', line 19 def instance? !class_name.nil? && !id.nil? end |
#to_context ⇒ Object Also known as: context
57 58 59 60 61 |
# File 'lib/zuul/context.rb', line 57 def to_context return nil if class_name.nil? return class_name.constantize if id.nil? class_name.constantize.find(id) end |
#type ⇒ Object
45 46 47 48 49 |
# File 'lib/zuul/context.rb', line 45 def type return :nil if class_name.nil? return :class if id.nil? :instance end |
#type_s ⇒ Object
51 52 53 54 55 |
# File 'lib/zuul/context.rb', line 51 def type_s return 'global' if class_name.nil? return class_name if id.nil? "#{class_name}(#{id})" end |