Class: ActiveScaffold::Config::Base::UserSettings
- Inherits:
-
Object
- Object
- ActiveScaffold::Config::Base::UserSettings
show all
- Defined in:
- lib/active_scaffold/config/base.rb
Class Method Summary
collapse
-
.session_attr(*names) ⇒ Object
define setter and getter for names values will be saved in session if store_user_settings is enabled, in other case for current request only getter will return value set with setter, or value from conf.
-
.user_attr(*names) ⇒ Object
define setter and getter for names values will be saved for current request only getter will return value set with setter, or value from conf.
Instance Method Summary
collapse
Constructor Details
#initialize(conf, storage, params, action = :base) ⇒ UserSettings
Returns a new instance of UserSettings.
99
100
101
102
103
104
105
106
107
|
# File 'lib/active_scaffold/config/base.rb', line 99
def initialize(conf, storage, params, action = :base)
@storage = storage
@params = params
@conf = conf
@action = action.to_s
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
135
136
137
|
# File 'lib/active_scaffold/config/base.rb', line 135
def method_missing(name, *args)
proxy_to_conf?(name, true) ? @conf.send(name, *args) : super
end
|
Class Method Details
.session_attr(*names) ⇒ Object
define setter and getter for names values will be saved in session if store_user_settings is enabled, in other case for current request only getter will return value set with setter, or value from conf
92
93
94
95
96
97
|
# File 'lib/active_scaffold/config/base.rb', line 92
def self.session_attr(*names)
names.each do |name|
define_method(name) { |value| self[name] = value }
define_method(name) { key?(name) ? self[name] : @conf.send(name) }
end
end
|
.user_attr(*names) ⇒ Object
define setter and getter for names values will be saved for current request only getter will return value set with setter, or value from conf
79
80
81
82
83
84
85
86
|
# File 'lib/active_scaffold/config/base.rb', line 79
def self.user_attr(*names)
attr_writer(*names)
names.each do |name|
define_method(name) do
instance_variable_defined?("@#{name}") ? instance_variable_get("@#{name}") : @conf.send(name)
end
end
end
|
Instance Method Details
117
118
119
|
# File 'lib/active_scaffold/config/base.rb', line 117
def [](key)
@storage[@action][key.to_s] if @action && @storage[@action]
end
|
#[]=(key, value) ⇒ Object
121
122
123
124
125
126
127
128
129
|
# File 'lib/active_scaffold/config/base.rb', line 121
def []=(key, value)
@storage[@action] ||= {}
if value.present?
@storage[@action][key.to_s] = value
else
@storage[@action].delete key.to_s
@storage.delete @action if @storage[@action].empty?
end
end
|
113
114
115
|
# File 'lib/active_scaffold/config/base.rb', line 113
def core
@conf.core.user
end
|
#key?(key) ⇒ Boolean
131
132
133
|
# File 'lib/active_scaffold/config/base.rb', line 131
def key?(key)
@storage[@action].key? key.to_s if @action && @storage[@action]
end
|
#proxy_to_conf?(name, include_all) ⇒ Boolean
143
144
145
|
# File 'lib/active_scaffold/config/base.rb', line 143
def proxy_to_conf?(name, include_all)
name !~ /=$/ && @conf.respond_to?(name, include_all)
end
|
#respond_to_missing?(name, include_all = false) ⇒ Boolean
139
140
141
|
# File 'lib/active_scaffold/config/base.rb', line 139
def respond_to_missing?(name, include_all = false)
proxy_to_conf?(name, include_all) || super
end
|
109
110
111
|
# File 'lib/active_scaffold/config/base.rb', line 109
def user
self
end
|