Class: Exposant::Base
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Exposant::Base
show all
- Extended by:
- ActiveModel::Naming
- Includes:
- Contextualizable
- Defined in:
- lib/exposant/base.rb
Instance Attribute Summary
#context
Class Method Summary
collapse
Instance Method Summary
collapse
#contextualize, #contextualized?
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
6
7
8
9
10
|
# File 'lib/exposant/base.rb', line 6
def initialize(*)
super
extend(Exposant::Collection) if __getobj__.is_a?(Enumerable)
end
|
Class Method Details
.belongs_to_model(name) ⇒ Object
32
33
34
|
# File 'lib/exposant/base.rb', line 32
def self.belongs_to_model(name)
exposed_class(name)
end
|
.custom_type? ⇒ Boolean
60
61
62
|
# File 'lib/exposant/base.rb', line 60
def self.custom_type?
exposant_type != :exposant
end
|
.exposant_base ⇒ Object
68
69
70
|
# File 'lib/exposant/base.rb', line 68
def self.exposant_base
@exposant_base = true
end
|
.exposant_base? ⇒ Boolean
64
65
66
|
# File 'lib/exposant/base.rb', line 64
def self.exposant_base?
!!@exposant_base
end
|
.exposant_type(value = nil) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/exposant/base.rb', line 47
def self.exposant_type(value = nil)
@exposant_type = value if value.present?
return @exposant_type if @exposant_type.present?
return ancestors[1].exposant_type unless ancestors[1] == Exposant::Base
:exposant
end
|
.exposant_variant ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'lib/exposant/base.rb', line 72
def self.exposant_variant
exposed_name = exposed_class.name.demodulize
variant = name
.split('::')
.tap { |arr| arr.last.gsub!(/#{exposed_name}#{type_name}$/, '') }
.last
.downcase
return nil if variant.blank?
variant.to_sym
end
|
.exposed_class(value = nil) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/exposant/base.rb', line 36
def self.exposed_class(value = nil)
@exposed_class = value.constantize if value.present?
return @exposed_class if @exposed_class.present?
return ancestors[1].exposed_class unless ancestors[1] == Exposant::Base || ancestors[1].exposant_base?
klass_name = name.gsub(/#{type_name}$/, '')
klass_name.constantize
end
|
.human_attribute_name(*args) ⇒ Object
24
25
26
|
# File 'lib/exposant/base.rb', line 24
def self.human_attribute_name(*args)
exposed_class.human_attribute_name(*args)
end
|
.klass ⇒ Object
28
29
30
|
# File 'lib/exposant/base.rb', line 28
def self.klass
@klass ||= exposed_class
end
|
.method_missing(name, *args, &block) ⇒ Object
20
21
22
|
# File 'lib/exposant/base.rb', line 20
def self.method_missing(name, *args, &block)
klass.send(name, *args, &block)
end
|
.parent_exposant ⇒ Object
86
87
88
89
90
|
# File 'lib/exposant/base.rb', line 86
def self.parent_exposant
return ancestors[1].parent_exposant unless ancestors[1] == Exposant::Base
name.constantize
end
|
.respond_to_missing?(name) ⇒ Boolean
16
17
18
|
# File 'lib/exposant/base.rb', line 16
def self.respond_to_missing?(name, *)
klass.respond_to?(name) || super
end
|
.type_name ⇒ Object
56
57
58
|
# File 'lib/exposant/base.rb', line 56
def self.type_name
exposant_type.to_s.camelcase
end
|
Instance Method Details
#to_model ⇒ Object
12
13
14
|
# File 'lib/exposant/base.rb', line 12
def to_model
__getobj__
end
|