Class: Atreides::Configuration
- Inherits:
-
Object
- Object
- Atreides::Configuration
- Defined in:
- lib/atreides/configuration.rb
Instance Attribute Summary collapse
-
#admin_route_prefix ⇒ Object
Returns the value of attribute admin_route_prefix.
-
#admin_route_redirect ⇒ Object
Returns the value of attribute admin_route_redirect.
-
#user_model ⇒ Object
Returns the value of attribute user_model.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Configuration defaults.
- #inject_overrides(atreides_class) ⇒ Object
- #override(*args) ⇒ Object
- #overrides ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Configuration defaults
10 11 12 13 14 |
# File 'lib/atreides/configuration.rb', line 10 def initialize @user_model = 'User' @admin_route_prefix = 'admin' @admin_route_redirect = "/#{@admin_route_prefix}/pages" end |
Instance Attribute Details
#admin_route_prefix ⇒ Object
Returns the value of attribute admin_route_prefix.
3 4 5 |
# File 'lib/atreides/configuration.rb', line 3 def admin_route_prefix @admin_route_prefix end |
#admin_route_redirect ⇒ Object
Returns the value of attribute admin_route_redirect.
4 5 6 |
# File 'lib/atreides/configuration.rb', line 4 def admin_route_redirect @admin_route_redirect end |
#user_model ⇒ Object
Returns the value of attribute user_model.
2 3 4 |
# File 'lib/atreides/configuration.rb', line 2 def user_model @user_model end |
Instance Method Details
#inject_overrides(atreides_class) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/atreides/configuration.rb', line 34 def inject_overrides atreides_class # Rails.logger.debug { "Injecting overrides in class #{atreides_class.inspect} !" } modules = @@overrides[atreides_class.to_s.to_sym] || [] modules.uniq.each do |hostapp_module_name| begin host_module = hostapp_module_name.to_s.constantize # puts "\t\tInjecting #{host_module} into #{atreides_class}" atreides_class.instance_eval { include host_module } rescue NameError => e from = @overriden_from[atreides_class.to_s.to_sym] rescue "---" puts <<-ERR Atreides configuration error ! Following Atreides's configuration, here: #{from.inspect} Atreides's' '#{atreides_class.to_s}' class should be overriden by a class named #{hostapp_module_name.inspect}. This #{hostapp_module_name.inspect} class could not be loaded ! ERR raise e end end end |
#override(*args) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/atreides/configuration.rb', line 20 def override *args from = caller[0] overrides = args. args.each { |arg| overrides[arg] = arg.to_sym } overrides.each do | atreides_classname, host_concern_name | unless atreides_classname.to_s.starts_with? 'Atreides::' atreides_classname = "Atreides::#{atreides_classname}" end @@overrides[atreides_classname.to_sym] = [] if @@overrides[atreides_classname.to_sym].nil? @@overrides[atreides_classname.to_sym] << host_concern_name @@overriden_from[atreides_classname.to_sym] = from end end |
#overrides ⇒ Object
16 17 18 |
# File 'lib/atreides/configuration.rb', line 16 def overrides @@overrides end |