Module: RocketJob::Batch::Categories

Extended by:
ActiveSupport::Concern
Included in:
RocketJob::Batch
Defined in:
lib/rocket_job/batch/categories.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#input_category(category_name = :main) ⇒ Object

Raises:

  • (ArgumentError)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rocket_job/batch/categories.rb', line 74

def input_category(category_name = :main)
  return category_name if category_name.is_a?(Category::Input)
  raise(ArgumentError, "Cannot supply Output Category to input category") if category_name.is_a?(Category::Output)

  category_name = category_name.to_sym
  # find does not work against this association
  input_categories.each { |category| return category if category.name == category_name }

  unless category_name == :main
    raise(
      ArgumentError,
      "Unknown Input Category: #{category_name.inspect}. Registered categories: #{input_categories.collect(&:name).join(',')}"
    )
  end

  # Auto-register main input category when not defined
  category = Category::Input.new(job: self)
  self.input_categories << category
  category
end

#input_category?(category_name) ⇒ Boolean

Returns [true|false] whether the named category has already been defined

Returns:

  • (Boolean)


110
111
112
113
114
115
# File 'lib/rocket_job/batch/categories.rb', line 110

def input_category?(category_name)
  category_name = category_name.to_sym
  # .find does not work against this association
  input_categories.each { |catg| return true if catg.name == category_name }
  false
end

#merge_input_categories(categories) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/rocket_job/batch/categories.rb', line 124

def merge_input_categories(categories)
  return if categories.blank?

  categories.each do |properties|
    category_name = (properties["name"] || properties[:name] || :main).to_sym
    category      = input_category(category_name)
    properties.each { |key, value| category.public_send("#{key}=".to_sym, value) }
  end
end

#merge_output_categories(categories) ⇒ Object



134
135
136
137
138
139
140
141
142
# File 'lib/rocket_job/batch/categories.rb', line 134

def merge_output_categories(categories)
  return if categories.blank?

  categories.each do |properties|
    category_name = (properties["name"] || properties[:name] || :main).to_sym
    category      = output_category(category_name)
    properties.each { |key, value| category.public_send("#{key}=".to_sym, value) }
  end
end

#output_category(category_name = :main) ⇒ Object

Raises:

  • (ArgumentError)


95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rocket_job/batch/categories.rb', line 95

def output_category(category_name = :main)
  return category_name if category_name.is_a?(Category::Output)
  raise(ArgumentError, "Cannot supply Input Category to output category") if category_name.is_a?(Category::Input)

  category_name = category_name.to_sym
  # .find does not work against this association
  output_categories.each { |category| return category if category.name == category_name }

  raise(
    ArgumentError,
    "Unknown Output Category: #{category_name.inspect}. Registered categories: #{output_categories.collect(&:name).join(',')}"
  )
end

#output_category?(category_name) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
120
121
122
# File 'lib/rocket_job/batch/categories.rb', line 117

def output_category?(category_name)
  category_name = category_name.to_sym
  # .find does not work against this association
  output_categories.each { |catg| return true if catg.name == category_name }
  false
end