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
backward compatibility, you can use TDiary::ViewHelper#base_url.
-
#bot? ⇒ Boolean
backward 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
backward compatibility, returns NOT mobile phone always.
- #save ⇒ Object
-
#smartphone? ⇒ Boolean
(also: #iphone?)
backward compatibility, returns NOT smartphone always.
- #to_native(str, charset = nil) ⇒ Object
Constructor Details
#initialize(cgi = nil, request = nil) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 |
# File 'lib/tdiary/configuration.rb', line 9 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)
229 230 231 232 |
# File 'lib/tdiary/configuration.rb', line 229 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.
7 8 9 |
# File 'lib/tdiary/configuration.rb', line 7 def database_url @database_url end |
Instance Method Details
#[](key) ⇒ Object
get/set/delete plugin options
29 30 31 |
# File 'lib/tdiary/configuration.rb', line 29 def []( key ) @options[key] end |
#[]=(key, val) ⇒ Object
33 34 35 |
# File 'lib/tdiary/configuration.rb', line 33 def []=( key, val ) @options2[key] = @options[key] = val end |
#base_url ⇒ Object
backward compatibility, you can use TDiary::ViewHelper#base_url
59 60 61 62 63 64 65 66 67 |
# File 'lib/tdiary/configuration.rb', line 59 def base_url if @options['base_url'] && @options['base_url'].length > 0 @options['base_url'] elsif @request @request.base_url else '' end end |
#bot? ⇒ Boolean
backward compatibility, you can use bot? or @conf.bot =~ @cgi.user_agent
54 55 56 |
# File 'lib/tdiary/configuration.rb', line 54 def bot? @bot =~ @request.user_agent end |
#delete(key) ⇒ Object
37 38 39 40 |
# File 'lib/tdiary/configuration.rb', line 37 def delete( key ) @options.delete( key ) @options2.delete( key ) end |
#mobile_agent? ⇒ Boolean
backward compatibility, returns NOT mobile phone always
43 44 45 |
# File 'lib/tdiary/configuration.rb', line 43 def mobile_agent? false end |
#save ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/tdiary/configuration.rb', line 17 def save result = ERB.new(File.read("#{File.dirname(__FILE__)}/../../views/tdiary.rconf").untaint).result(binding) result.untaint Safe::safe do eval( result, binding, "(TDiary::Configuration#save)", 1 ) end @io_class.save_cgi_conf(self, result) end |
#smartphone? ⇒ Boolean Also known as: iphone?
backward compatibility, returns NOT smartphone always
48 49 50 |
# File 'lib/tdiary/configuration.rb', line 48 def smartphone? false end |
#to_native(str, charset = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tdiary/configuration.rb', line 69 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 |