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
# 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)

  # Initialize categories when this method is called before initialization is complete
  rocketjob_categories_assign if input_categories.empty?

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

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

#input_category?(category_name) ⇒ Boolean

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

Returns:

  • (Boolean)


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

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



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

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



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

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)


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

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)

  # Initialize categories when this method is called before initialization is complete
  rocketjob_categories_assign if output_categories.empty? && self.class.defined_output_categories

  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)


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

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