Class: TDiary::Configuration
Instance Attribute Summary collapse
-
#database_url ⇒ Object
readonly
Returns the value of attribute database_url.
Instance Method Summary collapse
-
#[](key) ⇒ Object
get/set/delete plugin options.
- #[]=(key, val) ⇒ Object
-
#base_url ⇒ Object
backword compatibility, you can use TDiary::ViewHelper#base_url.
-
#bot? ⇒ Boolean
backword compatibility, you can use bot? or @conf.bot =~ @cgi.user_agent.
- #delete(key) ⇒ Object
-
#initialize(cgi = nil, request = nil) ⇒ Configuration
constructor
A new instance of Configuration.
-
#mobile_agent? ⇒ Boolean
backword compatibility, you can use @cgi.mobile_agent?.
- #save ⇒ Object
-
#smartphone? ⇒ Boolean
(also: #iphone?)
backword compatibility, you can use @cgi.smartphone?.
- #to_native(str, charset = nil) ⇒ Object
Constructor Details
#initialize(cgi = nil, request = nil) ⇒ Configuration
Returns a new instance of Configuration.
10 11 12 13 14 15 16 |
# File 'lib/tdiary/configuration.rb', line 10 def initialize( cgi = nil, request = nil ) @request = request configure_attrs configure_bot_pattern setup_attr_accessor_to_all_ivars load_logger end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*m) ⇒ Object (private)
228 229 230 231 |
# File 'lib/tdiary/configuration.rb', line 228 def method_missing( *m ) (class << self; self; end).class_eval { attr_accessor m[0] } if m.length == 1 nil end |
Instance Attribute Details
#database_url ⇒ Object (readonly)
Returns the value of attribute database_url.
8 9 10 |
# File 'lib/tdiary/configuration.rb', line 8 def database_url @database_url end |
Instance Method Details
#[](key) ⇒ Object
get/set/delete plugin options
30 31 32 |
# File 'lib/tdiary/configuration.rb', line 30 def []( key ) @options[key] end |
#[]=(key, val) ⇒ Object
34 35 36 |
# File 'lib/tdiary/configuration.rb', line 34 def []=( key, val ) @options2[key] = @options[key] = val end |
#base_url ⇒ Object
backword compatibility, you can use TDiary::ViewHelper#base_url
60 61 62 63 64 65 66 |
# File 'lib/tdiary/configuration.rb', line 60 def base_url if @options['base_url'] && @options['base_url'].length > 0 @options['base_url'] else @request.base_url end end |
#bot? ⇒ Boolean
backword compatibility, you can use bot? or @conf.bot =~ @cgi.user_agent
55 56 57 |
# File 'lib/tdiary/configuration.rb', line 55 def bot? @bot =~ @request.user_agent end |
#delete(key) ⇒ Object
38 39 40 41 |
# File 'lib/tdiary/configuration.rb', line 38 def delete( key ) @options.delete( key ) @options2.delete( key ) end |
#mobile_agent? ⇒ Boolean
backword compatibility, you can use @cgi.mobile_agent?
44 45 46 |
# File 'lib/tdiary/configuration.rb', line 44 def mobile_agent? @request.mobile_agent? end |
#save ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/tdiary/configuration.rb', line 18 def save result = ERB.new(File.read("#{File.dirname(__FILE__)}/../../views/tdiary.rconf").untaint).result(binding) result.untaint unless @secure Safe::safe( @secure ? 4 : 1 ) do eval( result, binding, "(TDiary::Configuration#save)", 1 ) end @io_class.save_cgi_conf(self, result) end |
#smartphone? ⇒ Boolean Also known as: iphone?
backword compatibility, you can use @cgi.smartphone?
49 50 51 |
# File 'lib/tdiary/configuration.rb', line 49 def smartphone? @request.smartphone? end |
#to_native(str, charset = nil) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tdiary/configuration.rb', line 68 def to_native( str, charset = nil ) str = str.dup if str.encoding == Encoding::ASCII_8BIT str.force_encoding(charset || 'utf-8') end unless str.valid_encoding? str.encode!('utf-16be', {invalid: :replace, undef: :replace}) end unless str.encoding == Encoding::UTF_8 str.encode!('utf-8', {invalid: :replace, undef: :replace}) end str end |