Class: ExportToGcloud::Exporter::Definition
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- ExportToGcloud::Exporter::Definition
- Defined in:
- lib/export_to_gcloud/exporter/definition.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get_bq_table_name ⇒ Object
- #get_data(*args) ⇒ Object
-
#initialize(exporter_type, attrs) ⇒ Definition
constructor
A new instance of Definition.
- #validate! ⇒ Object
Constructor Details
#initialize(exporter_type, attrs) ⇒ Definition
Returns a new instance of Definition.
3 4 5 |
# File 'lib/export_to_gcloud/exporter/definition.rb', line 3 def initialize exporter_type, attrs super attrs.merge!(type: exporter_type) end |
Class Method Details
.load_definition(name, finder) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/export_to_gcloud/exporter/definition.rb', line 30 def self.load_definition name, finder file_path = finder.call name load file_path definition = @last_definition @last_definition = nil unless definition raise("File #{file_path.to_s} must define exporter for '#{name}'!") end unless definition.name == name raise "File #{file_path.to_s} defines '#{definition.name}' instead of '#{name}'" end definition end |
.set_last_definition(klass, attrs = {}, &block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/export_to_gcloud/exporter/definition.rb', line 22 def self.set_last_definition klass, attrs={}, &block last_definition = new klass, attrs block.call last_definition if block last_definition.validate! @last_definition = last_definition end |
Instance Method Details
#get_bq_table_name ⇒ Object
18 19 20 |
# File 'lib/export_to_gcloud/exporter/definition.rb', line 18 def get_bq_table_name bq_table_name || name end |
#get_data(*args) ⇒ Object
14 15 16 |
# File 'lib/export_to_gcloud/exporter/definition.rb', line 14 def get_data *args Proc === data ? data.call(*args) : data end |
#validate! ⇒ Object
7 8 9 10 11 12 |
# File 'lib/export_to_gcloud/exporter/definition.rb', line 7 def validate! (String === name && !name.empty?) || raise('`name` must be defined!') Proc === bq_schema || raise('`bq_schema` must be defined as a Proc!') data || raise('`data` must be defined!') type.validate_definition! self if type.respond_to? 'validate_definition!' end |