Class: Orange::Plugins::Base

Inherits:
Object
  • Object
show all
Extended by:
ClassInheritableAttributes
Defined in:
lib/orange-core/plugin.rb

Overview

This class defines a basic Orange plugin. A plugin simply defines a bunch of possible classes/files that can be called up by the main orange system.

The plugins are used in several places. When the core is initialized, it will ask all plugins if they have any resources that should be added, and load those resources if they exist.

The stack will call the list of plugins several times in building a stack once for each possible middleware location.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassInheritableAttributes

cattr_accessor, cattr_reader, cattr_writer, eval_in_accessor_module, fetch_value, store_value

Class Method Details

.assets_dir(arg) ⇒ Object



104
105
106
# File 'lib/orange-core/plugin.rb', line 104

def self.assets_dir(arg)
  self.assets = arg
end

.postrouter(r) ⇒ Object

Adds a single postrouting middleware class to list of postrouting middleware



37
38
39
# File 'lib/orange-core/plugin.rb', line 37

def self.postrouter(r)
  postrouters(r)
end

.postrouters(*routers) ⇒ Object

Adds several postrouting middleware classes to list of postrouting middleware



42
43
44
45
46
47
# File 'lib/orange-core/plugin.rb', line 42

def self.postrouters(*routers)
  self.has_middleware = true
  routers.each do |postrouter|
    self.postrouting_middleware << postrouter
  end
end

.postrouting_middlewareObject

Returns the list of prerouting_middleware defined or an empty array if none defined



80
81
82
# File 'lib/orange-core/plugin.rb', line 80

def self.postrouting_middleware
  super || self.postrouting_middleware = []
end

.prerouter(r) ⇒ Object

Adds a single prerouting middleware class to list of prerouting middleware



24
25
26
# File 'lib/orange-core/plugin.rb', line 24

def self.prerouter(r)
  prerouters(r)
end

.prerouters(*routers) ⇒ Object

Adds several prerouting middleware classes to list of prerouting middleware



29
30
31
32
33
34
# File 'lib/orange-core/plugin.rb', line 29

def self.prerouters(*routers)
  self.has_middleware = true
  routers.each do |prerouter|
    self.prerouting_middleware << prerouter
  end
end

.prerouting_middlewareObject

Returns the list of prerouting_middleware defined or an empty array if none defined



74
75
76
# File 'lib/orange-core/plugin.rb', line 74

def self.prerouting_middleware
  super || self.prerouting_middleware = []
end

.resource(instance, name = false) ⇒ Object



108
109
110
# File 'lib/orange-core/plugin.rb', line 108

def self.resource(instance, name = false)
  self.resources << [instance, name]
end

.resourcesObject



112
113
114
# File 'lib/orange-core/plugin.rb', line 112

def self.resources
  super || self.resources = []
end

.responder(r) ⇒ Object

Adds a responder middleware class



61
62
63
# File 'lib/orange-core/plugin.rb', line 61

def self.responder(r)
  responders(r)
end

.responder_middlewareObject

Returns the list of responder_middleware defined or an empty array if none defined



92
93
94
# File 'lib/orange-core/plugin.rb', line 92

def self.responder_middleware
  super || self.responder_middleware = []
end

.responders(*respones) ⇒ Object

Adds several responder middleware classes



65
66
67
68
69
70
# File 'lib/orange-core/plugin.rb', line 65

def self.responders(*respones)
  self.has_middleware = true
  respones.each do |response|
    self.responder_middleware << response
  end
end

.router(r) ⇒ Object

Adds a router middleware class to the list of routing middleware



50
51
52
# File 'lib/orange-core/plugin.rb', line 50

def self.router(r)
  routers(r)
end

.routers(*routers) ⇒ Object

Adds several router middleware classes



54
55
56
57
58
59
# File 'lib/orange-core/plugin.rb', line 54

def self.routers(*routers)
  self.has_middleware = true
  routers.each do |router|
    self.routing_middleware << router
  end
end

.routing_middlewareObject

Returns the list of routing_middleware defined or an empty array if none defined



86
87
88
# File 'lib/orange-core/plugin.rb', line 86

def self.routing_middleware
  super || self.routing_middleware = []
end

.templates_dir(arg) ⇒ Object



96
97
98
# File 'lib/orange-core/plugin.rb', line 96

def self.templates_dir(arg)
  self.templates = arg
end

.views_dir(arg) ⇒ Object



100
101
102
# File 'lib/orange-core/plugin.rb', line 100

def self.views_dir(arg)
  self.views = arg
end

Instance Method Details

#assetsObject

Returns the assets directory for this plugin



123
124
125
# File 'lib/orange-core/plugin.rb', line 123

def assets
  self.class.assets
end

#assets_nameObject

Returns the assigned asset dir name, or Plugin class name formatted like this: PluginClass -> pluginclass



118
119
120
# File 'lib/orange-core/plugin.rb', line 118

def assets_name
  self.class.assets_name || '_'+self.class.to_s.gsub(/Orange::Plugins::/, '').gsub(/::/, '_').downcase+'_'
end

#has_assets?Boolean

Whether this plugin has assets for the static middleware to worry about

Returns:

  • (Boolean)


129
130
131
# File 'lib/orange-core/plugin.rb', line 129

def has_assets?
  !assets.blank?
end

#has_middleware?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/orange-core/plugin.rb', line 168

def has_middleware?
  !middleware.blank?
end

#has_resources?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/orange-core/plugin.rb', line 137

def has_resources?
  !resources.blank?
end

#has_templates?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/orange-core/plugin.rb', line 153

def has_templates?
  !templates.blank?
end

#has_views?Boolean

Returns:

  • (Boolean)


145
146
147
# File 'lib/orange-core/plugin.rb', line 145

def has_views?
  !views.blank?
end

#middleware(type = :has) ⇒ Object



157
158
159
160
161
162
163
164
165
166
# File 'lib/orange-core/plugin.rb', line 157

def middleware(type = :has)
  case type
  when :responders then self.class.responder_middleware
  when :routing then self.class.routing_middleware
  when :prerouting then self.class.prerouting_middleware
  when :postrouting then self.class.postrouting_middleware
  when :has then self.class.has_middleware
  else nil
  end
end

#resourcesObject



133
134
135
# File 'lib/orange-core/plugin.rb', line 133

def resources
  self.class.resources
end

#templatesObject



149
150
151
# File 'lib/orange-core/plugin.rb', line 149

def templates
  self.class.templates
end

#viewsObject



141
142
143
# File 'lib/orange-core/plugin.rb', line 141

def views
  self.class.views
end