Class: Rivendell::Import::Cart
- Inherits:
-
Object
- Object
- Rivendell::Import::Cart
show all
- Includes:
- ActiveModel::Serialization, ActiveModel::Serializers::JSON
- Defined in:
- lib/rivendell/import/cart.rb
Defined Under Namespace
Classes: ApiUpdater, DbUpdater, Updater
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(task = nil) ⇒ Cart
Returns a new instance of Cart.
38
39
40
|
# File 'lib/rivendell/import/cart.rb', line 38
def initialize(task = nil)
@task = task
end
|
Instance Attribute Details
#clear_cuts ⇒ Object
Also known as:
clear_cuts?
Returns the value of attribute clear_cuts.
183
184
185
|
# File 'lib/rivendell/import/cart.rb', line 183
def clear_cuts
@clear_cuts
end
|
#default_title ⇒ Object
Returns the value of attribute default_title.
35
36
37
|
# File 'lib/rivendell/import/cart.rb', line 35
def default_title
@default_title
end
|
#group ⇒ Object
Returns the value of attribute group.
35
36
37
|
# File 'lib/rivendell/import/cart.rb', line 35
def group
@group
end
|
#import_options ⇒ Object
Returns the value of attribute import_options.
155
156
157
|
# File 'lib/rivendell/import/cart.rb', line 155
def import_options
@import_options
end
|
#number ⇒ Object
Returns the value of attribute number.
35
36
37
|
# File 'lib/rivendell/import/cart.rb', line 35
def number
@number
end
|
#scheduler_codes ⇒ Object
Returns the value of attribute scheduler_codes.
35
36
37
|
# File 'lib/rivendell/import/cart.rb', line 35
def scheduler_codes
@scheduler_codes
end
|
#task ⇒ Object
Returns the value of attribute task.
36
37
38
|
# File 'lib/rivendell/import/cart.rb', line 36
def task
@task
end
|
#title ⇒ Object
Returns the value of attribute title.
35
36
37
|
# File 'lib/rivendell/import/cart.rb', line 35
def title
@title
end
|
Instance Method Details
#as_json(options = {}) ⇒ Object
7
8
9
|
# File 'lib/rivendell/import/cart.rb', line 7
def as_json(options = {})
super options.merge(:root => false)
end
|
#attributes ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/rivendell/import/cart.rb', line 11
def attributes
attributes = {}
%w{number group clear_cuts title default_title scheduler_codes import_options}.each do |attribute|
value = send attribute
attributes[attribute] = value if value.present?
end
if (cut_attributes = cut.attributes).present?
attributes["cut"] = cut_attributes
end
attributes
end
|
#attributes=(attributes) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/rivendell/import/cart.rb', line 23
def attributes=(attributes)
attributes.each do |k,v|
unless k == "cut"
send "#{k}=", v
else
cut.attributes = v
end
end
end
|
#clear_cuts! ⇒ Object
186
187
188
|
# File 'lib/rivendell/import/cart.rb', line 186
def clear_cuts!
self.clear_cuts = true
end
|
#create ⇒ Object
50
51
52
53
54
55
|
# File 'lib/rivendell/import/cart.rb', line 50
def create
unless number
raise "Can't create Cart, Group isn't defined" unless group.present?
self.number = xport.add_cart(:group => group).number
end
end
|
#cut ⇒ Object
151
152
153
|
# File 'lib/rivendell/import/cart.rb', line 151
def cut
@cut ||= Cut.new(self)
end
|
#find_by_title(string, options = {}) ⇒ Object
174
175
176
177
178
179
180
181
|
# File 'lib/rivendell/import/cart.rb', line 174
def find_by_title(string, options = {})
Rivendell::Import.logger.debug "Looking for a Cart '#{string}'"
if remote_cart = cart_finder.find_by_title(string, options)
Rivendell::Import.logger.debug "Found Cart #{remote_cart.number}"
self.number = remote_cart.number
self.import_options[:use_metadata] = false
end
end
|
#import(file) ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/rivendell/import/cart.rb', line 160
def import(file)
raise "File #{file.path} not found" unless file.exists?
if clear_cuts?
Rivendell::Import.logger.debug "Clear cuts of Cart #{number}"
xport.clear_cuts number
end
cut.create
Rivendell::Import.logger.debug "Import #{file.path} in Cut #{cut.number}"
xport.import number, cut.number, file.path, import_options.symbolize_keys
cut.update
end
|
#update ⇒ Object
57
58
59
60
61
|
# File 'lib/rivendell/import/cart.rb', line 57
def update
updaters.any? do |updater|
updater.new(self).update
end
end
|
#updaters ⇒ Object
63
64
65
66
67
68
|
# File 'lib/rivendell/import/cart.rb', line 63
def updaters
[].tap do |updaters|
updaters << ApiUpdater if scheduler_codes.empty?
updaters << DbUpdater if Database.enabled?
end
end
|
#xport ⇒ Object
46
47
48
|
# File 'lib/rivendell/import/cart.rb', line 46
def xport
task.xport
end
|