Class: SimpleMaster::Loader
- Inherits:
-
Object
- Object
- SimpleMaster::Loader
- Defined in:
- lib/simple_master/loader.rb,
lib/simple_master/loader/query_loader.rb,
lib/simple_master/loader/dataset_loader.rb,
lib/simple_master/loader/marshal_loader.rb
Direct Known Subclasses
Defined Under Namespace
Classes: DatasetLoader, MarshalLoader, QueryLoader
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#build_records(klass, raw) ⇒ Object
Interface for building records from raw data.
- #globalize(table) ⇒ Object
-
#initialize(options = {}) ⇒ Loader
constructor
A new instance of Loader.
-
#load_records(table) ⇒ Object
Returns if records are updated in table.
-
#read_raw(table) ⇒ Object
Interface for loader loading raw data, for building records and table digest.
Constructor Details
#initialize(options = {}) ⇒ Loader
Returns a new instance of Loader.
7 8 9 |
# File 'lib/simple_master/loader.rb', line 7 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/simple_master/loader.rb', line 5 def @options end |
Instance Method Details
#build_records(klass, raw) ⇒ Object
Interface for building records from raw data.
42 43 44 |
# File 'lib/simple_master/loader.rb', line 42 def build_records(klass, raw) fail NotImplementedError end |
#globalize(table) ⇒ Object
46 47 48 49 |
# File 'lib/simple_master/loader.rb', line 46 def globalize(table) return unless [:globalize_proc] table.all = [:globalize_proc].call(table.klass, table.all) end |
#load_records(table) ⇒ Object
Returns if records are updated in table.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/simple_master/loader.rb', line 12 def load_records(table) klass = table.klass fail "Load target not available." unless klass.base_class? raw = read_raw(table) new_digest = table.diff.nil? ? raw.hash : "#{raw.hash}/#{table.diff.hash}" if new_digest == table.digest return false end table.digest = new_digest table.all = build_records(klass, raw).freeze globalize(table) table.apply_diff table.update_sub_tables klass.reset_object_cache true end |
#read_raw(table) ⇒ Object
Interface for loader loading raw data, for building records and table digest.
37 38 39 |
# File 'lib/simple_master/loader.rb', line 37 def read_raw(table) fail NotImplementedError end |