Class: Sequel::Platform::Base
- Inherits:
-
Object
- Object
- Sequel::Platform::Base
- Defined in:
- lib/sequel/extensions/platform.rb
Overview
Base platform class with KVCSV config loading and default implementations. Subclasses override function translation methods for platform-specific SQL.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#db ⇒ Object
readonly
Returns the value of attribute db.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Access arbitrary config values.
-
#cast_date(expr) ⇒ Sequel::SQL::Cast
Cast expression to date type.
-
#date_diff(from, to) ⇒ Sequel::SQL::Expression
Calculate date difference between two dates.
-
#days_between(from, to) ⇒ Sequel::SQL::Expression
Calculate days between two dates.
-
#fetch(key, default = nil) ⇒ Object
Fetch config value with default.
-
#initialize(db, *config_paths) ⇒ Base
constructor
Initialize platform with database connection and config paths.
-
#prefers?(feature) ⇒ Boolean
Check if the platform prefers a feature (may support but not prefer).
-
#str_to_date(value, format) ⇒ Sequel::SQL::Expression
Parse string to date with format.
-
#supports?(feature) ⇒ Boolean
Check if the platform supports a feature.
Constructor Details
#initialize(db, *config_paths) ⇒ Base
Initialize platform with database connection and config paths.
39 40 41 42 |
# File 'lib/sequel/extensions/platform.rb', line 39 def initialize(db, *config_paths) @db = db @config = config_paths.empty? ? {} : KVCSV::Settings.new(*config_paths) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
33 34 35 |
# File 'lib/sequel/extensions/platform.rb', line 33 def config @config end |
#db ⇒ Object (readonly)
Returns the value of attribute db.
33 34 35 |
# File 'lib/sequel/extensions/platform.rb', line 33 def db @db end |
Instance Method Details
#[](key) ⇒ Object
Access arbitrary config values.
76 77 78 |
# File 'lib/sequel/extensions/platform.rb', line 76 def [](key) config[key] end |
#cast_date(expr) ⇒ Sequel::SQL::Cast
Cast expression to date type.
104 105 106 |
# File 'lib/sequel/extensions/platform.rb', line 104 def cast_date(expr) Sequel.cast(expr, Date) end |
#date_diff(from, to) ⇒ Sequel::SQL::Expression
Calculate date difference between two dates.
96 97 98 |
# File 'lib/sequel/extensions/platform.rb', line 96 def date_diff(from, to) Sequel.function(:datediff, from, to) end |
#days_between(from, to) ⇒ Sequel::SQL::Expression
Calculate days between two dates.
122 123 124 |
# File 'lib/sequel/extensions/platform.rb', line 122 def days_between(from, to) date_diff(from, to) end |
#fetch(key, default = nil) ⇒ Object
Fetch config value with default.
85 86 87 |
# File 'lib/sequel/extensions/platform.rb', line 85 def fetch(key, default = nil) config.respond_to?(:fetch) ? config.fetch(key, default) : (config[key] || default) end |
#prefers?(feature) ⇒ Boolean
Check if the platform prefers a feature (may support but not prefer).
64 65 66 |
# File 'lib/sequel/extensions/platform.rb', line 64 def prefers?(feature) config[:"prefers_#{feature}"] || false end |
#str_to_date(value, format) ⇒ Sequel::SQL::Expression
Parse string to date with format.
113 114 115 |
# File 'lib/sequel/extensions/platform.rb', line 113 def str_to_date(value, format) Sequel.function(:to_date, value, format) end |
#supports?(feature) ⇒ Boolean
Check if the platform supports a feature.
52 53 54 |
# File 'lib/sequel/extensions/platform.rb', line 52 def supports?(feature) config[:"supports_#{feature}"] || false end |