Class: CommaHeaven::Export
- Inherits:
-
Object
- Object
- CommaHeaven::Export
- Defined in:
- lib/comma-heaven/export.rb
Defined Under Namespace
Modules: Implementation
Instance Attribute Summary collapse
-
#by ⇒ Object
Returns the value of attribute by.
-
#col_sep ⇒ Object
Returns the value of attribute col_sep.
-
#current_scope ⇒ Object
Returns the value of attribute current_scope.
-
#export ⇒ Object
Returns the value of attribute export.
-
#format ⇒ Object
Returns the value of attribute format.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#limit ⇒ Object
Returns the value of attribute limit.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(klass, current_scope, options = {}) ⇒ Export
constructor
A new instance of Export.
- #save(options = {}) ⇒ Object
Constructor Details
#initialize(klass, current_scope, options = {}) ⇒ Export
Returns a new instance of Export.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/comma-heaven/export.rb', line 34 def initialize(klass, current_scope, = {}) self.klass = klass self.current_scope = current_scope self. = || {} self..symbolize_keys! if self..respond_to?(:symbolize_keys!) self.export = self.[:export] || {} self.export.symbolize_keys! if self.export.respond_to?(:symbolize_keys!) self.limit = self.[:limit] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/comma-heaven/export.rb', line 63 def method_missing(name, *args, &block) case when column_name?(name) return OpenStruct.new(export[name].values.first) rescue OpenStruct.new({}) when association_name?(name) return self.class.new(klass.reflect_on_association(name).klass, {}, export[name].values.first) rescue self.class.new(klass.reflect_on_association(name).klass, {}, {}) else return super end end |
Instance Attribute Details
#by ⇒ Object
Returns the value of attribute by.
31 32 33 |
# File 'lib/comma-heaven/export.rb', line 31 def by @by end |
#col_sep ⇒ Object
Returns the value of attribute col_sep.
31 32 33 |
# File 'lib/comma-heaven/export.rb', line 31 def col_sep @col_sep end |
#current_scope ⇒ Object
Returns the value of attribute current_scope.
31 32 33 |
# File 'lib/comma-heaven/export.rb', line 31 def current_scope @current_scope end |
#export ⇒ Object
Returns the value of attribute export.
31 32 33 |
# File 'lib/comma-heaven/export.rb', line 31 def export @export end |
#format ⇒ Object
Returns the value of attribute format.
31 32 33 |
# File 'lib/comma-heaven/export.rb', line 31 def format @format end |
#klass ⇒ Object
Returns the value of attribute klass.
31 32 33 |
# File 'lib/comma-heaven/export.rb', line 31 def klass @klass end |
#limit ⇒ Object
Returns the value of attribute limit.
31 32 33 |
# File 'lib/comma-heaven/export.rb', line 31 def limit @limit end |
#options ⇒ Object
Returns the value of attribute options.
31 32 33 |
# File 'lib/comma-heaven/export.rb', line 31 def @options end |
Instance Method Details
#save(options = {}) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/comma-heaven/export.rb', line 48 def save( = {}) = self..merge() = .slice(*FasterCSV::DEFAULT_OPTIONS.keys) = .except(*FasterCSV::DEFAULT_OPTIONS.keys) # TCH means To Comma Heaven = .symbolize_keys if .respond_to?(:symbolize_keys!) = .symbolize_keys if .respond_to?(:symbolize_keys!) current_scope .to_comma_heaven() .to_csv() end |