repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
nning/transmission-rss
lib/transmission-rss/aggregator.rb
TransmissionRSS.Aggregator.run
def run(interval = 600) @log.debug('aggregator start') loop do @feeds.each do |feed| @log.debug('aggregate ' + feed.url) options = {allow_redirections: :safe} unless feed.validate_cert @log.debug('aggregate certificate validation: false') options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE end begin content = open(feed.url, options).read rescue StandardError => e @log.debug("retrieval error (#{e.class}: #{e.message})") next end # gzip HTTP Content-Encoding is not automatically decompressed in # Ruby 1.9.3. content = decompress(content) if RUBY_VERSION == '1.9.3' begin items = RSS::Parser.parse(content, false).items rescue StandardError => e @log.debug("parse error (#{e.class}: #{e.message})") next end items.each do |item| result = process_link(feed, item) next if result.nil? end end if interval == -1 @log.debug('single run mode, exiting') break end sleep(interval) end end
ruby
def run(interval = 600) @log.debug('aggregator start') loop do @feeds.each do |feed| @log.debug('aggregate ' + feed.url) options = {allow_redirections: :safe} unless feed.validate_cert @log.debug('aggregate certificate validation: false') options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE end begin content = open(feed.url, options).read rescue StandardError => e @log.debug("retrieval error (#{e.class}: #{e.message})") next end # gzip HTTP Content-Encoding is not automatically decompressed in # Ruby 1.9.3. content = decompress(content) if RUBY_VERSION == '1.9.3' begin items = RSS::Parser.parse(content, false).items rescue StandardError => e @log.debug("parse error (#{e.class}: #{e.message})") next end items.each do |item| result = process_link(feed, item) next if result.nil? end end if interval == -1 @log.debug('single run mode, exiting') break end sleep(interval) end end
[ "def", "run", "(", "interval", "=", "600", ")", "@log", ".", "debug", "(", "'aggregator start'", ")", "loop", "do", "@feeds", ".", "each", "do", "|", "feed", "|", "@log", ".", "debug", "(", "'aggregate '", "+", "feed", ".", "url", ")", "options", "=", "{", "allow_redirections", ":", ":safe", "}", "unless", "feed", ".", "validate_cert", "@log", ".", "debug", "(", "'aggregate certificate validation: false'", ")", "options", "[", ":ssl_verify_mode", "]", "=", "OpenSSL", "::", "SSL", "::", "VERIFY_NONE", "end", "begin", "content", "=", "open", "(", "feed", ".", "url", ",", "options", ")", ".", "read", "rescue", "StandardError", "=>", "e", "@log", ".", "debug", "(", "\"retrieval error (#{e.class}: #{e.message})\"", ")", "next", "end", "# gzip HTTP Content-Encoding is not automatically decompressed in", "# Ruby 1.9.3.", "content", "=", "decompress", "(", "content", ")", "if", "RUBY_VERSION", "==", "'1.9.3'", "begin", "items", "=", "RSS", "::", "Parser", ".", "parse", "(", "content", ",", "false", ")", ".", "items", "rescue", "StandardError", "=>", "e", "@log", ".", "debug", "(", "\"parse error (#{e.class}: #{e.message})\"", ")", "next", "end", "items", ".", "each", "do", "|", "item", "|", "result", "=", "process_link", "(", "feed", ",", "item", ")", "next", "if", "result", ".", "nil?", "end", "end", "if", "interval", "==", "-", "1", "@log", ".", "debug", "(", "'single run mode, exiting'", ")", "break", "end", "sleep", "(", "interval", ")", "end", "end" ]
Get file enclosures from all feeds items and call on_new_item callback with torrent file URL as argument.
[ "Get", "file", "enclosures", "from", "all", "feeds", "items", "and", "call", "on_new_item", "callback", "with", "torrent", "file", "URL", "as", "argument", "." ]
07baaf149d9e129e98b4cb496d808a528a59bc5b
https://github.com/nning/transmission-rss/blob/07baaf149d9e129e98b4cb496d808a528a59bc5b/lib/transmission-rss/aggregator.rb#L40-L84
train
nning/transmission-rss
lib/transmission-rss/callback.rb
TransmissionRSS.Callback.callback
def callback(*names) names.each do |name| self.class_eval do define_method name, ->(*args, &block) do @callbacks ||= {} if block @callbacks[name] = block elsif @callbacks[name] @callbacks[name].call(*args) end end end end end
ruby
def callback(*names) names.each do |name| self.class_eval do define_method name, ->(*args, &block) do @callbacks ||= {} if block @callbacks[name] = block elsif @callbacks[name] @callbacks[name].call(*args) end end end end end
[ "def", "callback", "(", "*", "names", ")", "names", ".", "each", "do", "|", "name", "|", "self", ".", "class_eval", "do", "define_method", "name", ",", "->", "(", "*", "args", ",", "&", "block", ")", "do", "@callbacks", "||=", "{", "}", "if", "block", "@callbacks", "[", "name", "]", "=", "block", "elsif", "@callbacks", "[", "name", "]", "@callbacks", "[", "name", "]", ".", "call", "(", "args", ")", "end", "end", "end", "end", "end" ]
Define callback method.
[ "Define", "callback", "method", "." ]
07baaf149d9e129e98b4cb496d808a528a59bc5b
https://github.com/nning/transmission-rss/blob/07baaf149d9e129e98b4cb496d808a528a59bc5b/lib/transmission-rss/callback.rb#L4-L17
train
GoogleCloudPlatform/appengine-ruby
lib/appengine/exec.rb
AppEngine.Exec.start
def start resolve_parameters version_info = version_info @service, @version env_variables = version_info["envVariables"] || {} beta_settings = version_info["betaSettings"] || {} cloud_sql_instances = beta_settings["cloud_sql_instances"] || [] image = version_info["deployment"]["container"]["image"] config = build_config command, image, env_variables, cloud_sql_instances file = ::Tempfile.new ["cloudbuild_", ".json"] begin ::JSON.dump config, file file.flush Util::Gcloud.execute [ "builds", "submit", "--no-source", "--config=#{file.path}", "--timeout=#{@timeout}"] ensure file.close! end end
ruby
def start resolve_parameters version_info = version_info @service, @version env_variables = version_info["envVariables"] || {} beta_settings = version_info["betaSettings"] || {} cloud_sql_instances = beta_settings["cloud_sql_instances"] || [] image = version_info["deployment"]["container"]["image"] config = build_config command, image, env_variables, cloud_sql_instances file = ::Tempfile.new ["cloudbuild_", ".json"] begin ::JSON.dump config, file file.flush Util::Gcloud.execute [ "builds", "submit", "--no-source", "--config=#{file.path}", "--timeout=#{@timeout}"] ensure file.close! end end
[ "def", "start", "resolve_parameters", "version_info", "=", "version_info", "@service", ",", "@version", "env_variables", "=", "version_info", "[", "\"envVariables\"", "]", "||", "{", "}", "beta_settings", "=", "version_info", "[", "\"betaSettings\"", "]", "||", "{", "}", "cloud_sql_instances", "=", "beta_settings", "[", "\"cloud_sql_instances\"", "]", "||", "[", "]", "image", "=", "version_info", "[", "\"deployment\"", "]", "[", "\"container\"", "]", "[", "\"image\"", "]", "config", "=", "build_config", "command", ",", "image", ",", "env_variables", ",", "cloud_sql_instances", "file", "=", "::", "Tempfile", ".", "new", "[", "\"cloudbuild_\"", ",", "\".json\"", "]", "begin", "::", "JSON", ".", "dump", "config", ",", "file", "file", ".", "flush", "Util", "::", "Gcloud", ".", "execute", "[", "\"builds\"", ",", "\"submit\"", ",", "\"--no-source\"", ",", "\"--config=#{file.path}\"", ",", "\"--timeout=#{@timeout}\"", "]", "ensure", "file", ".", "close!", "end", "end" ]
Executes the command synchronously. Streams the logs back to standard out and does not return until the command has completed or timed out.
[ "Executes", "the", "command", "synchronously", ".", "Streams", "the", "logs", "back", "to", "standard", "out", "and", "does", "not", "return", "until", "the", "command", "has", "completed", "or", "timed", "out", "." ]
e8f6525c14ceda29013d570560880354ceb7153c
https://github.com/GoogleCloudPlatform/appengine-ruby/blob/e8f6525c14ceda29013d570560880354ceb7153c/lib/appengine/exec.rb#L288-L310
train
lolcommits/lolcommits
lib/lolcommits/capturer/capture_windows_animated.rb
Lolcommits.CaptureWindowsAnimated.device_names
def device_names @device_names ||= begin names = [] cmd_output = '' count = 0 while cmd_output.empty? || !cmd_output.split('DirectShow')[2] cmd_output = system_call(ffpmeg_list_devices_cmd, true) count += 1 raise 'failed to find a video capture device with ffmpeg -list_devices' if count == 5 sleep 0.1 end cmd_output.gsub!("\r\n", "\n") video = cmd_output.split('DirectShow')[1] video.lines.map do |line| names << Regexp.last_match(1) if line =~ /"(.+)"\n/ end debug "Capturer: found #{names.length} video devices: #{names.join(', ')}" names end end
ruby
def device_names @device_names ||= begin names = [] cmd_output = '' count = 0 while cmd_output.empty? || !cmd_output.split('DirectShow')[2] cmd_output = system_call(ffpmeg_list_devices_cmd, true) count += 1 raise 'failed to find a video capture device with ffmpeg -list_devices' if count == 5 sleep 0.1 end cmd_output.gsub!("\r\n", "\n") video = cmd_output.split('DirectShow')[1] video.lines.map do |line| names << Regexp.last_match(1) if line =~ /"(.+)"\n/ end debug "Capturer: found #{names.length} video devices: #{names.join(', ')}" names end end
[ "def", "device_names", "@device_names", "||=", "begin", "names", "=", "[", "]", "cmd_output", "=", "''", "count", "=", "0", "while", "cmd_output", ".", "empty?", "||", "!", "cmd_output", ".", "split", "(", "'DirectShow'", ")", "[", "2", "]", "cmd_output", "=", "system_call", "(", "ffpmeg_list_devices_cmd", ",", "true", ")", "count", "+=", "1", "raise", "'failed to find a video capture device with ffmpeg -list_devices'", "if", "count", "==", "5", "sleep", "0.1", "end", "cmd_output", ".", "gsub!", "(", "\"\\r\\n\"", ",", "\"\\n\"", ")", "video", "=", "cmd_output", ".", "split", "(", "'DirectShow'", ")", "[", "1", "]", "video", ".", "lines", ".", "map", "do", "|", "line", "|", "names", "<<", "Regexp", ".", "last_match", "(", "1", ")", "if", "line", "=~", "/", "\\n", "/", "end", "debug", "\"Capturer: found #{names.length} video devices: #{names.join(', ')}\"", "names", "end", "end" ]
inspired by this code from @rdp http://tinyurl.com/y7t276bh
[ "inspired", "by", "this", "code", "from" ]
8569c729daff97d0b2cd328bcfb0986925f6622e
https://github.com/lolcommits/lolcommits/blob/8569c729daff97d0b2cd328bcfb0986925f6622e/lib/lolcommits/capturer/capture_windows_animated.rb#L45-L67
train
lolcommits/lolcommits
lib/lolcommits/runner.rb
Lolcommits.Runner.run_capture
def run_capture puts '*** Preserving this moment in history.' unless capture_stealth self.snapshot_loc = config.raw_image(image_file_type) self.main_image = config.main_image(sha, image_file_type) capturer = Platform.capturer_class(capture_animated?).new( capture_device: capture_device, capture_delay: capture_delay, snapshot_location: snapshot_loc, video_location: config.video_loc, frames_location: config.frames_loc, animated_duration: capture_animate ) capturer.capture end
ruby
def run_capture puts '*** Preserving this moment in history.' unless capture_stealth self.snapshot_loc = config.raw_image(image_file_type) self.main_image = config.main_image(sha, image_file_type) capturer = Platform.capturer_class(capture_animated?).new( capture_device: capture_device, capture_delay: capture_delay, snapshot_location: snapshot_loc, video_location: config.video_loc, frames_location: config.frames_loc, animated_duration: capture_animate ) capturer.capture end
[ "def", "run_capture", "puts", "'*** Preserving this moment in history.'", "unless", "capture_stealth", "self", ".", "snapshot_loc", "=", "config", ".", "raw_image", "(", "image_file_type", ")", "self", ".", "main_image", "=", "config", ".", "main_image", "(", "sha", ",", "image_file_type", ")", "capturer", "=", "Platform", ".", "capturer_class", "(", "capture_animated?", ")", ".", "new", "(", "capture_device", ":", "capture_device", ",", "capture_delay", ":", "capture_delay", ",", "snapshot_location", ":", "snapshot_loc", ",", "video_location", ":", "config", ".", "video_loc", ",", "frames_location", ":", "config", ".", "frames_loc", ",", "animated_duration", ":", "capture_animate", ")", "capturer", ".", "capture", "end" ]
the main capture
[ "the", "main", "capture" ]
8569c729daff97d0b2cd328bcfb0986925f6622e
https://github.com/lolcommits/lolcommits/blob/8569c729daff97d0b2cd328bcfb0986925f6622e/lib/lolcommits/runner.rb#L71-L85
train
weshatheleopard/rubyXL
lib/rubyXL/objects/column_range.rb
RubyXL.ColumnRanges.get_range
def get_range(col_index) col_num = col_index + 1 old_range = self.locate_range(col_index) if old_range.nil? then new_range = RubyXL::ColumnRange.new else if old_range.min == col_num && old_range.max == col_num then return old_range # Single column range, OK to change in place elsif old_range.min == col_num then new_range = old_range.dup old_range.min += 1 elsif old_range.max == col_num then new_range = old_range.dup old_range.max -= 1 else range_before = old_range.dup range_before.max = col_index # col_num - 1 self << range_before old_range.min = col_num + 1 new_range = RubyXL::ColumnRange.new end end new_range.min = new_range.max = col_num self << new_range return new_range end
ruby
def get_range(col_index) col_num = col_index + 1 old_range = self.locate_range(col_index) if old_range.nil? then new_range = RubyXL::ColumnRange.new else if old_range.min == col_num && old_range.max == col_num then return old_range # Single column range, OK to change in place elsif old_range.min == col_num then new_range = old_range.dup old_range.min += 1 elsif old_range.max == col_num then new_range = old_range.dup old_range.max -= 1 else range_before = old_range.dup range_before.max = col_index # col_num - 1 self << range_before old_range.min = col_num + 1 new_range = RubyXL::ColumnRange.new end end new_range.min = new_range.max = col_num self << new_range return new_range end
[ "def", "get_range", "(", "col_index", ")", "col_num", "=", "col_index", "+", "1", "old_range", "=", "self", ".", "locate_range", "(", "col_index", ")", "if", "old_range", ".", "nil?", "then", "new_range", "=", "RubyXL", "::", "ColumnRange", ".", "new", "else", "if", "old_range", ".", "min", "==", "col_num", "&&", "old_range", ".", "max", "==", "col_num", "then", "return", "old_range", "# Single column range, OK to change in place", "elsif", "old_range", ".", "min", "==", "col_num", "then", "new_range", "=", "old_range", ".", "dup", "old_range", ".", "min", "+=", "1", "elsif", "old_range", ".", "max", "==", "col_num", "then", "new_range", "=", "old_range", ".", "dup", "old_range", ".", "max", "-=", "1", "else", "range_before", "=", "old_range", ".", "dup", "range_before", ".", "max", "=", "col_index", "# col_num - 1", "self", "<<", "range_before", "old_range", ".", "min", "=", "col_num", "+", "1", "new_range", "=", "RubyXL", "::", "ColumnRange", ".", "new", "end", "end", "new_range", ".", "min", "=", "new_range", ".", "max", "=", "col_num", "self", "<<", "new_range", "return", "new_range", "end" ]
Locate an existing column range, make a new one if not found, or split existing column range into multiples.
[ "Locate", "an", "existing", "column", "range", "make", "a", "new", "one", "if", "not", "found", "or", "split", "existing", "column", "range", "into", "multiples", "." ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/objects/column_range.rb#L45-L75
train
weshatheleopard/rubyXL
lib/rubyXL/objects/workbook.rb
RubyXL.Workbook.save
def save(dst_file_path = nil) dst_file_path ||= root.source_file_path extension = File.extname(dst_file_path) unless %w{.xlsx .xlsm}.include?(extension.downcase) raise "Unsupported extension: #{extension} (only .xlsx and .xlsm files are supported)." end File.open(dst_file_path, "wb") { |output_file| FileUtils.copy_stream(root.stream, output_file) } return dst_file_path end
ruby
def save(dst_file_path = nil) dst_file_path ||= root.source_file_path extension = File.extname(dst_file_path) unless %w{.xlsx .xlsm}.include?(extension.downcase) raise "Unsupported extension: #{extension} (only .xlsx and .xlsm files are supported)." end File.open(dst_file_path, "wb") { |output_file| FileUtils.copy_stream(root.stream, output_file) } return dst_file_path end
[ "def", "save", "(", "dst_file_path", "=", "nil", ")", "dst_file_path", "||=", "root", ".", "source_file_path", "extension", "=", "File", ".", "extname", "(", "dst_file_path", ")", "unless", "%w{", ".xlsx", ".xlsm", "}", ".", "include?", "(", "extension", ".", "downcase", ")", "raise", "\"Unsupported extension: #{extension} (only .xlsx and .xlsm files are supported).\"", "end", "File", ".", "open", "(", "dst_file_path", ",", "\"wb\"", ")", "{", "|", "output_file", "|", "FileUtils", ".", "copy_stream", "(", "root", ".", "stream", ",", "output_file", ")", "}", "return", "dst_file_path", "end" ]
Save the resulting XLSX file to the specified location
[ "Save", "the", "resulting", "XLSX", "file", "to", "the", "specified", "location" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/objects/workbook.rb#L390-L401
train
weshatheleopard/rubyXL
lib/rubyXL/objects/workbook.rb
RubyXL.Workbook.[]
def [](ind) case ind when Integer then worksheets[ind] when String then worksheets.find { |ws| ws.sheet_name == ind } end end
ruby
def [](ind) case ind when Integer then worksheets[ind] when String then worksheets.find { |ws| ws.sheet_name == ind } end end
[ "def", "[]", "(", "ind", ")", "case", "ind", "when", "Integer", "then", "worksheets", "[", "ind", "]", "when", "String", "then", "worksheets", ".", "find", "{", "|", "ws", "|", "ws", ".", "sheet_name", "==", "ind", "}", "end", "end" ]
Finds worksheet by its name or numerical index
[ "Finds", "worksheet", "by", "its", "name", "or", "numerical", "index" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/objects/workbook.rb#L463-L468
train
weshatheleopard/rubyXL
lib/rubyXL/objects/workbook.rb
RubyXL.Workbook.add_worksheet
def add_worksheet(name = nil) if name.nil? then n = 0 begin name = SHEET_NAME_TEMPLATE % (n += 1) end until self[name].nil? end new_worksheet = Worksheet.new(:workbook => self, :sheet_name => name) worksheets << new_worksheet new_worksheet end
ruby
def add_worksheet(name = nil) if name.nil? then n = 0 begin name = SHEET_NAME_TEMPLATE % (n += 1) end until self[name].nil? end new_worksheet = Worksheet.new(:workbook => self, :sheet_name => name) worksheets << new_worksheet new_worksheet end
[ "def", "add_worksheet", "(", "name", "=", "nil", ")", "if", "name", ".", "nil?", "then", "n", "=", "0", "begin", "name", "=", "SHEET_NAME_TEMPLATE", "%", "(", "n", "+=", "1", ")", "end", "until", "self", "[", "name", "]", ".", "nil?", "end", "new_worksheet", "=", "Worksheet", ".", "new", "(", ":workbook", "=>", "self", ",", ":sheet_name", "=>", "name", ")", "worksheets", "<<", "new_worksheet", "new_worksheet", "end" ]
Create new simple worksheet and add it to the workbook worksheets @param [String] The name for the new worksheet
[ "Create", "new", "simple", "worksheet", "and", "add", "it", "to", "the", "workbook", "worksheets" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/objects/workbook.rb#L473-L485
train
weshatheleopard/rubyXL
lib/rubyXL/worksheet.rb
RubyXL.LegacyWorksheet.validate_workbook
def validate_workbook() unless @workbook.nil? || @workbook.worksheets.nil? return if @workbook.worksheets.any? { |sheet| sheet.equal?(self) } end raise "This worksheet #{self} is not in workbook #{@workbook}" end
ruby
def validate_workbook() unless @workbook.nil? || @workbook.worksheets.nil? return if @workbook.worksheets.any? { |sheet| sheet.equal?(self) } end raise "This worksheet #{self} is not in workbook #{@workbook}" end
[ "def", "validate_workbook", "(", ")", "unless", "@workbook", ".", "nil?", "||", "@workbook", ".", "worksheets", ".", "nil?", "return", "if", "@workbook", ".", "worksheets", ".", "any?", "{", "|", "sheet", "|", "sheet", ".", "equal?", "(", "self", ")", "}", "end", "raise", "\"This worksheet #{self} is not in workbook #{@workbook}\"", "end" ]
validates Workbook, ensures that this worksheet is in @workbook
[ "validates", "Workbook", "ensures", "that", "this", "worksheet", "is", "in" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/worksheet.rb#L73-L79
train
weshatheleopard/rubyXL
lib/rubyXL/worksheet.rb
RubyXL.LegacyWorksheet.ensure_cell_exists
def ensure_cell_exists(row_index, column_index = 0) validate_nonnegative(row_index) validate_nonnegative(column_index) sheet_data.rows[row_index] || add_row(row_index) end
ruby
def ensure_cell_exists(row_index, column_index = 0) validate_nonnegative(row_index) validate_nonnegative(column_index) sheet_data.rows[row_index] || add_row(row_index) end
[ "def", "ensure_cell_exists", "(", "row_index", ",", "column_index", "=", "0", ")", "validate_nonnegative", "(", "row_index", ")", "validate_nonnegative", "(", "column_index", ")", "sheet_data", ".", "rows", "[", "row_index", "]", "||", "add_row", "(", "row_index", ")", "end" ]
Ensures that storage space for a cell with +row_index+ and +column_index+ exists in +sheet_data+ arrays, growing them up if necessary.
[ "Ensures", "that", "storage", "space", "for", "a", "cell", "with", "+", "row_index", "+", "and", "+", "column_index", "+", "exists", "in", "+", "sheet_data", "+", "arrays", "growing", "them", "up", "if", "necessary", "." ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/worksheet.rb#L83-L88
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/cell.rb
RubyXL.CellConvenienceMethods.change_fill
def change_fill(rgb = 'ffffff') validate_worksheet Color.validate_color(rgb) self.style_index = workbook.modify_fill(self.style_index, rgb) end
ruby
def change_fill(rgb = 'ffffff') validate_worksheet Color.validate_color(rgb) self.style_index = workbook.modify_fill(self.style_index, rgb) end
[ "def", "change_fill", "(", "rgb", "=", "'ffffff'", ")", "validate_worksheet", "Color", ".", "validate_color", "(", "rgb", ")", "self", ".", "style_index", "=", "workbook", ".", "modify_fill", "(", "self", ".", "style_index", ",", "rgb", ")", "end" ]
Changes fill color of cell
[ "Changes", "fill", "color", "of", "cell" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/cell.rb#L151-L155
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/cell.rb
RubyXL.CellConvenienceMethods.change_font_name
def change_font_name(new_font_name = 'Verdana') validate_worksheet font = get_cell_font.dup font.set_name(new_font_name) update_font_references(font) end
ruby
def change_font_name(new_font_name = 'Verdana') validate_worksheet font = get_cell_font.dup font.set_name(new_font_name) update_font_references(font) end
[ "def", "change_font_name", "(", "new_font_name", "=", "'Verdana'", ")", "validate_worksheet", "font", "=", "get_cell_font", ".", "dup", "font", ".", "set_name", "(", "new_font_name", ")", "update_font_references", "(", "font", ")", "end" ]
Changes font name of cell
[ "Changes", "font", "name", "of", "cell" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/cell.rb#L158-L164
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/cell.rb
RubyXL.CellConvenienceMethods.change_font_size
def change_font_size(font_size = 10) validate_worksheet raise 'Argument must be a number' unless font_size.is_a?(Integer) || font_size.is_a?(Float) font = get_cell_font.dup font.set_size(font_size) update_font_references(font) end
ruby
def change_font_size(font_size = 10) validate_worksheet raise 'Argument must be a number' unless font_size.is_a?(Integer) || font_size.is_a?(Float) font = get_cell_font.dup font.set_size(font_size) update_font_references(font) end
[ "def", "change_font_size", "(", "font_size", "=", "10", ")", "validate_worksheet", "raise", "'Argument must be a number'", "unless", "font_size", ".", "is_a?", "(", "Integer", ")", "||", "font_size", ".", "is_a?", "(", "Float", ")", "font", "=", "get_cell_font", ".", "dup", "font", ".", "set_size", "(", "font_size", ")", "update_font_references", "(", "font", ")", "end" ]
Changes font size of cell
[ "Changes", "font", "size", "of", "cell" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/cell.rb#L167-L174
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/cell.rb
RubyXL.CellConvenienceMethods.change_font_color
def change_font_color(font_color = '000000') validate_worksheet Color.validate_color(font_color) font = get_cell_font.dup font.set_rgb_color(font_color) update_font_references(font) end
ruby
def change_font_color(font_color = '000000') validate_worksheet Color.validate_color(font_color) font = get_cell_font.dup font.set_rgb_color(font_color) update_font_references(font) end
[ "def", "change_font_color", "(", "font_color", "=", "'000000'", ")", "validate_worksheet", "Color", ".", "validate_color", "(", "font_color", ")", "font", "=", "get_cell_font", ".", "dup", "font", ".", "set_rgb_color", "(", "font_color", ")", "update_font_references", "(", "font", ")", "end" ]
Changes font color of cell
[ "Changes", "font", "color", "of", "cell" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/cell.rb#L177-L184
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/cell.rb
RubyXL.CellConvenienceMethods.change_font_italics
def change_font_italics(italicized = false) validate_worksheet font = get_cell_font.dup font.set_italic(italicized) update_font_references(font) end
ruby
def change_font_italics(italicized = false) validate_worksheet font = get_cell_font.dup font.set_italic(italicized) update_font_references(font) end
[ "def", "change_font_italics", "(", "italicized", "=", "false", ")", "validate_worksheet", "font", "=", "get_cell_font", ".", "dup", "font", ".", "set_italic", "(", "italicized", ")", "update_font_references", "(", "font", ")", "end" ]
Changes font italics settings of cell
[ "Changes", "font", "italics", "settings", "of", "cell" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/cell.rb#L187-L193
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/cell.rb
RubyXL.CellConvenienceMethods.change_font_bold
def change_font_bold(bolded = false) validate_worksheet font = get_cell_font.dup font.set_bold(bolded) update_font_references(font) end
ruby
def change_font_bold(bolded = false) validate_worksheet font = get_cell_font.dup font.set_bold(bolded) update_font_references(font) end
[ "def", "change_font_bold", "(", "bolded", "=", "false", ")", "validate_worksheet", "font", "=", "get_cell_font", ".", "dup", "font", ".", "set_bold", "(", "bolded", ")", "update_font_references", "(", "font", ")", "end" ]
Changes font bold settings of cell
[ "Changes", "font", "bold", "settings", "of", "cell" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/cell.rb#L196-L202
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/cell.rb
RubyXL.CellConvenienceMethods.change_font_underline
def change_font_underline(underlined = false) validate_worksheet font = get_cell_font.dup font.set_underline(underlined) update_font_references(font) end
ruby
def change_font_underline(underlined = false) validate_worksheet font = get_cell_font.dup font.set_underline(underlined) update_font_references(font) end
[ "def", "change_font_underline", "(", "underlined", "=", "false", ")", "validate_worksheet", "font", "=", "get_cell_font", ".", "dup", "font", ".", "set_underline", "(", "underlined", ")", "update_font_references", "(", "font", ")", "end" ]
Changes font underline settings of cell
[ "Changes", "font", "underline", "settings", "of", "cell" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/cell.rb#L205-L211
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/cell.rb
RubyXL.CellConvenienceMethods.update_font_references
def update_font_references(modified_font) xf = workbook.register_new_font(modified_font, get_cell_xf) self.style_index = workbook.register_new_xf(xf) end
ruby
def update_font_references(modified_font) xf = workbook.register_new_font(modified_font, get_cell_xf) self.style_index = workbook.register_new_xf(xf) end
[ "def", "update_font_references", "(", "modified_font", ")", "xf", "=", "workbook", ".", "register_new_font", "(", "modified_font", ",", "get_cell_xf", ")", "self", ".", "style_index", "=", "workbook", ".", "register_new_xf", "(", "xf", ")", "end" ]
Helper method to update the font array and xf array
[ "Helper", "method", "to", "update", "the", "font", "array", "and", "xf", "array" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/cell.rb#L222-L225
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/cell.rb
RubyXL.CellConvenienceMethods.font_switch
def font_switch(change_type, arg) case change_type when Worksheet::NAME then change_font_name(arg) when Worksheet::SIZE then change_font_size(arg) when Worksheet::COLOR then change_font_color(arg) when Worksheet::ITALICS then change_font_italics(arg) when Worksheet::BOLD then change_font_bold(arg) when Worksheet::UNDERLINE then change_font_underline(arg) when Worksheet::STRIKETHROUGH then change_font_strikethrough(arg) else raise 'Invalid change_type' end end
ruby
def font_switch(change_type, arg) case change_type when Worksheet::NAME then change_font_name(arg) when Worksheet::SIZE then change_font_size(arg) when Worksheet::COLOR then change_font_color(arg) when Worksheet::ITALICS then change_font_italics(arg) when Worksheet::BOLD then change_font_bold(arg) when Worksheet::UNDERLINE then change_font_underline(arg) when Worksheet::STRIKETHROUGH then change_font_strikethrough(arg) else raise 'Invalid change_type' end end
[ "def", "font_switch", "(", "change_type", ",", "arg", ")", "case", "change_type", "when", "Worksheet", "::", "NAME", "then", "change_font_name", "(", "arg", ")", "when", "Worksheet", "::", "SIZE", "then", "change_font_size", "(", "arg", ")", "when", "Worksheet", "::", "COLOR", "then", "change_font_color", "(", "arg", ")", "when", "Worksheet", "::", "ITALICS", "then", "change_font_italics", "(", "arg", ")", "when", "Worksheet", "::", "BOLD", "then", "change_font_bold", "(", "arg", ")", "when", "Worksheet", "::", "UNDERLINE", "then", "change_font_underline", "(", "arg", ")", "when", "Worksheet", "::", "STRIKETHROUGH", "then", "change_font_strikethrough", "(", "arg", ")", "else", "raise", "'Invalid change_type'", "end", "end" ]
Performs correct modification based on what type of change_type is specified
[ "Performs", "correct", "modification", "based", "on", "what", "type", "of", "change_type", "is", "specified" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/cell.rb#L229-L240
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/worksheet.rb
RubyXL.WorksheetConvenienceMethods.get_column_width_raw
def get_column_width_raw(column_index = 0) validate_workbook validate_nonnegative(column_index) range = cols.locate_range(column_index) range && range.width end
ruby
def get_column_width_raw(column_index = 0) validate_workbook validate_nonnegative(column_index) range = cols.locate_range(column_index) range && range.width end
[ "def", "get_column_width_raw", "(", "column_index", "=", "0", ")", "validate_workbook", "validate_nonnegative", "(", "column_index", ")", "range", "=", "cols", ".", "locate_range", "(", "column_index", ")", "range", "&&", "range", ".", "width", "end" ]
Get raw column width value as stored in the file
[ "Get", "raw", "column", "width", "value", "as", "stored", "in", "the", "file" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/worksheet.rb#L293-L299
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/worksheet.rb
RubyXL.WorksheetConvenienceMethods.change_column_width_raw
def change_column_width_raw(column_index, width) validate_workbook ensure_cell_exists(0, column_index) range = cols.get_range(column_index) range.width = width range.custom_width = true end
ruby
def change_column_width_raw(column_index, width) validate_workbook ensure_cell_exists(0, column_index) range = cols.get_range(column_index) range.width = width range.custom_width = true end
[ "def", "change_column_width_raw", "(", "column_index", ",", "width", ")", "validate_workbook", "ensure_cell_exists", "(", "0", ",", "column_index", ")", "range", "=", "cols", ".", "get_range", "(", "column_index", ")", "range", ".", "width", "=", "width", "range", ".", "custom_width", "=", "true", "end" ]
Set raw column width value
[ "Set", "raw", "column", "width", "value" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/worksheet.rb#L310-L316
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/worksheet.rb
RubyXL.WorksheetConvenienceMethods.change_row_font
def change_row_font(row_index, change_type, arg, font) validate_workbook ensure_cell_exists(row_index) xf = workbook.register_new_font(font, get_row_xf(row_index)) row = sheet_data[row_index] row.style_index = workbook.register_new_xf(xf) row.cells.each { |c| c.font_switch(change_type, arg) unless c.nil? } end
ruby
def change_row_font(row_index, change_type, arg, font) validate_workbook ensure_cell_exists(row_index) xf = workbook.register_new_font(font, get_row_xf(row_index)) row = sheet_data[row_index] row.style_index = workbook.register_new_xf(xf) row.cells.each { |c| c.font_switch(change_type, arg) unless c.nil? } end
[ "def", "change_row_font", "(", "row_index", ",", "change_type", ",", "arg", ",", "font", ")", "validate_workbook", "ensure_cell_exists", "(", "row_index", ")", "xf", "=", "workbook", ".", "register_new_font", "(", "font", ",", "get_row_xf", "(", "row_index", ")", ")", "row", "=", "sheet_data", "[", "row_index", "]", "row", ".", "style_index", "=", "workbook", ".", "register_new_xf", "(", "xf", ")", "row", ".", "cells", ".", "each", "{", "|", "c", "|", "c", ".", "font_switch", "(", "change_type", ",", "arg", ")", "unless", "c", ".", "nil?", "}", "end" ]
Helper method to update the row styles array change_type - NAME or SIZE or COLOR etc main method to change font, called from each separate font mutator method
[ "Helper", "method", "to", "update", "the", "row", "styles", "array", "change_type", "-", "NAME", "or", "SIZE", "or", "COLOR", "etc", "main", "method", "to", "change", "font", "called", "from", "each", "separate", "font", "mutator", "method" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/worksheet.rb#L428-L436
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/worksheet.rb
RubyXL.WorksheetConvenienceMethods.change_column_font
def change_column_font(column_index, change_type, arg, font, xf) validate_workbook ensure_cell_exists(0, column_index) xf = workbook.register_new_font(font, xf) cols.get_range(column_index).style_index = workbook.register_new_xf(xf) sheet_data.rows.each { |row| c = row && row[column_index] c.font_switch(change_type, arg) unless c.nil? } end
ruby
def change_column_font(column_index, change_type, arg, font, xf) validate_workbook ensure_cell_exists(0, column_index) xf = workbook.register_new_font(font, xf) cols.get_range(column_index).style_index = workbook.register_new_xf(xf) sheet_data.rows.each { |row| c = row && row[column_index] c.font_switch(change_type, arg) unless c.nil? } end
[ "def", "change_column_font", "(", "column_index", ",", "change_type", ",", "arg", ",", "font", ",", "xf", ")", "validate_workbook", "ensure_cell_exists", "(", "0", ",", "column_index", ")", "xf", "=", "workbook", ".", "register_new_font", "(", "font", ",", "xf", ")", "cols", ".", "get_range", "(", "column_index", ")", ".", "style_index", "=", "workbook", ".", "register_new_xf", "(", "xf", ")", "sheet_data", ".", "rows", ".", "each", "{", "|", "row", "|", "c", "=", "row", "&&", "row", "[", "column_index", "]", "c", ".", "font_switch", "(", "change_type", ",", "arg", ")", "unless", "c", ".", "nil?", "}", "end" ]
Helper method to update the fonts and cell styles array main method to change font, called from each separate font mutator method
[ "Helper", "method", "to", "update", "the", "fonts", "and", "cell", "styles", "array", "main", "method", "to", "change", "font", "called", "from", "each", "separate", "font", "mutator", "method" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/worksheet.rb#L499-L510
train
weshatheleopard/rubyXL
lib/rubyXL/convenience_methods/worksheet.rb
RubyXL.WorksheetConvenienceMethods.merge_cells
def merge_cells(start_row, start_col, end_row, end_col) validate_workbook self.merged_cells ||= RubyXL::MergedCells.new # TODO: add validation to make sure ranges are not intersecting with existing ones merged_cells << RubyXL::MergedCell.new(:ref => RubyXL::Reference.new(start_row, end_row, start_col, end_col)) end
ruby
def merge_cells(start_row, start_col, end_row, end_col) validate_workbook self.merged_cells ||= RubyXL::MergedCells.new # TODO: add validation to make sure ranges are not intersecting with existing ones merged_cells << RubyXL::MergedCell.new(:ref => RubyXL::Reference.new(start_row, end_row, start_col, end_col)) end
[ "def", "merge_cells", "(", "start_row", ",", "start_col", ",", "end_row", ",", "end_col", ")", "validate_workbook", "self", ".", "merged_cells", "||=", "RubyXL", "::", "MergedCells", ".", "new", "# TODO: add validation to make sure ranges are not intersecting with existing ones", "merged_cells", "<<", "RubyXL", "::", "MergedCell", ".", "new", "(", ":ref", "=>", "RubyXL", "::", "Reference", ".", "new", "(", "start_row", ",", "end_row", ",", "start_col", ",", "end_col", ")", ")", "end" ]
Merges cells within a rectangular area
[ "Merges", "cells", "within", "a", "rectangular", "area" ]
e61d78de9486316cdee039d3590177dc05db0f0c
https://github.com/weshatheleopard/rubyXL/blob/e61d78de9486316cdee039d3590177dc05db0f0c/lib/rubyXL/convenience_methods/worksheet.rb#L628-L634
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.environment_variables
def environment_variables vars = @process.environment_variables.merge({ 'PROC_NAME' => self.description, 'PID_FILE' => self.pid_file_path, 'APP_ROOT' => @process.config.root }) vars['PORT'] = @port.to_s if @port vars end
ruby
def environment_variables vars = @process.environment_variables.merge({ 'PROC_NAME' => self.description, 'PID_FILE' => self.pid_file_path, 'APP_ROOT' => @process.config.root }) vars['PORT'] = @port.to_s if @port vars end
[ "def", "environment_variables", "vars", "=", "@process", ".", "environment_variables", ".", "merge", "(", "{", "'PROC_NAME'", "=>", "self", ".", "description", ",", "'PID_FILE'", "=>", "self", ".", "pid_file_path", ",", "'APP_ROOT'", "=>", "@process", ".", "config", ".", "root", "}", ")", "vars", "[", "'PORT'", "]", "=", "@port", ".", "to_s", "if", "@port", "vars", "end" ]
Return an array of environment variables that should be set
[ "Return", "an", "array", "of", "environment", "variables", "that", "should", "be", "set" ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L58-L66
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.pid_from_file
def pid_from_file if File.exist?(pid_file_path) pid = File.read(pid_file_path) pid.length > 0 ? pid.strip.to_i : nil else nil end end
ruby
def pid_from_file if File.exist?(pid_file_path) pid = File.read(pid_file_path) pid.length > 0 ? pid.strip.to_i : nil else nil end end
[ "def", "pid_from_file", "if", "File", ".", "exist?", "(", "pid_file_path", ")", "pid", "=", "File", ".", "read", "(", "pid_file_path", ")", "pid", ".", "length", ">", "0", "?", "pid", ".", "strip", ".", "to_i", ":", "nil", "else", "nil", "end", "end" ]
Return the PID that is in the instances process PID file
[ "Return", "the", "PID", "that", "is", "in", "the", "instances", "process", "PID", "file" ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L78-L85
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.start
def start if stopping? Procodile.log(@process.log_color, description, "Process is stopped/stopping therefore cannot be started again.") return false end update_pid if running? Procodile.log(@process.log_color, description, "Already running with PID #{@pid}") nil else if @supervisor.run_options[:port_allocations] && chosen_port = @supervisor.run_options[:port_allocations][@process.name] if chosen_port == 0 allocate_port else @port = chosen_port Procodile.log(@process.log_color, description, "Assigned #{chosen_port} to process") end elsif @process.proxy? && @supervisor.tcp_proxy # Allocate a port randomly if a proxy is needed allocate_port elsif @process.allocate_port_from && @process.restart_mode != 'start-term' # Allocate ports to this process sequentially from the starting port allocated_ports = (@supervisor.processes[@process] ? @supervisor.processes[@process].select(&:running?) : []).map(&:port) proposed_port = @process.allocate_port_from until @port unless allocated_ports.include?(proposed_port) @port = proposed_port end proposed_port += 1 end end if self.process.log_path && @supervisor.run_options[:force_single_log] != true log_destination = File.open(self.process.log_path, 'a') io = nil else reader, writer = IO.pipe log_destination = writer io = reader end @tag = @supervisor.tag.dup if @supervisor.tag Dir.chdir(@process.config.root) without_rbenv do @pid = ::Process.spawn(environment_variables, @process.command, :out => log_destination, :err => log_destination, :pgroup => true) end log_destination.close File.open(pid_file_path, 'w') { |f| f.write(@pid.to_s + "\n") } @supervisor.add_instance(self, io) ::Process.detach(@pid) Procodile.log(@process.log_color, description, "Started with PID #{@pid}" + (@tag ? " (tagged with #{@tag})" : '')) if self.process.log_path && io.nil? Procodile.log(@process.log_color, description, "Logging to #{self.process.log_path}") end @started_at = Time.now end end
ruby
def start if stopping? Procodile.log(@process.log_color, description, "Process is stopped/stopping therefore cannot be started again.") return false end update_pid if running? Procodile.log(@process.log_color, description, "Already running with PID #{@pid}") nil else if @supervisor.run_options[:port_allocations] && chosen_port = @supervisor.run_options[:port_allocations][@process.name] if chosen_port == 0 allocate_port else @port = chosen_port Procodile.log(@process.log_color, description, "Assigned #{chosen_port} to process") end elsif @process.proxy? && @supervisor.tcp_proxy # Allocate a port randomly if a proxy is needed allocate_port elsif @process.allocate_port_from && @process.restart_mode != 'start-term' # Allocate ports to this process sequentially from the starting port allocated_ports = (@supervisor.processes[@process] ? @supervisor.processes[@process].select(&:running?) : []).map(&:port) proposed_port = @process.allocate_port_from until @port unless allocated_ports.include?(proposed_port) @port = proposed_port end proposed_port += 1 end end if self.process.log_path && @supervisor.run_options[:force_single_log] != true log_destination = File.open(self.process.log_path, 'a') io = nil else reader, writer = IO.pipe log_destination = writer io = reader end @tag = @supervisor.tag.dup if @supervisor.tag Dir.chdir(@process.config.root) without_rbenv do @pid = ::Process.spawn(environment_variables, @process.command, :out => log_destination, :err => log_destination, :pgroup => true) end log_destination.close File.open(pid_file_path, 'w') { |f| f.write(@pid.to_s + "\n") } @supervisor.add_instance(self, io) ::Process.detach(@pid) Procodile.log(@process.log_color, description, "Started with PID #{@pid}" + (@tag ? " (tagged with #{@tag})" : '')) if self.process.log_path && io.nil? Procodile.log(@process.log_color, description, "Logging to #{self.process.log_path}") end @started_at = Time.now end end
[ "def", "start", "if", "stopping?", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Process is stopped/stopping therefore cannot be started again.\"", ")", "return", "false", "end", "update_pid", "if", "running?", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Already running with PID #{@pid}\"", ")", "nil", "else", "if", "@supervisor", ".", "run_options", "[", ":port_allocations", "]", "&&", "chosen_port", "=", "@supervisor", ".", "run_options", "[", ":port_allocations", "]", "[", "@process", ".", "name", "]", "if", "chosen_port", "==", "0", "allocate_port", "else", "@port", "=", "chosen_port", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Assigned #{chosen_port} to process\"", ")", "end", "elsif", "@process", ".", "proxy?", "&&", "@supervisor", ".", "tcp_proxy", "# Allocate a port randomly if a proxy is needed", "allocate_port", "elsif", "@process", ".", "allocate_port_from", "&&", "@process", ".", "restart_mode", "!=", "'start-term'", "# Allocate ports to this process sequentially from the starting port", "allocated_ports", "=", "(", "@supervisor", ".", "processes", "[", "@process", "]", "?", "@supervisor", ".", "processes", "[", "@process", "]", ".", "select", "(", ":running?", ")", ":", "[", "]", ")", ".", "map", "(", ":port", ")", "proposed_port", "=", "@process", ".", "allocate_port_from", "until", "@port", "unless", "allocated_ports", ".", "include?", "(", "proposed_port", ")", "@port", "=", "proposed_port", "end", "proposed_port", "+=", "1", "end", "end", "if", "self", ".", "process", ".", "log_path", "&&", "@supervisor", ".", "run_options", "[", ":force_single_log", "]", "!=", "true", "log_destination", "=", "File", ".", "open", "(", "self", ".", "process", ".", "log_path", ",", "'a'", ")", "io", "=", "nil", "else", "reader", ",", "writer", "=", "IO", ".", "pipe", "log_destination", "=", "writer", "io", "=", "reader", "end", "@tag", "=", "@supervisor", ".", "tag", ".", "dup", "if", "@supervisor", ".", "tag", "Dir", ".", "chdir", "(", "@process", ".", "config", ".", "root", ")", "without_rbenv", "do", "@pid", "=", "::", "Process", ".", "spawn", "(", "environment_variables", ",", "@process", ".", "command", ",", ":out", "=>", "log_destination", ",", ":err", "=>", "log_destination", ",", ":pgroup", "=>", "true", ")", "end", "log_destination", ".", "close", "File", ".", "open", "(", "pid_file_path", ",", "'w'", ")", "{", "|", "f", "|", "f", ".", "write", "(", "@pid", ".", "to_s", "+", "\"\\n\"", ")", "}", "@supervisor", ".", "add_instance", "(", "self", ",", "io", ")", "::", "Process", ".", "detach", "(", "@pid", ")", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Started with PID #{@pid}\"", "+", "(", "@tag", "?", "\" (tagged with #{@tag})\"", ":", "''", ")", ")", "if", "self", ".", "process", ".", "log_path", "&&", "io", ".", "nil?", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Logging to #{self.process.log_path}\"", ")", "end", "@started_at", "=", "Time", ".", "now", "end", "end" ]
Start a new instance of this process
[ "Start", "a", "new", "instance", "of", "this", "process" ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L103-L159
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.stop
def stop @stopping = Time.now update_pid if self.running? Procodile.log(@process.log_color, description, "Sending #{@process.term_signal} to #{@pid}") ::Process.kill(@process.term_signal, pid) else Procodile.log(@process.log_color, description, "Process already stopped") end end
ruby
def stop @stopping = Time.now update_pid if self.running? Procodile.log(@process.log_color, description, "Sending #{@process.term_signal} to #{@pid}") ::Process.kill(@process.term_signal, pid) else Procodile.log(@process.log_color, description, "Process already stopped") end end
[ "def", "stop", "@stopping", "=", "Time", ".", "now", "update_pid", "if", "self", ".", "running?", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Sending #{@process.term_signal} to #{@pid}\"", ")", "::", "Process", ".", "kill", "(", "@process", ".", "term_signal", ",", "pid", ")", "else", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Process already stopped\"", ")", "end", "end" ]
Send this signal the signal to stop and mark the instance in a state that tells us that we want it to be stopped.
[ "Send", "this", "signal", "the", "signal", "to", "stop", "and", "mark", "the", "instance", "in", "a", "state", "that", "tells", "us", "that", "we", "want", "it", "to", "be", "stopped", "." ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L186-L195
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.restart
def restart Procodile.log(@process.log_color, description, "Restarting using #{@process.restart_mode} mode") update_pid case @process.restart_mode when 'usr1', 'usr2' if running? ::Process.kill(@process.restart_mode.upcase, @pid) @tag = @supervisor.tag if @supervisor.tag Procodile.log(@process.log_color, description, "Sent #{@process.restart_mode.upcase} signal to process #{@pid}") else Procodile.log(@process.log_color, description, "Process not running already. Starting it.") on_stop new_instance = @process.create_instance(@supervisor) new_instance.port = self.port new_instance.start end self when 'start-term' new_instance = @process.create_instance(@supervisor) new_instance.start stop new_instance when 'term-start' stop new_instance = @process.create_instance(@supervisor) new_instance.port = self.port Thread.new do sleep 0.5 while running? new_instance.start end new_instance end end
ruby
def restart Procodile.log(@process.log_color, description, "Restarting using #{@process.restart_mode} mode") update_pid case @process.restart_mode when 'usr1', 'usr2' if running? ::Process.kill(@process.restart_mode.upcase, @pid) @tag = @supervisor.tag if @supervisor.tag Procodile.log(@process.log_color, description, "Sent #{@process.restart_mode.upcase} signal to process #{@pid}") else Procodile.log(@process.log_color, description, "Process not running already. Starting it.") on_stop new_instance = @process.create_instance(@supervisor) new_instance.port = self.port new_instance.start end self when 'start-term' new_instance = @process.create_instance(@supervisor) new_instance.start stop new_instance when 'term-start' stop new_instance = @process.create_instance(@supervisor) new_instance.port = self.port Thread.new do sleep 0.5 while running? new_instance.start end new_instance end end
[ "def", "restart", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Restarting using #{@process.restart_mode} mode\"", ")", "update_pid", "case", "@process", ".", "restart_mode", "when", "'usr1'", ",", "'usr2'", "if", "running?", "::", "Process", ".", "kill", "(", "@process", ".", "restart_mode", ".", "upcase", ",", "@pid", ")", "@tag", "=", "@supervisor", ".", "tag", "if", "@supervisor", ".", "tag", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Sent #{@process.restart_mode.upcase} signal to process #{@pid}\"", ")", "else", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Process not running already. Starting it.\"", ")", "on_stop", "new_instance", "=", "@process", ".", "create_instance", "(", "@supervisor", ")", "new_instance", ".", "port", "=", "self", ".", "port", "new_instance", ".", "start", "end", "self", "when", "'start-term'", "new_instance", "=", "@process", ".", "create_instance", "(", "@supervisor", ")", "new_instance", ".", "start", "stop", "new_instance", "when", "'term-start'", "stop", "new_instance", "=", "@process", ".", "create_instance", "(", "@supervisor", ")", "new_instance", ".", "port", "=", "self", ".", "port", "Thread", ".", "new", "do", "sleep", "0.5", "while", "running?", "new_instance", ".", "start", "end", "new_instance", "end", "end" ]
Retarts the process using the appropriate method from the process configuraiton
[ "Retarts", "the", "process", "using", "the", "appropriate", "method", "from", "the", "process", "configuraiton" ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L218-L250
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.update_pid
def update_pid pid_from_file = self.pid_from_file if pid_from_file && pid_from_file != @pid @pid = pid_from_file @started_at = File.mtime(self.pid_file_path) Procodile.log(@process.log_color, description, "PID file changed. Updated pid to #{@pid}") true else false end end
ruby
def update_pid pid_from_file = self.pid_from_file if pid_from_file && pid_from_file != @pid @pid = pid_from_file @started_at = File.mtime(self.pid_file_path) Procodile.log(@process.log_color, description, "PID file changed. Updated pid to #{@pid}") true else false end end
[ "def", "update_pid", "pid_from_file", "=", "self", ".", "pid_from_file", "if", "pid_from_file", "&&", "pid_from_file", "!=", "@pid", "@pid", "=", "pid_from_file", "@started_at", "=", "File", ".", "mtime", "(", "self", ".", "pid_file_path", ")", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"PID file changed. Updated pid to #{@pid}\"", ")", "true", "else", "false", "end", "end" ]
Update the locally cached PID from that stored on the file system.
[ "Update", "the", "locally", "cached", "PID", "from", "that", "stored", "on", "the", "file", "system", "." ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L255-L265
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.check
def check(options = {}) return if failed? if self.running? # Everything is OK. The process is running. true else # If the process isn't running any more, update the PID in our memory from # the file in case the process has changed itself. return check if update_pid if @supervisor.allow_respawning? if can_respawn? Procodile.log(@process.log_color, description, "Process has stopped. Respawning...") start add_respawn elsif respawns >= @process.max_respawns Procodile.log(@process.log_color, description, "\e[41;37mWarning:\e[0m\e[31m this process has been respawned #{respawns} times and keeps dying.\e[0m") Procodile.log(@process.log_color, description, "It will not be respawned automatically any longer and will no longer be managed.".color(31)) @failed = Time.now tidy end else Procodile.log(@process.log_color, description, "Process has stopped. Respawning not available.") @failed = Time.now tidy end end end
ruby
def check(options = {}) return if failed? if self.running? # Everything is OK. The process is running. true else # If the process isn't running any more, update the PID in our memory from # the file in case the process has changed itself. return check if update_pid if @supervisor.allow_respawning? if can_respawn? Procodile.log(@process.log_color, description, "Process has stopped. Respawning...") start add_respawn elsif respawns >= @process.max_respawns Procodile.log(@process.log_color, description, "\e[41;37mWarning:\e[0m\e[31m this process has been respawned #{respawns} times and keeps dying.\e[0m") Procodile.log(@process.log_color, description, "It will not be respawned automatically any longer and will no longer be managed.".color(31)) @failed = Time.now tidy end else Procodile.log(@process.log_color, description, "Process has stopped. Respawning not available.") @failed = Time.now tidy end end end
[ "def", "check", "(", "options", "=", "{", "}", ")", "return", "if", "failed?", "if", "self", ".", "running?", "# Everything is OK. The process is running.", "true", "else", "# If the process isn't running any more, update the PID in our memory from", "# the file in case the process has changed itself.", "return", "check", "if", "update_pid", "if", "@supervisor", ".", "allow_respawning?", "if", "can_respawn?", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Process has stopped. Respawning...\"", ")", "start", "add_respawn", "elsif", "respawns", ">=", "@process", ".", "max_respawns", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"\\e[41;37mWarning:\\e[0m\\e[31m this process has been respawned #{respawns} times and keeps dying.\\e[0m\"", ")", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"It will not be respawned automatically any longer and will no longer be managed.\"", ".", "color", "(", "31", ")", ")", "@failed", "=", "Time", ".", "now", "tidy", "end", "else", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Process has stopped. Respawning not available.\"", ")", "@failed", "=", "Time", ".", "now", "tidy", "end", "end", "end" ]
Check the status of this process and handle as appropriate.
[ "Check", "the", "status", "of", "this", "process", "and", "handle", "as", "appropriate", "." ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L270-L298
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.allocate_port
def allocate_port(max_attempts = 10) attempts = 0 until @port attempts += 1 possible_port = rand(10000) + 20000 if self.port_available?(possible_port) Procodile.log(@process.log_color, description, "Allocated port as #{possible_port}") return @port = possible_port elsif attempts >= max_attempts raise Procodile::Error, "Couldn't allocate port for #{instance.name}" end end end
ruby
def allocate_port(max_attempts = 10) attempts = 0 until @port attempts += 1 possible_port = rand(10000) + 20000 if self.port_available?(possible_port) Procodile.log(@process.log_color, description, "Allocated port as #{possible_port}") return @port = possible_port elsif attempts >= max_attempts raise Procodile::Error, "Couldn't allocate port for #{instance.name}" end end end
[ "def", "allocate_port", "(", "max_attempts", "=", "10", ")", "attempts", "=", "0", "until", "@port", "attempts", "+=", "1", "possible_port", "=", "rand", "(", "10000", ")", "+", "20000", "if", "self", ".", "port_available?", "(", "possible_port", ")", "Procodile", ".", "log", "(", "@process", ".", "log_color", ",", "description", ",", "\"Allocated port as #{possible_port}\"", ")", "return", "@port", "=", "possible_port", "elsif", "attempts", ">=", "max_attempts", "raise", "Procodile", "::", "Error", ",", "\"Couldn't allocate port for #{instance.name}\"", "end", "end", "end" ]
Find a port number for this instance to listen on. We just check that nothing is already listening on it. The process is expected to take it straight away if it wants it.
[ "Find", "a", "port", "number", "for", "this", "instance", "to", "listen", "on", ".", "We", "just", "check", "that", "nothing", "is", "already", "listening", "on", "it", ".", "The", "process", "is", "expected", "to", "take", "it", "straight", "away", "if", "it", "wants", "it", "." ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L351-L363
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.port_available?
def port_available?(port) case @process.network_protocol when 'tcp' server = TCPServer.new('127.0.0.1', port) server.close true when 'udp' server = UDPSocket.new server.bind('127.0.0.1', port) server.close true else raise Procodile::Error, "Invalid network_protocol '#{@process.network_protocol}'" end rescue Errno::EADDRINUSE => e false end
ruby
def port_available?(port) case @process.network_protocol when 'tcp' server = TCPServer.new('127.0.0.1', port) server.close true when 'udp' server = UDPSocket.new server.bind('127.0.0.1', port) server.close true else raise Procodile::Error, "Invalid network_protocol '#{@process.network_protocol}'" end rescue Errno::EADDRINUSE => e false end
[ "def", "port_available?", "(", "port", ")", "case", "@process", ".", "network_protocol", "when", "'tcp'", "server", "=", "TCPServer", ".", "new", "(", "'127.0.0.1'", ",", "port", ")", "server", ".", "close", "true", "when", "'udp'", "server", "=", "UDPSocket", ".", "new", "server", ".", "bind", "(", "'127.0.0.1'", ",", "port", ")", "server", ".", "close", "true", "else", "raise", "Procodile", "::", "Error", ",", "\"Invalid network_protocol '#{@process.network_protocol}'\"", "end", "rescue", "Errno", "::", "EADDRINUSE", "=>", "e", "false", "end" ]
Is the given port available?
[ "Is", "the", "given", "port", "available?" ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L368-L384
train
adamcooke/procodile
lib/procodile/instance.rb
Procodile.Instance.without_rbenv
def without_rbenv(&block) previous_environment = ENV.select { |k,v| k =~ /\A(RBENV\_)/ } if previous_environment.size > 0 previous_environment.each { |key, value| ENV[key] = nil } previous_environment['PATH'] = ENV['PATH'] ENV['PATH'] = ENV['PATH'].split(':').select { |p| !(p =~ /\.rbenv\/versions/) }.join(':') end yield ensure previous_environment.each do |key, value| ENV[key] = value end end
ruby
def without_rbenv(&block) previous_environment = ENV.select { |k,v| k =~ /\A(RBENV\_)/ } if previous_environment.size > 0 previous_environment.each { |key, value| ENV[key] = nil } previous_environment['PATH'] = ENV['PATH'] ENV['PATH'] = ENV['PATH'].split(':').select { |p| !(p =~ /\.rbenv\/versions/) }.join(':') end yield ensure previous_environment.each do |key, value| ENV[key] = value end end
[ "def", "without_rbenv", "(", "&", "block", ")", "previous_environment", "=", "ENV", ".", "select", "{", "|", "k", ",", "v", "|", "k", "=~", "/", "\\A", "\\_", "/", "}", "if", "previous_environment", ".", "size", ">", "0", "previous_environment", ".", "each", "{", "|", "key", ",", "value", "|", "ENV", "[", "key", "]", "=", "nil", "}", "previous_environment", "[", "'PATH'", "]", "=", "ENV", "[", "'PATH'", "]", "ENV", "[", "'PATH'", "]", "=", "ENV", "[", "'PATH'", "]", ".", "split", "(", "':'", ")", ".", "select", "{", "|", "p", "|", "!", "(", "p", "=~", "/", "\\.", "\\/", "/", ")", "}", ".", "join", "(", "':'", ")", "end", "yield", "ensure", "previous_environment", ".", "each", "do", "|", "key", ",", "value", "|", "ENV", "[", "key", "]", "=", "value", "end", "end" ]
If procodile is executed through rbenv it will pollute our environment which means that any spawned processes will be invoked with procodile's ruby rather than the ruby that the application wishes to use
[ "If", "procodile", "is", "executed", "through", "rbenv", "it", "will", "pollute", "our", "environment", "which", "means", "that", "any", "spawned", "processes", "will", "be", "invoked", "with", "procodile", "s", "ruby", "rather", "than", "the", "ruby", "that", "the", "application", "wishes", "to", "use" ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/instance.rb#L391-L403
train
adamcooke/procodile
lib/procodile/process.rb
Procodile.Process.environment_variables
def environment_variables global_variables = @config.environment_variables process_vars = @config.process_options[@name] ? @config.process_options[@name]['env'] || {} : {} process_local_vars = @config.local_process_options[@name] ? @config.local_process_options[@name]['env'] || {} : {} global_variables.merge(process_vars.merge(process_local_vars)).each_with_object({}) do |(key, value), hash| hash[key.to_s] = value.to_s end end
ruby
def environment_variables global_variables = @config.environment_variables process_vars = @config.process_options[@name] ? @config.process_options[@name]['env'] || {} : {} process_local_vars = @config.local_process_options[@name] ? @config.local_process_options[@name]['env'] || {} : {} global_variables.merge(process_vars.merge(process_local_vars)).each_with_object({}) do |(key, value), hash| hash[key.to_s] = value.to_s end end
[ "def", "environment_variables", "global_variables", "=", "@config", ".", "environment_variables", "process_vars", "=", "@config", ".", "process_options", "[", "@name", "]", "?", "@config", ".", "process_options", "[", "@name", "]", "[", "'env'", "]", "||", "{", "}", ":", "{", "}", "process_local_vars", "=", "@config", ".", "local_process_options", "[", "@name", "]", "?", "@config", ".", "local_process_options", "[", "@name", "]", "[", "'env'", "]", "||", "{", "}", ":", "{", "}", "global_variables", ".", "merge", "(", "process_vars", ".", "merge", "(", "process_local_vars", ")", ")", ".", "each_with_object", "(", "{", "}", ")", "do", "|", "(", "key", ",", "value", ")", ",", "hash", "|", "hash", "[", "key", ".", "to_s", "]", "=", "value", ".", "to_s", "end", "end" ]
Return all environment variables for this process
[ "Return", "all", "environment", "variables", "for", "this", "process" ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/process.rb#L37-L44
train
adamcooke/procodile
lib/procodile/process.rb
Procodile.Process.to_hash
def to_hash { :name => self.name, :log_color => self.log_color, :quantity => self.quantity, :max_respawns => self.max_respawns, :respawn_window => self.respawn_window, :command => self.command, :restart_mode => self.restart_mode, :log_path => self.log_path, :removed => self.removed ? true : false, :proxy_port => proxy_port, :proxy_address => proxy_address } end
ruby
def to_hash { :name => self.name, :log_color => self.log_color, :quantity => self.quantity, :max_respawns => self.max_respawns, :respawn_window => self.respawn_window, :command => self.command, :restart_mode => self.restart_mode, :log_path => self.log_path, :removed => self.removed ? true : false, :proxy_port => proxy_port, :proxy_address => proxy_address } end
[ "def", "to_hash", "{", ":name", "=>", "self", ".", "name", ",", ":log_color", "=>", "self", ".", "log_color", ",", ":quantity", "=>", "self", ".", "quantity", ",", ":max_respawns", "=>", "self", ".", "max_respawns", ",", ":respawn_window", "=>", "self", ".", "respawn_window", ",", ":command", "=>", "self", ".", "command", ",", ":restart_mode", "=>", "self", ".", "restart_mode", ",", ":log_path", "=>", "self", ".", "log_path", ",", ":removed", "=>", "self", ".", "removed", "?", "true", ":", "false", ",", ":proxy_port", "=>", "proxy_port", ",", ":proxy_address", "=>", "proxy_address", "}", "end" ]
Return a hash
[ "Return", "a", "hash" ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/process.rb#L165-L179
train
adamcooke/procodile
lib/procodile/app_determination.rb
Procodile.AppDetermination.app_options
def app_options if ambiguous? hash = {} @global_options.each_with_index do |option, i| hash[i] = option['name'] || option['root'] end hash else {} end end
ruby
def app_options if ambiguous? hash = {} @global_options.each_with_index do |option, i| hash[i] = option['name'] || option['root'] end hash else {} end end
[ "def", "app_options", "if", "ambiguous?", "hash", "=", "{", "}", "@global_options", ".", "each_with_index", "do", "|", "option", ",", "i", "|", "hash", "[", "i", "]", "=", "option", "[", "'name'", "]", "||", "option", "[", "'root'", "]", "end", "hash", "else", "{", "}", "end", "end" ]
Return an hash of possible options to settle the ambiguity
[ "Return", "an", "hash", "of", "possible", "options", "to", "settle", "the", "ambiguity" ]
57f42940715cba7186f0ce82b9bc4763f384cf2a
https://github.com/adamcooke/procodile/blob/57f42940715cba7186f0ce82b9bc4763f384cf2a/lib/procodile/app_determination.rb#L49-L59
train
rom-rb/rom
core/lib/rom/pipeline.rb
ROM.Pipeline.map_with
def map_with(*names) [self, *names.map { |name| mappers[name] }] .reduce { |a, e| composite_class.new(a, e) } end
ruby
def map_with(*names) [self, *names.map { |name| mappers[name] }] .reduce { |a, e| composite_class.new(a, e) } end
[ "def", "map_with", "(", "*", "names", ")", "[", "self", ",", "names", ".", "map", "{", "|", "name", "|", "mappers", "[", "name", "]", "}", "]", ".", "reduce", "{", "|", "a", ",", "e", "|", "composite_class", ".", "new", "(", "a", ",", "e", ")", "}", "end" ]
Send data through specified mappers @return [Relation::Composite] @api public
[ "Send", "data", "through", "specified", "mappers" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/pipeline.rb#L41-L44
train
rom-rb/rom
core/lib/rom/plugin_registry.rb
ROM.PluginRegistry.plugins_for
def plugins_for(type, adapter) case type when :configuration then configuration when :command then commands.adapter(adapter) when :mapper then mappers.adapter(adapter) when :relation then relations.adapter(adapter) when :schema then schemas.adapter(adapter) end end
ruby
def plugins_for(type, adapter) case type when :configuration then configuration when :command then commands.adapter(adapter) when :mapper then mappers.adapter(adapter) when :relation then relations.adapter(adapter) when :schema then schemas.adapter(adapter) end end
[ "def", "plugins_for", "(", "type", ",", "adapter", ")", "case", "type", "when", ":configuration", "then", "configuration", "when", ":command", "then", "commands", ".", "adapter", "(", "adapter", ")", "when", ":mapper", "then", "mappers", ".", "adapter", "(", "adapter", ")", "when", ":relation", "then", "relations", ".", "adapter", "(", "adapter", ")", "when", ":schema", "then", "schemas", ".", "adapter", "(", "adapter", ")", "end", "end" ]
Determine which specific registry to use @api private
[ "Determine", "which", "specific", "registry", "to", "use" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/plugin_registry.rb#L75-L83
train
rom-rb/rom
core/lib/rom/plugin_registry.rb
ROM.PluginRegistryBase.register
def register(name, mod, options) elements[name] = plugin_type.new(mod, options) end
ruby
def register(name, mod, options) elements[name] = plugin_type.new(mod, options) end
[ "def", "register", "(", "name", ",", "mod", ",", "options", ")", "elements", "[", "name", "]", "=", "plugin_type", ".", "new", "(", "mod", ",", "options", ")", "end" ]
Assign a plugin to this environment registry @param [Symbol] name The registered plugin name @param [Module] mod The plugin to register @param [Hash] options optional configuration data @api private
[ "Assign", "a", "plugin", "to", "this", "environment", "registry" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/plugin_registry.rb#L114-L116
train
rom-rb/rom
core/lib/rom/plugin_registry.rb
ROM.PluginRegistryBase.plugin_name
def plugin_name(plugin) tuple = elements.find { |(_, p)| p.equal?(plugin) } tuple[0] if tuple end
ruby
def plugin_name(plugin) tuple = elements.find { |(_, p)| p.equal?(plugin) } tuple[0] if tuple end
[ "def", "plugin_name", "(", "plugin", ")", "tuple", "=", "elements", ".", "find", "{", "|", "(", "_", ",", "p", ")", "|", "p", ".", "equal?", "(", "plugin", ")", "}", "tuple", "[", "0", "]", "if", "tuple", "end" ]
Returns plugin name by instance @return [Symbol] Plugin name @api private
[ "Returns", "plugin", "name", "by", "instance" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/plugin_registry.rb#L123-L126
train
rom-rb/rom
core/lib/rom/plugin_registry.rb
ROM.InternalPluginRegistry.fetch
def fetch(name, adapter_name = :default) adapter(adapter_name)[name] || adapter(:default)[name] || raise(UnknownPluginError, name) end
ruby
def fetch(name, adapter_name = :default) adapter(adapter_name)[name] || adapter(:default)[name] || raise(UnknownPluginError, name) end
[ "def", "fetch", "(", "name", ",", "adapter_name", "=", ":default", ")", "adapter", "(", "adapter_name", ")", "[", "name", "]", "||", "adapter", "(", ":default", ")", "[", "name", "]", "||", "raise", "(", "UnknownPluginError", ",", "name", ")", "end" ]
Return the plugin for a given adapter @param [Symbol] name The name of the plugin @param [Symbol] adapter_name (:default) The name of the adapter used @raise [UnknownPluginError] if no plugin is found with the given name @api public
[ "Return", "the", "plugin", "for", "a", "given", "adapter" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/plugin_registry.rb#L192-L195
train
rom-rb/rom
core/lib/rom/setup/auto_registration.rb
ROM.AutoRegistration.load_entities
def load_entities(entity) Dir[globs[entity]].map do |file| require file klass_name = case namespace when String AutoRegistrationStrategies::CustomNamespace.new( namespace: namespace, file: file, directory: directory ).call when TrueClass AutoRegistrationStrategies::WithNamespace.new( file: file, directory: directory ).call when FalseClass AutoRegistrationStrategies::NoNamespace.new( file: file, directory: directory, entity: component_dirs.fetch(entity) ).call end Inflector.constantize(klass_name) end end
ruby
def load_entities(entity) Dir[globs[entity]].map do |file| require file klass_name = case namespace when String AutoRegistrationStrategies::CustomNamespace.new( namespace: namespace, file: file, directory: directory ).call when TrueClass AutoRegistrationStrategies::WithNamespace.new( file: file, directory: directory ).call when FalseClass AutoRegistrationStrategies::NoNamespace.new( file: file, directory: directory, entity: component_dirs.fetch(entity) ).call end Inflector.constantize(klass_name) end end
[ "def", "load_entities", "(", "entity", ")", "Dir", "[", "globs", "[", "entity", "]", "]", ".", "map", "do", "|", "file", "|", "require", "file", "klass_name", "=", "case", "namespace", "when", "String", "AutoRegistrationStrategies", "::", "CustomNamespace", ".", "new", "(", "namespace", ":", "namespace", ",", "file", ":", "file", ",", "directory", ":", "directory", ")", ".", "call", "when", "TrueClass", "AutoRegistrationStrategies", "::", "WithNamespace", ".", "new", "(", "file", ":", "file", ",", "directory", ":", "directory", ")", ".", "call", "when", "FalseClass", "AutoRegistrationStrategies", "::", "NoNamespace", ".", "new", "(", "file", ":", "file", ",", "directory", ":", "directory", ",", "entity", ":", "component_dirs", ".", "fetch", "(", "entity", ")", ")", ".", "call", "end", "Inflector", ".", "constantize", "(", "klass_name", ")", "end", "end" ]
Load given component files @api private
[ "Load", "given", "component", "files" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/setup/auto_registration.rb#L80-L101
train
rom-rb/rom
core/lib/rom/setup/finalize.rb
ROM.Finalize.run!
def run! mappers = load_mappers relations = load_relations(mappers) commands = load_commands(relations) container = Container.new(gateways, relations, mappers, commands) container.freeze container end
ruby
def run! mappers = load_mappers relations = load_relations(mappers) commands = load_commands(relations) container = Container.new(gateways, relations, mappers, commands) container.freeze container end
[ "def", "run!", "mappers", "=", "load_mappers", "relations", "=", "load_relations", "(", "mappers", ")", "commands", "=", "load_commands", "(", "relations", ")", "container", "=", "Container", ".", "new", "(", "gateways", ",", "relations", ",", "mappers", ",", "commands", ")", "container", ".", "freeze", "container", "end" ]
Run the finalization process This creates relations, mappers and commands @return [Container] @api private
[ "Run", "the", "finalization", "process" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/setup/finalize.rb#L62-L70
train
rom-rb/rom
core/lib/rom/setup/finalize.rb
ROM.Finalize.load_relations
def load_relations(mappers) global_plugins = plugins.select { |p| p.relation? || p.schema? } FinalizeRelations.new( gateways, relation_classes, mappers: mappers, plugins: global_plugins, notifications: notifications ).run! end
ruby
def load_relations(mappers) global_plugins = plugins.select { |p| p.relation? || p.schema? } FinalizeRelations.new( gateways, relation_classes, mappers: mappers, plugins: global_plugins, notifications: notifications ).run! end
[ "def", "load_relations", "(", "mappers", ")", "global_plugins", "=", "plugins", ".", "select", "{", "|", "p", "|", "p", ".", "relation?", "||", "p", ".", "schema?", "}", "FinalizeRelations", ".", "new", "(", "gateways", ",", "relation_classes", ",", "mappers", ":", "mappers", ",", "plugins", ":", "global_plugins", ",", "notifications", ":", "notifications", ")", ".", "run!", "end" ]
Build entire relation registry from all known relation subclasses This includes both classes created via DSL and explicit definitions @api private
[ "Build", "entire", "relation", "registry", "from", "all", "known", "relation", "subclasses" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/setup/finalize.rb#L79-L89
train
rom-rb/rom
changeset/lib/rom/changeset.rb
ROM.Changeset.new
def new(relation, new_options = EMPTY_HASH) self.class.new(relation, new_options.empty? ? options : options.merge(new_options)) end
ruby
def new(relation, new_options = EMPTY_HASH) self.class.new(relation, new_options.empty? ? options : options.merge(new_options)) end
[ "def", "new", "(", "relation", ",", "new_options", "=", "EMPTY_HASH", ")", "self", ".", "class", ".", "new", "(", "relation", ",", "new_options", ".", "empty?", "?", "options", ":", "options", ".", "merge", "(", "new_options", ")", ")", "end" ]
Return a new changeset with provided relation New options can be provided too @param [Relation] relation @param [Hash] new_options @return [Changeset] @api public
[ "Return", "a", "new", "changeset", "with", "provided", "relation" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/changeset/lib/rom/changeset.rb#L86-L88
train
rom-rb/rom
core/lib/rom/support/notifications.rb
ROM.Notifications.register_event
def register_event(id, info = EMPTY_HASH) Notifications.events[id] = Event.new(id, info) end
ruby
def register_event(id, info = EMPTY_HASH) Notifications.events[id] = Event.new(id, info) end
[ "def", "register_event", "(", "id", ",", "info", "=", "EMPTY_HASH", ")", "Notifications", ".", "events", "[", "id", "]", "=", "Event", ".", "new", "(", "id", ",", "info", ")", "end" ]
Register an event @param [String] id A unique event key @param [Hash] info @api public
[ "Register", "an", "event" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/support/notifications.rb#L160-L162
train
rom-rb/rom
core/lib/rom/plugin.rb
ROM.Plugin.apply_to
def apply_to(klass, options = EMPTY_HASH) if mod.respond_to?(:new) klass.send(:include, mod.new(options)) else klass.send(:include, mod) end end
ruby
def apply_to(klass, options = EMPTY_HASH) if mod.respond_to?(:new) klass.send(:include, mod.new(options)) else klass.send(:include, mod) end end
[ "def", "apply_to", "(", "klass", ",", "options", "=", "EMPTY_HASH", ")", "if", "mod", ".", "respond_to?", "(", ":new", ")", "klass", ".", "send", "(", ":include", ",", "mod", ".", "new", "(", "options", ")", ")", "else", "klass", ".", "send", "(", ":include", ",", "mod", ")", "end", "end" ]
Apply this plugin to the provided class @param [Class] klass @api private
[ "Apply", "this", "plugin", "to", "the", "provided", "class" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/plugin.rb#L19-L25
train
rom-rb/rom
core/lib/rom/schema.rb
ROM.Schema.project
def project(*names) new(names.map { |name| name.is_a?(Symbol) ? self[name] : name }) end
ruby
def project(*names) new(names.map { |name| name.is_a?(Symbol) ? self[name] : name }) end
[ "def", "project", "(", "*", "names", ")", "new", "(", "names", ".", "map", "{", "|", "name", "|", "name", ".", "is_a?", "(", "Symbol", ")", "?", "self", "[", "name", "]", ":", "name", "}", ")", "end" ]
Project a schema to include only specified attributes @param [*Array<Symbol, Attribute>] names Attribute names @return [Schema] @api public
[ "Project", "a", "schema", "to", "include", "only", "specified", "attributes" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/schema.rb#L245-L247
train
rom-rb/rom
core/lib/rom/schema.rb
ROM.Schema.rename
def rename(mapping) new_attributes = map do |attr| alias_name = mapping[attr.name] alias_name ? attr.aliased(alias_name) : attr end new(new_attributes) end
ruby
def rename(mapping) new_attributes = map do |attr| alias_name = mapping[attr.name] alias_name ? attr.aliased(alias_name) : attr end new(new_attributes) end
[ "def", "rename", "(", "mapping", ")", "new_attributes", "=", "map", "do", "|", "attr", "|", "alias_name", "=", "mapping", "[", "attr", ".", "name", "]", "alias_name", "?", "attr", ".", "aliased", "(", "alias_name", ")", ":", "attr", "end", "new", "(", "new_attributes", ")", "end" ]
Project a schema with renamed attributes @param [Hash] mapping The attribute mappings @return [Schema] @api public
[ "Project", "a", "schema", "with", "renamed", "attributes" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/schema.rb#L267-L274
train
rom-rb/rom
core/lib/rom/schema.rb
ROM.Schema.wrap
def wrap(prefix = name.dataset) new(map { |attr| attr.wrapped? ? attr : attr.wrapped(prefix) }) end
ruby
def wrap(prefix = name.dataset) new(map { |attr| attr.wrapped? ? attr : attr.wrapped(prefix) }) end
[ "def", "wrap", "(", "prefix", "=", "name", ".", "dataset", ")", "new", "(", "map", "{", "|", "attr", "|", "attr", ".", "wrapped?", "?", "attr", ":", "attr", ".", "wrapped", "(", "prefix", ")", "}", ")", "end" ]
Return new schema with all attributes marked as prefixed and wrapped This is useful when relations are joined and the right side should be marked as wrapped @param [Symbol] prefix The prefix used for aliasing wrapped attributes @return [Schema] @api public
[ "Return", "new", "schema", "with", "all", "attributes", "marked", "as", "prefixed", "and", "wrapped" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/schema.rb#L297-L299
train
rom-rb/rom
core/lib/rom/schema.rb
ROM.Schema.uniq
def uniq(&block) if block new(attributes.uniq(&block)) else new(attributes.uniq(&:name)) end end
ruby
def uniq(&block) if block new(attributes.uniq(&block)) else new(attributes.uniq(&:name)) end end
[ "def", "uniq", "(", "&", "block", ")", "if", "block", "new", "(", "attributes", ".", "uniq", "(", "block", ")", ")", "else", "new", "(", "attributes", ".", "uniq", "(", ":name", ")", ")", "end", "end" ]
Return a new schema with uniq attributes @return [Schema] @api public
[ "Return", "a", "new", "schema", "with", "uniq", "attributes" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/schema.rb#L349-L355
train
rom-rb/rom
core/lib/rom/schema.rb
ROM.Schema.finalize_attributes!
def finalize_attributes!(gateway: nil, relations: nil) inferrer.(self, gateway).each { |key, value| set!(key, value) } yield if block_given? initialize_primary_key_names self end
ruby
def finalize_attributes!(gateway: nil, relations: nil) inferrer.(self, gateway).each { |key, value| set!(key, value) } yield if block_given? initialize_primary_key_names self end
[ "def", "finalize_attributes!", "(", "gateway", ":", "nil", ",", "relations", ":", "nil", ")", "inferrer", ".", "(", "self", ",", "gateway", ")", ".", "each", "{", "|", "key", ",", "value", "|", "set!", "(", "key", ",", "value", ")", "}", "yield", "if", "block_given?", "initialize_primary_key_names", "self", "end" ]
This hook is called when relation is being build during container finalization When block is provided it'll be called just before freezing the instance so that additional ivars can be set @return [self] @api private
[ "This", "hook", "is", "called", "when", "relation", "is", "being", "build", "during", "container", "finalization" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/schema.rb#L395-L403
train
rom-rb/rom
core/lib/rom/schema.rb
ROM.Schema.to_output_hash
def to_output_hash HASH_SCHEMA.schema( map { |attr| [attr.key, attr.to_read_type] }.to_h ) end
ruby
def to_output_hash HASH_SCHEMA.schema( map { |attr| [attr.key, attr.to_read_type] }.to_h ) end
[ "def", "to_output_hash", "HASH_SCHEMA", ".", "schema", "(", "map", "{", "|", "attr", "|", "[", "attr", ".", "key", ",", "attr", ".", "to_read_type", "]", "}", ".", "to_h", ")", "end" ]
Return coercion function using attribute read types This is used for `output_schema` in relations @return [Dry::Types::Hash] @api private
[ "Return", "coercion", "function", "using", "attribute", "read", "types" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/schema.rb#L424-L428
train
rom-rb/rom
core/lib/rom/schema.rb
ROM.Schema.to_input_hash
def to_input_hash HASH_SCHEMA.schema( map { |attr| [attr.name, attr.to_write_type] }.to_h ) end
ruby
def to_input_hash HASH_SCHEMA.schema( map { |attr| [attr.name, attr.to_write_type] }.to_h ) end
[ "def", "to_input_hash", "HASH_SCHEMA", ".", "schema", "(", "map", "{", "|", "attr", "|", "[", "attr", ".", "name", ",", "attr", ".", "to_write_type", "]", "}", ".", "to_h", ")", "end" ]
Return coercion function using attribute types This is used for `input_schema` in relations, typically commands use it for processing input @return [Dry::Types::Hash] @api private
[ "Return", "coercion", "function", "using", "attribute", "types" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/schema.rb#L438-L442
train
rom-rb/rom
core/lib/rom/auto_curry.rb
ROM.AutoCurry.auto_curry
def auto_curry(name, &block) arity = instance_method(name).arity return unless public_instance_methods.include?(name) && arity != 0 mod = Module.new mod.module_eval do define_method(name) do |*args, &mblock| response = if arity < 0 || arity == args.size super(*args, &mblock) else self.class.curried.new(self, view: name, curry_args: args, arity: arity) end if block response.instance_exec(&block) else response end end end auto_curried_methods << name prepend(mod) end
ruby
def auto_curry(name, &block) arity = instance_method(name).arity return unless public_instance_methods.include?(name) && arity != 0 mod = Module.new mod.module_eval do define_method(name) do |*args, &mblock| response = if arity < 0 || arity == args.size super(*args, &mblock) else self.class.curried.new(self, view: name, curry_args: args, arity: arity) end if block response.instance_exec(&block) else response end end end auto_curried_methods << name prepend(mod) end
[ "def", "auto_curry", "(", "name", ",", "&", "block", ")", "arity", "=", "instance_method", "(", "name", ")", ".", "arity", "return", "unless", "public_instance_methods", ".", "include?", "(", "name", ")", "&&", "arity", "!=", "0", "mod", "=", "Module", ".", "new", "mod", ".", "module_eval", "do", "define_method", "(", "name", ")", "do", "|", "*", "args", ",", "&", "mblock", "|", "response", "=", "if", "arity", "<", "0", "||", "arity", "==", "args", ".", "size", "super", "(", "args", ",", "mblock", ")", "else", "self", ".", "class", ".", "curried", ".", "new", "(", "self", ",", "view", ":", "name", ",", "curry_args", ":", "args", ",", "arity", ":", "arity", ")", "end", "if", "block", "response", ".", "instance_exec", "(", "block", ")", "else", "response", "end", "end", "end", "auto_curried_methods", "<<", "name", "prepend", "(", "mod", ")", "end" ]
Auto-curry a method @param [Symbol] name The name of a method @api private
[ "Auto", "-", "curry", "a", "method" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/auto_curry.rb#L39-L66
train
rom-rb/rom
core/lib/rom/command_registry.rb
ROM.CommandRegistry.[]
def [](*args) if args.size.equal?(1) command = super mapper = options[:mapper] if mapper command.curry >> mapper else command end else cache.fetch_or_store(args.hash) { compiler.(*args) } end end
ruby
def [](*args) if args.size.equal?(1) command = super mapper = options[:mapper] if mapper command.curry >> mapper else command end else cache.fetch_or_store(args.hash) { compiler.(*args) } end end
[ "def", "[]", "(", "*", "args", ")", "if", "args", ".", "size", ".", "equal?", "(", "1", ")", "command", "=", "super", "mapper", "=", "options", "[", ":mapper", "]", "if", "mapper", "command", ".", "curry", ">>", "mapper", "else", "command", "end", "else", "cache", ".", "fetch_or_store", "(", "args", ".", "hash", ")", "{", "compiler", ".", "(", "args", ")", "}", "end", "end" ]
Return a command from the registry If mapper is set command will be turned into a composite command with auto-mapping @overload [](name) @param [Symbol] name The command identifier from the registry @example create_user = rom.commands[:users][:create] create_user[name: 'Jane'] # with mapping, assuming :entity mapper is registered for :users relation create_user = rom.commands[:users].map_with(:entity)[:create] create_user[name: 'Jane'] # => result is sent through :entity mapper @overload [](*args) @param [Array] *args {CommandCompiler} arguments @see CommandCompiler#call @return [Command,Command::Composite] @api public
[ "Return", "a", "command", "from", "the", "registry" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/command_registry.rb#L63-L76
train
rom-rb/rom
core/lib/rom/configuration_dsl.rb
ROM.ConfigurationDSL.relation
def relation(name, options = EMPTY_HASH, &block) klass_opts = { adapter: default_adapter }.merge(options) klass = Relation.build_class(name, klass_opts) klass.schema_opts(dataset: name, relation: name) klass.class_eval(&block) if block register_relation(klass) klass end
ruby
def relation(name, options = EMPTY_HASH, &block) klass_opts = { adapter: default_adapter }.merge(options) klass = Relation.build_class(name, klass_opts) klass.schema_opts(dataset: name, relation: name) klass.class_eval(&block) if block register_relation(klass) klass end
[ "def", "relation", "(", "name", ",", "options", "=", "EMPTY_HASH", ",", "&", "block", ")", "klass_opts", "=", "{", "adapter", ":", "default_adapter", "}", ".", "merge", "(", "options", ")", "klass", "=", "Relation", ".", "build_class", "(", "name", ",", "klass_opts", ")", "klass", ".", "schema_opts", "(", "dataset", ":", "name", ",", "relation", ":", "name", ")", "klass", ".", "class_eval", "(", "block", ")", "if", "block", "register_relation", "(", "klass", ")", "klass", "end" ]
Relation definition DSL @example setup.relation(:users) do def names project(:name) end end @api public
[ "Relation", "definition", "DSL" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/configuration_dsl.rb#L21-L28
train
rom-rb/rom
core/lib/rom/configuration_dsl.rb
ROM.ConfigurationDSL.commands
def commands(name, &block) register_command(*CommandDSL.new(name, default_adapter, &block).command_classes) end
ruby
def commands(name, &block) register_command(*CommandDSL.new(name, default_adapter, &block).command_classes) end
[ "def", "commands", "(", "name", ",", "&", "block", ")", "register_command", "(", "CommandDSL", ".", "new", "(", "name", ",", "default_adapter", ",", "block", ")", ".", "command_classes", ")", "end" ]
Command definition DSL @example setup.commands(:users) do define(:create) do input NewUserParams result :one end define(:update) do input UserParams result :many end define(:delete) do result :many end end @api public
[ "Command", "definition", "DSL" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/configuration_dsl.rb#L50-L52
train
rom-rb/rom
core/lib/rom/configuration_dsl.rb
ROM.ConfigurationDSL.plugin
def plugin(adapter, spec, &block) type, name = spec.flatten(1) plugin = plugin_registry.send(type).adapter(adapter).fetch(name) { plugin_registry.send(type).fetch(name) } if block register_plugin(plugin.configure(&block)) else register_plugin(plugin) end end
ruby
def plugin(adapter, spec, &block) type, name = spec.flatten(1) plugin = plugin_registry.send(type).adapter(adapter).fetch(name) { plugin_registry.send(type).fetch(name) } if block register_plugin(plugin.configure(&block)) else register_plugin(plugin) end end
[ "def", "plugin", "(", "adapter", ",", "spec", ",", "&", "block", ")", "type", ",", "name", "=", "spec", ".", "flatten", "(", "1", ")", "plugin", "=", "plugin_registry", ".", "send", "(", "type", ")", ".", "adapter", "(", "adapter", ")", ".", "fetch", "(", "name", ")", "{", "plugin_registry", ".", "send", "(", "type", ")", ".", "fetch", "(", "name", ")", "}", "if", "block", "register_plugin", "(", "plugin", ".", "configure", "(", "block", ")", ")", "else", "register_plugin", "(", "plugin", ")", "end", "end" ]
Configures a plugin for a specific adapter to be enabled for all relations @example config = ROM::Configuration.new(:sql, 'sqlite::memory') config.plugin(:sql, relations: :instrumentation) do |p| p.notifications = MyNotificationsBackend end config.plugin(:sql, relations: :pagination) @param [Symbol] adapter The adapter identifier @param [Hash<Symbol=>Symbol>] spec Component identifier => plugin identifier @return [Plugin] @api public
[ "Configures", "a", "plugin", "for", "a", "specific", "adapter", "to", "be", "enabled", "for", "all", "relations" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/configuration_dsl.rb#L71-L80
train
rom-rb/rom
core/lib/rom/command.rb
ROM.Command.call
def call(*args, &block) tuples = if hooks? prepared = if curried? apply_hooks(before_hooks, *(curry_args + args)) else apply_hooks(before_hooks, *args) end result = prepared ? execute(prepared, &block) : execute(&block) if curried? if args.size > 0 apply_hooks(after_hooks, result, *args) elsif curry_args.size > 1 apply_hooks(after_hooks, result, curry_args[1]) else apply_hooks(after_hooks, result) end else apply_hooks(after_hooks, result, *args[1..args.size-1]) end else execute(*(curry_args + args), &block) end if one? tuples.first else tuples end end
ruby
def call(*args, &block) tuples = if hooks? prepared = if curried? apply_hooks(before_hooks, *(curry_args + args)) else apply_hooks(before_hooks, *args) end result = prepared ? execute(prepared, &block) : execute(&block) if curried? if args.size > 0 apply_hooks(after_hooks, result, *args) elsif curry_args.size > 1 apply_hooks(after_hooks, result, curry_args[1]) else apply_hooks(after_hooks, result) end else apply_hooks(after_hooks, result, *args[1..args.size-1]) end else execute(*(curry_args + args), &block) end if one? tuples.first else tuples end end
[ "def", "call", "(", "*", "args", ",", "&", "block", ")", "tuples", "=", "if", "hooks?", "prepared", "=", "if", "curried?", "apply_hooks", "(", "before_hooks", ",", "(", "curry_args", "+", "args", ")", ")", "else", "apply_hooks", "(", "before_hooks", ",", "args", ")", "end", "result", "=", "prepared", "?", "execute", "(", "prepared", ",", "block", ")", ":", "execute", "(", "block", ")", "if", "curried?", "if", "args", ".", "size", ">", "0", "apply_hooks", "(", "after_hooks", ",", "result", ",", "args", ")", "elsif", "curry_args", ".", "size", ">", "1", "apply_hooks", "(", "after_hooks", ",", "result", ",", "curry_args", "[", "1", "]", ")", "else", "apply_hooks", "(", "after_hooks", ",", "result", ")", "end", "else", "apply_hooks", "(", "after_hooks", ",", "result", ",", "args", "[", "1", "..", "args", ".", "size", "-", "1", "]", ")", "end", "else", "execute", "(", "(", "curry_args", "+", "args", ")", ",", "block", ")", "end", "if", "one?", "tuples", ".", "first", "else", "tuples", "end", "end" ]
Call the command and return one or many tuples This method will apply before/after hooks automatically @api public
[ "Call", "the", "command", "and", "return", "one", "or", "many", "tuples" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/command.rb#L272-L304
train
rom-rb/rom
core/lib/rom/command.rb
ROM.Command.curry
def curry(*args) if curry_args.empty? && args.first.is_a?(Graph::InputEvaluator) Lazy[self].new(self, *args) else self.class.build(relation, { **options, curry_args: args }) end end
ruby
def curry(*args) if curry_args.empty? && args.first.is_a?(Graph::InputEvaluator) Lazy[self].new(self, *args) else self.class.build(relation, { **options, curry_args: args }) end end
[ "def", "curry", "(", "*", "args", ")", "if", "curry_args", ".", "empty?", "&&", "args", ".", "first", ".", "is_a?", "(", "Graph", "::", "InputEvaluator", ")", "Lazy", "[", "self", "]", ".", "new", "(", "self", ",", "args", ")", "else", "self", ".", "class", ".", "build", "(", "relation", ",", "{", "**", "options", ",", "curry_args", ":", "args", "}", ")", "end", "end" ]
Curry this command with provided args Curried command can be called without args. If argument is a graph input processor, lazy command will be returned, which is used for handling nested input hashes. @return [Command, Lazy] @api public
[ "Curry", "this", "command", "with", "provided", "args" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/command.rb#L315-L321
train
rom-rb/rom
core/lib/rom/command.rb
ROM.Command.map_input_tuples
def map_input_tuples(tuples, &mapper) return enum_for(:with_input_tuples, tuples) unless mapper if tuples.respond_to? :merge mapper[tuples] else tuples.map(&mapper) end end
ruby
def map_input_tuples(tuples, &mapper) return enum_for(:with_input_tuples, tuples) unless mapper if tuples.respond_to? :merge mapper[tuples] else tuples.map(&mapper) end end
[ "def", "map_input_tuples", "(", "tuples", ",", "&", "mapper", ")", "return", "enum_for", "(", ":with_input_tuples", ",", "tuples", ")", "unless", "mapper", "if", "tuples", ".", "respond_to?", ":merge", "mapper", "[", "tuples", "]", "else", "tuples", ".", "map", "(", "mapper", ")", "end", "end" ]
Yields tuples for insertion or return an enumerator @api private
[ "Yields", "tuples", "for", "insertion", "or", "return", "an", "enumerator" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/command.rb#L449-L457
train
rom-rb/rom
core/lib/rom/command.rb
ROM.Command.apply_hooks
def apply_hooks(hooks, tuples, *args) hooks.reduce(tuples) do |a, e| if e.is_a?(Hash) hook_meth, hook_args = e.to_a.flatten(1) __send__(hook_meth, a, *args, **hook_args) else __send__(e, a, *args) end end end
ruby
def apply_hooks(hooks, tuples, *args) hooks.reduce(tuples) do |a, e| if e.is_a?(Hash) hook_meth, hook_args = e.to_a.flatten(1) __send__(hook_meth, a, *args, **hook_args) else __send__(e, a, *args) end end end
[ "def", "apply_hooks", "(", "hooks", ",", "tuples", ",", "*", "args", ")", "hooks", ".", "reduce", "(", "tuples", ")", "do", "|", "a", ",", "e", "|", "if", "e", ".", "is_a?", "(", "Hash", ")", "hook_meth", ",", "hook_args", "=", "e", ".", "to_a", ".", "flatten", "(", "1", ")", "__send__", "(", "hook_meth", ",", "a", ",", "args", ",", "**", "hook_args", ")", "else", "__send__", "(", "e", ",", "a", ",", "args", ")", "end", "end", "end" ]
Apply provided hooks Used by #call @return [Array<Hash>] @api private
[ "Apply", "provided", "hooks" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/command.rb#L477-L486
train
rom-rb/rom
core/lib/rom/command.rb
ROM.Command.wrap_dataset
def wrap_dataset(dataset) if relation.is_a?(Relation::Composite) relation.new(dataset).to_a else dataset end end
ruby
def wrap_dataset(dataset) if relation.is_a?(Relation::Composite) relation.new(dataset).to_a else dataset end end
[ "def", "wrap_dataset", "(", "dataset", ")", "if", "relation", ".", "is_a?", "(", "Relation", "::", "Composite", ")", "relation", ".", "new", "(", "dataset", ")", ".", "to_a", "else", "dataset", "end", "end" ]
Pipes a dataset through command's relation @return [Array] @api private
[ "Pipes", "a", "dataset", "through", "command", "s", "relation" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/command.rb#L493-L499
train
rom-rb/rom
core/lib/rom/mapper.rb
ROM.Mapper.call
def call(relation) transformers.reduce(relation.to_a) { |a, e| e.call(a) } end
ruby
def call(relation) transformers.reduce(relation.to_a) { |a, e| e.call(a) } end
[ "def", "call", "(", "relation", ")", "transformers", ".", "reduce", "(", "relation", ".", "to_a", ")", "{", "|", "a", ",", "e", "|", "e", ".", "call", "(", "a", ")", "}", "end" ]
Process a relation using the transformers @api private
[ "Process", "a", "relation", "using", "the", "transformers" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/mapper.rb#L96-L98
train
rom-rb/rom
core/lib/rom/command_compiler.rb
ROM.CommandCompiler.call
def call(*args) cache.fetch_or_store(args.hash) do type, adapter, ast, plugins, plugins_options, meta = args compiler = with( id: type, adapter: adapter, plugins: Array(plugins), plugins_options: plugins_options, meta: meta ) graph_opts = compiler.visit(ast) command = ROM::Commands::Graph.build(registry, graph_opts) if command.graph? CommandProxy.new(command) elsif command.lazy? command.unwrap else command end end end
ruby
def call(*args) cache.fetch_or_store(args.hash) do type, adapter, ast, plugins, plugins_options, meta = args compiler = with( id: type, adapter: adapter, plugins: Array(plugins), plugins_options: plugins_options, meta: meta ) graph_opts = compiler.visit(ast) command = ROM::Commands::Graph.build(registry, graph_opts) if command.graph? CommandProxy.new(command) elsif command.lazy? command.unwrap else command end end end
[ "def", "call", "(", "*", "args", ")", "cache", ".", "fetch_or_store", "(", "args", ".", "hash", ")", "do", "type", ",", "adapter", ",", "ast", ",", "plugins", ",", "plugins_options", ",", "meta", "=", "args", "compiler", "=", "with", "(", "id", ":", "type", ",", "adapter", ":", "adapter", ",", "plugins", ":", "Array", "(", "plugins", ")", ",", "plugins_options", ":", "plugins_options", ",", "meta", ":", "meta", ")", "graph_opts", "=", "compiler", ".", "visit", "(", "ast", ")", "command", "=", "ROM", "::", "Commands", "::", "Graph", ".", "build", "(", "registry", ",", "graph_opts", ")", "if", "command", ".", "graph?", "CommandProxy", ".", "new", "(", "command", ")", "elsif", "command", ".", "lazy?", "command", ".", "unwrap", "else", "command", "end", "end", "end" ]
Return a specific command type for a given adapter and relation AST This class holds its own registry where all generated commands are being stored CommandProxy is returned for complex command graphs as they expect root relation name to be present in the input, which we don't want to have in repositories. It might be worth looking into removing this requirement from rom core Command::Graph API. @overload [](type, adapter, ast, plugins, meta) @param type [Symbol] The type of command @param adapter [Symbol] The adapter identifier @param ast [Array] The AST representation of a relation @param plugins [Array<Symbol>] A list of optional command plugins that should be used @param meta [Hash] Meta data for a command @return [Command, CommandProxy] @api private
[ "Return", "a", "specific", "command", "type", "for", "a", "given", "adapter", "and", "relation", "AST" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/command_compiler.rb#L89-L112
train
rom-rb/rom
core/lib/rom/command_compiler.rb
ROM.CommandCompiler.register_command
def register_command(rel_name, type, meta, parent_relation = nil) relation = relations[rel_name] type.create_class(rel_name, type) do |klass| klass.result(meta.fetch(:combine_type, result)) if meta[:combine_type] setup_associates(klass, relation, meta, parent_relation) end plugins.each do |plugin| plugin_options = plugins_options.fetch(plugin) { EMPTY_HASH } klass.use(plugin, plugin_options) end gateway = gateways[relation.gateway] notifications.trigger( 'configuration.commands.class.before_build', command: klass, gateway: gateway, dataset: relation.dataset, adapter: adapter ) klass.extend_for_relation(relation) if klass.restrictable registry[rel_name][type] = klass.build(relation, input: relation.input_schema) end end
ruby
def register_command(rel_name, type, meta, parent_relation = nil) relation = relations[rel_name] type.create_class(rel_name, type) do |klass| klass.result(meta.fetch(:combine_type, result)) if meta[:combine_type] setup_associates(klass, relation, meta, parent_relation) end plugins.each do |plugin| plugin_options = plugins_options.fetch(plugin) { EMPTY_HASH } klass.use(plugin, plugin_options) end gateway = gateways[relation.gateway] notifications.trigger( 'configuration.commands.class.before_build', command: klass, gateway: gateway, dataset: relation.dataset, adapter: adapter ) klass.extend_for_relation(relation) if klass.restrictable registry[rel_name][type] = klass.build(relation, input: relation.input_schema) end end
[ "def", "register_command", "(", "rel_name", ",", "type", ",", "meta", ",", "parent_relation", "=", "nil", ")", "relation", "=", "relations", "[", "rel_name", "]", "type", ".", "create_class", "(", "rel_name", ",", "type", ")", "do", "|", "klass", "|", "klass", ".", "result", "(", "meta", ".", "fetch", "(", ":combine_type", ",", "result", ")", ")", "if", "meta", "[", ":combine_type", "]", "setup_associates", "(", "klass", ",", "relation", ",", "meta", ",", "parent_relation", ")", "end", "plugins", ".", "each", "do", "|", "plugin", "|", "plugin_options", "=", "plugins_options", ".", "fetch", "(", "plugin", ")", "{", "EMPTY_HASH", "}", "klass", ".", "use", "(", "plugin", ",", "plugin_options", ")", "end", "gateway", "=", "gateways", "[", "relation", ".", "gateway", "]", "notifications", ".", "trigger", "(", "'configuration.commands.class.before_build'", ",", "command", ":", "klass", ",", "gateway", ":", "gateway", ",", "dataset", ":", "relation", ".", "dataset", ",", "adapter", ":", "adapter", ")", "klass", ".", "extend_for_relation", "(", "relation", ")", "if", "klass", ".", "restrictable", "registry", "[", "rel_name", "]", "[", "type", "]", "=", "klass", ".", "build", "(", "relation", ",", "input", ":", "relation", ".", "input_schema", ")", "end", "end" ]
Build a command object for a specific relation The command will be prepared for handling associations if it's a combined relation. Additional plugins will be enabled if they are configured for this compiler. @param [Symbol] rel_name A relation identifier from the container registry @param [Symbol] type The command type @param [Hash] meta Meta information from relation AST @param [Symbol] parent_relation Optional parent relation identifier @return [ROM::Command] @api private
[ "Build", "a", "command", "object", "for", "a", "specific", "relation" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/command_compiler.rb#L190-L216
train
rom-rb/rom
core/lib/rom/command_compiler.rb
ROM.CommandCompiler.setup_associates
def setup_associates(klass, relation, meta, parent_relation) assoc_name = if relation.associations.key?(parent_relation) parent_relation else singular_name = Inflector.singularize(parent_relation).to_sym singular_name if relation.associations.key?(singular_name) end if assoc_name klass.associates(assoc_name) else klass.associates(parent_relation) end end
ruby
def setup_associates(klass, relation, meta, parent_relation) assoc_name = if relation.associations.key?(parent_relation) parent_relation else singular_name = Inflector.singularize(parent_relation).to_sym singular_name if relation.associations.key?(singular_name) end if assoc_name klass.associates(assoc_name) else klass.associates(parent_relation) end end
[ "def", "setup_associates", "(", "klass", ",", "relation", ",", "meta", ",", "parent_relation", ")", "assoc_name", "=", "if", "relation", ".", "associations", ".", "key?", "(", "parent_relation", ")", "parent_relation", "else", "singular_name", "=", "Inflector", ".", "singularize", "(", "parent_relation", ")", ".", "to_sym", "singular_name", "if", "relation", ".", "associations", ".", "key?", "(", "singular_name", ")", "end", "if", "assoc_name", "klass", ".", "associates", "(", "assoc_name", ")", "else", "klass", ".", "associates", "(", "parent_relation", ")", "end", "end" ]
Sets up `associates` plugin for a given command class and relation @param [Class] klass The command class @param [Relation] relation The relation for the command @api private
[ "Sets", "up", "associates", "plugin", "for", "a", "given", "command", "class", "and", "relation" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/command_compiler.rb#L233-L247
train
rom-rb/rom
core/lib/rom/environment.rb
ROM.Environment.normalize_gateways
def normalize_gateways(gateways_config) gateways_config.each_with_object(map: {}, gateways: {}) do |(name, spec), hash| identifier, *args = Array(spec) if identifier.is_a?(Gateway) gateway = identifier else gateway = Gateway.setup(identifier, *args.flatten) end hash[:map][gateway] = name hash[:gateways][name] = gateway end end
ruby
def normalize_gateways(gateways_config) gateways_config.each_with_object(map: {}, gateways: {}) do |(name, spec), hash| identifier, *args = Array(spec) if identifier.is_a?(Gateway) gateway = identifier else gateway = Gateway.setup(identifier, *args.flatten) end hash[:map][gateway] = name hash[:gateways][name] = gateway end end
[ "def", "normalize_gateways", "(", "gateways_config", ")", "gateways_config", ".", "each_with_object", "(", "map", ":", "{", "}", ",", "gateways", ":", "{", "}", ")", "do", "|", "(", "name", ",", "spec", ")", ",", "hash", "|", "identifier", ",", "*", "args", "=", "Array", "(", "spec", ")", "if", "identifier", ".", "is_a?", "(", "Gateway", ")", "gateway", "=", "identifier", "else", "gateway", "=", "Gateway", ".", "setup", "(", "identifier", ",", "args", ".", "flatten", ")", "end", "hash", "[", ":map", "]", "[", "gateway", "]", "=", "name", "hash", "[", ":gateways", "]", "[", "name", "]", "=", "gateway", "end", "end" ]
Build gateways using the setup interface @api private
[ "Build", "gateways", "using", "the", "setup", "interface" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/environment.rb#L47-L60
train
rom-rb/rom
core/lib/rom/attribute.rb
ROM.Attribute.meta
def meta(opts = nil) if opts self.class.new(type.meta(opts), options) else type.meta end end
ruby
def meta(opts = nil) if opts self.class.new(type.meta(opts), options) else type.meta end end
[ "def", "meta", "(", "opts", "=", "nil", ")", "if", "opts", "self", ".", "class", ".", "new", "(", "type", ".", "meta", "(", "opts", ")", ",", "options", ")", "else", "type", ".", "meta", "end", "end" ]
Return attribute type with additional meta information Return meta information hash if no opts are provided @param [Hash] opts The meta options @return [Attribute] @api public
[ "Return", "attribute", "type", "with", "additional", "meta", "information" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/attribute.rb#L305-L311
train
rom-rb/rom
core/lib/rom/attribute.rb
ROM.Attribute.inspect
def inspect opts = options.reject { |k| %i[type name].include?(k) } meta_and_opts = meta.merge(opts).map { |k, v| "#{k}=#{v.inspect}" } %(#<#{self.class}[#{type.name}] name=#{name.inspect} #{meta_and_opts.join(' ')}>) end
ruby
def inspect opts = options.reject { |k| %i[type name].include?(k) } meta_and_opts = meta.merge(opts).map { |k, v| "#{k}=#{v.inspect}" } %(#<#{self.class}[#{type.name}] name=#{name.inspect} #{meta_and_opts.join(' ')}>) end
[ "def", "inspect", "opts", "=", "options", ".", "reject", "{", "|", "k", "|", "%i[", "type", "name", "]", ".", "include?", "(", "k", ")", "}", "meta_and_opts", "=", "meta", ".", "merge", "(", "opts", ")", ".", "map", "{", "|", "k", ",", "v", "|", "\"#{k}=#{v.inspect}\"", "}", "%(#<#{self.class}[#{type.name}] name=#{name.inspect} #{meta_and_opts.join(' ')}>)", "end" ]
Return string representation of the attribute type @return [String] @api public
[ "Return", "string", "representation", "of", "the", "attribute", "type" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/attribute.rb#L318-L322
train
rom-rb/rom
core/lib/rom/attribute.rb
ROM.Attribute.optional
def optional sum = self.class.new(super, options) read? ? sum.meta(read: meta[:read].optional) : sum end
ruby
def optional sum = self.class.new(super, options) read? ? sum.meta(read: meta[:read].optional) : sum end
[ "def", "optional", "sum", "=", "self", ".", "class", ".", "new", "(", "super", ",", "options", ")", "read?", "?", "sum", ".", "meta", "(", "read", ":", "meta", "[", ":read", "]", ".", "optional", ")", ":", "sum", "end" ]
Return nullable attribute @return [Attribute] @api public
[ "Return", "nullable", "attribute" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/attribute.rb#L369-L372
train
rom-rb/rom
core/lib/rom/relation.rb
ROM.Relation.each
def each return to_enum unless block_given? if auto_map? mapper.(dataset.map { |tuple| output_schema[tuple] }).each { |struct| yield(struct) } else dataset.each { |tuple| yield(output_schema[tuple]) } end end
ruby
def each return to_enum unless block_given? if auto_map? mapper.(dataset.map { |tuple| output_schema[tuple] }).each { |struct| yield(struct) } else dataset.each { |tuple| yield(output_schema[tuple]) } end end
[ "def", "each", "return", "to_enum", "unless", "block_given?", "if", "auto_map?", "mapper", ".", "(", "dataset", ".", "map", "{", "|", "tuple", "|", "output_schema", "[", "tuple", "]", "}", ")", ".", "each", "{", "|", "struct", "|", "yield", "(", "struct", ")", "}", "else", "dataset", ".", "each", "{", "|", "tuple", "|", "yield", "(", "output_schema", "[", "tuple", "]", ")", "}", "end", "end" ]
Yields relation tuples Every tuple is processed through Relation#output_schema, it's a no-op by default @yield [Hash] @return [Enumerator] if block is not provided @api public
[ "Yields", "relation", "tuples" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/relation.rb#L219-L227
train
rom-rb/rom
core/lib/rom/relation.rb
ROM.Relation.node
def node(name) assoc = associations[name] other = assoc.node other.eager_load(assoc) end
ruby
def node(name) assoc = associations[name] other = assoc.node other.eager_load(assoc) end
[ "def", "node", "(", "name", ")", "assoc", "=", "associations", "[", "name", "]", "other", "=", "assoc", ".", "node", "other", ".", "eager_load", "(", "assoc", ")", "end" ]
Create a graph node for a given association identifier @param [Symbol, Relation::Name] name @return [Relation] @api public
[ "Create", "a", "graph", "node", "for", "a", "given", "association", "identifier" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/relation.rb#L289-L293
train
rom-rb/rom
core/lib/rom/relation.rb
ROM.Relation.eager_load
def eager_load(assoc) relation = assoc.prepare(self) if assoc.override? relation.(assoc) else relation.preload_assoc(assoc) end end
ruby
def eager_load(assoc) relation = assoc.prepare(self) if assoc.override? relation.(assoc) else relation.preload_assoc(assoc) end end
[ "def", "eager_load", "(", "assoc", ")", "relation", "=", "assoc", ".", "prepare", "(", "self", ")", "if", "assoc", ".", "override?", "relation", ".", "(", "assoc", ")", "else", "relation", ".", "preload_assoc", "(", "assoc", ")", "end", "end" ]
Return a graph node prepared by the given association @param [Association] assoc An association object @return [Relation] @api public
[ "Return", "a", "graph", "node", "prepared", "by", "the", "given", "association" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/relation.rb#L302-L310
train
rom-rb/rom
core/lib/rom/relation.rb
ROM.Relation.new
def new(dataset, new_opts = EMPTY_HASH) opts = if new_opts.empty? options elsif new_opts.key?(:schema) options.merge(new_opts).reject { |k, _| k == :input_schema || k == :output_schema } else options.merge(new_opts) end self.class.new(dataset, opts) end
ruby
def new(dataset, new_opts = EMPTY_HASH) opts = if new_opts.empty? options elsif new_opts.key?(:schema) options.merge(new_opts).reject { |k, _| k == :input_schema || k == :output_schema } else options.merge(new_opts) end self.class.new(dataset, opts) end
[ "def", "new", "(", "dataset", ",", "new_opts", "=", "EMPTY_HASH", ")", "opts", "=", "if", "new_opts", ".", "empty?", "options", "elsif", "new_opts", ".", "key?", "(", ":schema", ")", "options", ".", "merge", "(", "new_opts", ")", ".", "reject", "{", "|", "k", ",", "_", "|", "k", "==", ":input_schema", "||", "k", "==", ":output_schema", "}", "else", "options", ".", "merge", "(", "new_opts", ")", "end", "self", ".", "class", ".", "new", "(", "dataset", ",", "opts", ")", "end" ]
Return a new relation with provided dataset and additional options Use this method whenever you need to use dataset API to get a new dataset and you want to return a relation back. Typically relation API should be enough though. If you find yourself using this method, it might be worth to consider reporting an issue that some dataset functionality is not available through relation API. @example with a new dataset users.new(users.dataset.some_method) @example with a new dataset and options users.new(users.dataset.some_method, other: 'options') @param [Object] dataset @param [Hash] new_opts Additional options @api public
[ "Return", "a", "new", "relation", "with", "provided", "dataset", "and", "additional", "options" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/relation.rb#L420-L431
train
rom-rb/rom
core/lib/rom/relation.rb
ROM.Relation.with
def with(opts) new_options = if opts.key?(:meta) opts.merge(meta: meta.merge(opts[:meta])) else opts end new(dataset, options.merge(new_options)) end
ruby
def with(opts) new_options = if opts.key?(:meta) opts.merge(meta: meta.merge(opts[:meta])) else opts end new(dataset, options.merge(new_options)) end
[ "def", "with", "(", "opts", ")", "new_options", "=", "if", "opts", ".", "key?", "(", ":meta", ")", "opts", ".", "merge", "(", "meta", ":", "meta", ".", "merge", "(", "opts", "[", ":meta", "]", ")", ")", "else", "opts", "end", "new", "(", "dataset", ",", "options", ".", "merge", "(", "new_options", ")", ")", "end" ]
Returns a new instance with the same dataset but new options @example users.with(output_schema: -> tuple { .. }) @param [Hash] opts New options @return [Relation] @api public
[ "Returns", "a", "new", "instance", "with", "the", "same", "dataset", "but", "new", "options" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/relation.rb#L445-L454
train
rom-rb/rom
core/lib/rom/relation.rb
ROM.Relation.map_to
def map_to(klass, **opts) with(opts.merge(auto_map: false, auto_struct: true, meta: { model: klass })) end
ruby
def map_to(klass, **opts) with(opts.merge(auto_map: false, auto_struct: true, meta: { model: klass })) end
[ "def", "map_to", "(", "klass", ",", "**", "opts", ")", "with", "(", "opts", ".", "merge", "(", "auto_map", ":", "false", ",", "auto_struct", ":", "true", ",", "meta", ":", "{", "model", ":", "klass", "}", ")", ")", "end" ]
Return a new relation that will map its tuples to instances of the provided class @example users.map_to(MyUserModel) @param [Class] klass Your custom model class @return [Relation] @api public
[ "Return", "a", "new", "relation", "that", "will", "map", "its", "tuples", "to", "instances", "of", "the", "provided", "class" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/relation.rb#L541-L543
train
rom-rb/rom
core/lib/rom/schema_plugin.rb
ROM.SchemaPlugin.apply_to
def apply_to(schema, options = EMPTY_HASH) mod.apply(schema, options) if mod.respond_to?(:apply) end
ruby
def apply_to(schema, options = EMPTY_HASH) mod.apply(schema, options) if mod.respond_to?(:apply) end
[ "def", "apply_to", "(", "schema", ",", "options", "=", "EMPTY_HASH", ")", "mod", ".", "apply", "(", "schema", ",", "options", ")", "if", "mod", ".", "respond_to?", "(", ":apply", ")", "end" ]
Apply this plugin to the provided configuration @param [ROM::Schema] schema A schema instance for extension @param [Hash] options Extension options @api private
[ "Apply", "this", "plugin", "to", "the", "provided", "configuration" ]
7245b8cb6dadb5a9413606997a0294dd4a956f19
https://github.com/rom-rb/rom/blob/7245b8cb6dadb5a9413606997a0294dd4a956f19/core/lib/rom/schema_plugin.rb#L16-L18
train
libvips/ruby-vips
lib/vips/operation.rb
Vips.Operation.get_construct_args
def get_construct_args args = [] argument_map do |pspec, argument_class, argument_instance| flags = argument_class[:flags] if (flags & ARGUMENT_CONSTRUCT) != 0 # names can include - as punctuation, but we always use _ in # Ruby name = pspec[:name].tr("-", "_") args << [name, flags] end end return args end
ruby
def get_construct_args args = [] argument_map do |pspec, argument_class, argument_instance| flags = argument_class[:flags] if (flags & ARGUMENT_CONSTRUCT) != 0 # names can include - as punctuation, but we always use _ in # Ruby name = pspec[:name].tr("-", "_") args << [name, flags] end end return args end
[ "def", "get_construct_args", "args", "=", "[", "]", "argument_map", "do", "|", "pspec", ",", "argument_class", ",", "argument_instance", "|", "flags", "=", "argument_class", "[", ":flags", "]", "if", "(", "flags", "&", "ARGUMENT_CONSTRUCT", ")", "!=", "0", "# names can include - as punctuation, but we always use _ in", "# Ruby", "name", "=", "pspec", "[", ":name", "]", ".", "tr", "(", "\"-\"", ",", "\"_\"", ")", "args", "<<", "[", "name", ",", "flags", "]", "end", "end", "return", "args", "end" ]
not quick! try to call this infrequently
[ "not", "quick!", "try", "to", "call", "this", "infrequently" ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/operation.rb#L93-L108
train
libvips/ruby-vips
lib/vips/operation.rb
Vips.Operation.set
def set name, value, match_image = nil, flags = 0 gtype = get_typeof name if gtype == IMAGE_TYPE value = Operation::imageize match_image, value if (flags & ARGUMENT_MODIFY) != 0 # make sure we have a unique copy value = value.copy.copy_memory end elsif gtype == ARRAY_IMAGE_TYPE value = value.map {|x| Operation::imageize match_image, x} end super name, value end
ruby
def set name, value, match_image = nil, flags = 0 gtype = get_typeof name if gtype == IMAGE_TYPE value = Operation::imageize match_image, value if (flags & ARGUMENT_MODIFY) != 0 # make sure we have a unique copy value = value.copy.copy_memory end elsif gtype == ARRAY_IMAGE_TYPE value = value.map {|x| Operation::imageize match_image, x} end super name, value end
[ "def", "set", "name", ",", "value", ",", "match_image", "=", "nil", ",", "flags", "=", "0", "gtype", "=", "get_typeof", "name", "if", "gtype", "==", "IMAGE_TYPE", "value", "=", "Operation", "::", "imageize", "match_image", ",", "value", "if", "(", "flags", "&", "ARGUMENT_MODIFY", ")", "!=", "0", "# make sure we have a unique copy", "value", "=", "value", ".", "copy", ".", "copy_memory", "end", "elsif", "gtype", "==", "ARRAY_IMAGE_TYPE", "value", "=", "value", ".", "map", "{", "|", "x", "|", "Operation", "::", "imageize", "match_image", ",", "x", "}", "end", "super", "name", ",", "value", "end" ]
set an operation argument, expanding constants and copying images as required
[ "set", "an", "operation", "argument", "expanding", "constants", "and", "copying", "images", "as", "required" ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/operation.rb#L140-L155
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.call_enum
def call_enum(name, other, enum) if other.is_a?(Vips::Image) Vips::Operation.call name.to_s, [self, other, enum] else Vips::Operation.call name.to_s + "_const", [self, enum, other] end end
ruby
def call_enum(name, other, enum) if other.is_a?(Vips::Image) Vips::Operation.call name.to_s, [self, other, enum] else Vips::Operation.call name.to_s + "_const", [self, enum, other] end end
[ "def", "call_enum", "(", "name", ",", "other", ",", "enum", ")", "if", "other", ".", "is_a?", "(", "Vips", "::", "Image", ")", "Vips", "::", "Operation", ".", "call", "name", ".", "to_s", ",", "[", "self", ",", "other", ",", "enum", "]", "else", "Vips", "::", "Operation", ".", "call", "name", ".", "to_s", "+", "\"_const\"", ",", "[", "self", ",", "enum", ",", "other", "]", "end", "end" ]
handy for expanding enum operations
[ "handy", "for", "expanding", "enum", "operations" ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L142-L148
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.new_from_image
def new_from_image value pixel = (Vips::Image.black(1, 1) + value).cast(format) image = pixel.embed 0, 0, width, height, extend: :copy image.copy interpretation: interpretation, xres: xres, yres: yres, xoffset: xoffset, yoffset: yoffset end
ruby
def new_from_image value pixel = (Vips::Image.black(1, 1) + value).cast(format) image = pixel.embed 0, 0, width, height, extend: :copy image.copy interpretation: interpretation, xres: xres, yres: yres, xoffset: xoffset, yoffset: yoffset end
[ "def", "new_from_image", "value", "pixel", "=", "(", "Vips", "::", "Image", ".", "black", "(", "1", ",", "1", ")", "+", "value", ")", ".", "cast", "(", "format", ")", "image", "=", "pixel", ".", "embed", "0", ",", "0", ",", "width", ",", "height", ",", "extend", ":", ":copy", "image", ".", "copy", "interpretation", ":", "interpretation", ",", "xres", ":", "xres", ",", "yres", ":", "yres", ",", "xoffset", ":", "xoffset", ",", "yoffset", ":", "yoffset", "end" ]
A new image is created with the same width, height, format, interpretation, resolution and offset as self, but with every pixel set to the specified value. You can pass an array to make a many-band image, or a single value to make a one-band image. @param value [Real, Array<Real>] value to put in each pixel @return [Image] constant image
[ "A", "new", "image", "is", "created", "with", "the", "same", "width", "height", "format", "interpretation", "resolution", "and", "offset", "as", "self", "but", "with", "every", "pixel", "set", "to", "the", "specified", "value", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L385-L390
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.write_to_memory
def write_to_memory len = Vips::SizeStruct.new ptr = Vips::vips_image_write_to_memory self, len # wrap up as an autopointer ptr = FFI::AutoPointer.new(ptr, GLib::G_FREE) ptr.get_bytes 0, len[:value] end
ruby
def write_to_memory len = Vips::SizeStruct.new ptr = Vips::vips_image_write_to_memory self, len # wrap up as an autopointer ptr = FFI::AutoPointer.new(ptr, GLib::G_FREE) ptr.get_bytes 0, len[:value] end
[ "def", "write_to_memory", "len", "=", "Vips", "::", "SizeStruct", ".", "new", "ptr", "=", "Vips", "::", "vips_image_write_to_memory", "self", ",", "len", "# wrap up as an autopointer", "ptr", "=", "FFI", "::", "AutoPointer", ".", "new", "(", "ptr", ",", "GLib", "::", "G_FREE", ")", "ptr", ".", "get_bytes", "0", ",", "len", "[", ":value", "]", "end" ]
Write this image to a large memory buffer. @return [String] the pixels as a huge binary string
[ "Write", "this", "image", "to", "a", "large", "memory", "buffer", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L480-L488
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.get_typeof
def get_typeof name # on libvips before 8.5, property types must be searched first, # since vips_image_get_typeof returned built-in enums as int unless Vips::at_least_libvips?(8, 5) gtype = parent_get_typeof name return gtype if gtype != 0 end Vips::vips_image_get_typeof self, name end
ruby
def get_typeof name # on libvips before 8.5, property types must be searched first, # since vips_image_get_typeof returned built-in enums as int unless Vips::at_least_libvips?(8, 5) gtype = parent_get_typeof name return gtype if gtype != 0 end Vips::vips_image_get_typeof self, name end
[ "def", "get_typeof", "name", "# on libvips before 8.5, property types must be searched first,", "# since vips_image_get_typeof returned built-in enums as int", "unless", "Vips", "::", "at_least_libvips?", "(", "8", ",", "5", ")", "gtype", "=", "parent_get_typeof", "name", "return", "gtype", "if", "gtype", "!=", "0", "end", "Vips", "::", "vips_image_get_typeof", "self", ",", "name", "end" ]
Get the `GType` of a metadata field. The result is 0 if no such field exists. @see get @param name [String] Metadata field to fetch @return [Integer] GType
[ "Get", "the", "GType", "of", "a", "metadata", "field", ".", "The", "result", "is", "0", "if", "no", "such", "field", "exists", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L496-L505
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.get
def get name # with old libvips, we must fetch properties (as opposed to # metadata) via VipsObject unless Vips::at_least_libvips?(8, 5) return super if parent_get_typeof(name) != 0 end gvalue = GObject::GValue.alloc result = Vips::vips_image_get self, name, gvalue raise Vips::Error if result != 0 gvalue.get end
ruby
def get name # with old libvips, we must fetch properties (as opposed to # metadata) via VipsObject unless Vips::at_least_libvips?(8, 5) return super if parent_get_typeof(name) != 0 end gvalue = GObject::GValue.alloc result = Vips::vips_image_get self, name, gvalue raise Vips::Error if result != 0 gvalue.get end
[ "def", "get", "name", "# with old libvips, we must fetch properties (as opposed to", "# metadata) via VipsObject", "unless", "Vips", "::", "at_least_libvips?", "(", "8", ",", "5", ")", "return", "super", "if", "parent_get_typeof", "(", "name", ")", "!=", "0", "end", "gvalue", "=", "GObject", "::", "GValue", ".", "alloc", "result", "=", "Vips", "::", "vips_image_get", "self", ",", "name", ",", "gvalue", "raise", "Vips", "::", "Error", "if", "result", "!=", "0", "gvalue", ".", "get", "end" ]
Get a metadata item from an image. Ruby types are constructed automatically from the `GValue`, if possible. For example, you can read the ICC profile from an image like this: ``` profile = image.get "icc-profile-data" ``` and profile will be an array containing the profile. @param name [String] Metadata field to get @return [Object] Value of field
[ "Get", "a", "metadata", "item", "from", "an", "image", ".", "Ruby", "types", "are", "constructed", "automatically", "from", "the", "GValue", "if", "possible", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L520-L532
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.get_fields
def get_fields # vips_image_get_fields() was added in libvips 8.5 return [] unless Vips.respond_to? :vips_image_get_fields array = Vips::vips_image_get_fields self names = [] p = array until (q = p.read_pointer).null? names << q.read_string GLib::g_free q p += FFI::Type::POINTER.size end GLib::g_free array names end
ruby
def get_fields # vips_image_get_fields() was added in libvips 8.5 return [] unless Vips.respond_to? :vips_image_get_fields array = Vips::vips_image_get_fields self names = [] p = array until (q = p.read_pointer).null? names << q.read_string GLib::g_free q p += FFI::Type::POINTER.size end GLib::g_free array names end
[ "def", "get_fields", "# vips_image_get_fields() was added in libvips 8.5", "return", "[", "]", "unless", "Vips", ".", "respond_to?", ":vips_image_get_fields", "array", "=", "Vips", "::", "vips_image_get_fields", "self", "names", "=", "[", "]", "p", "=", "array", "until", "(", "q", "=", "p", ".", "read_pointer", ")", ".", "null?", "names", "<<", "q", ".", "read_string", "GLib", "::", "g_free", "q", "p", "+=", "FFI", "::", "Type", "::", "POINTER", ".", "size", "end", "GLib", "::", "g_free", "array", "names", "end" ]
Get the names of all fields on an image. Use this to loop over all image metadata. @return [[String]] array of field names
[ "Get", "the", "names", "of", "all", "fields", "on", "an", "image", ".", "Use", "this", "to", "loop", "over", "all", "image", "metadata", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L538-L554
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.set_type
def set_type gtype, name, value gvalue = GObject::GValue.alloc gvalue.init gtype gvalue.set value Vips::vips_image_set self, name, gvalue end
ruby
def set_type gtype, name, value gvalue = GObject::GValue.alloc gvalue.init gtype gvalue.set value Vips::vips_image_set self, name, gvalue end
[ "def", "set_type", "gtype", ",", "name", ",", "value", "gvalue", "=", "GObject", "::", "GValue", ".", "alloc", "gvalue", ".", "init", "gtype", "gvalue", ".", "set", "value", "Vips", "::", "vips_image_set", "self", ",", "name", ",", "gvalue", "end" ]
Create a metadata item on an image of the specifed type. Ruby types are automatically transformed into the matching `GType`, if possible. For example, you can use this to set an image's ICC profile: ``` x = y.set_type Vips::BLOB_TYPE, "icc-profile-data", profile ``` where `profile` is an ICC profile held as a binary string object. @see set @param gtype [Integer] GType of item @param name [String] Metadata field to set @param value [Object] Value to set
[ "Create", "a", "metadata", "item", "on", "an", "image", "of", "the", "specifed", "type", ".", "Ruby", "types", "are", "automatically", "transformed", "into", "the", "matching", "GType", "if", "possible", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L571-L576
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.draw_point
def draw_point ink, left, top, opts = {} draw_rect ink, left, top, 1, 1, opts end
ruby
def draw_point ink, left, top, opts = {} draw_rect ink, left, top, 1, 1, opts end
[ "def", "draw_point", "ink", ",", "left", ",", "top", ",", "opts", "=", "{", "}", "draw_rect", "ink", ",", "left", ",", "top", ",", "1", ",", "1", ",", "opts", "end" ]
Draw a point on an image. See {Image#draw_rect}. @return [Image] modified image
[ "Draw", "a", "point", "on", "an", "image", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L756-L758
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.-
def - other other.is_a?(Vips::Image) ? subtract(other) : linear(1, Image::smap(other) {|x| x * -1}) end
ruby
def - other other.is_a?(Vips::Image) ? subtract(other) : linear(1, Image::smap(other) {|x| x * -1}) end
[ "def", "-", "other", "other", ".", "is_a?", "(", "Vips", "::", "Image", ")", "?", "subtract", "(", "other", ")", ":", "linear", "(", "1", ",", "Image", "::", "smap", "(", "other", ")", "{", "|", "x", "|", "x", "*", "-", "1", "}", ")", "end" ]
Subtract an image, constant or array. @param other [Image, Real, Array<Real>] Thing to subtract from self @return [Image] result of subtraction
[ "Subtract", "an", "image", "constant", "or", "array", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L773-L776
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image./
def / other other.is_a?(Vips::Image) ? divide(other) : linear(Image::smap(other) {|x| 1.0 / x}, 0) end
ruby
def / other other.is_a?(Vips::Image) ? divide(other) : linear(Image::smap(other) {|x| 1.0 / x}, 0) end
[ "def", "/", "other", "other", ".", "is_a?", "(", "Vips", "::", "Image", ")", "?", "divide", "(", "other", ")", ":", "linear", "(", "Image", "::", "smap", "(", "other", ")", "{", "|", "x", "|", "1.0", "/", "x", "}", ",", "0", ")", "end" ]
Divide an image, constant or array. @param other [Image, Real, Array<Real>] Thing to divide self by @return [Image] result of division
[ "Divide", "an", "image", "constant", "or", "array", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L791-L794
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.[]
def [] index if index.is_a? Range n = index.size extract_band index.begin, n: n elsif index.is_a? Numeric extract_band index else raise Vips::Error, "[] index is not range or numeric." end end
ruby
def [] index if index.is_a? Range n = index.size extract_band index.begin, n: n elsif index.is_a? Numeric extract_band index else raise Vips::Error, "[] index is not range or numeric." end end
[ "def", "[]", "index", "if", "index", ".", "is_a?", "Range", "n", "=", "index", ".", "size", "extract_band", "index", ".", "begin", ",", "n", ":", "n", "elsif", "index", ".", "is_a?", "Numeric", "extract_band", "index", "else", "raise", "Vips", "::", "Error", ",", "\"[] index is not range or numeric.\"", "end", "end" ]
Fetch bands using a number or a range @param index [Numeric, Range] extract these band(s) @return [Image] extracted band(s)
[ "Fetch", "bands", "using", "a", "number", "or", "a", "range" ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L943-L952
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.to_a
def to_a # we render the image to a big string, then unpack # as a Ruby array of the correct type memory = write_to_memory # make the template for unpack template = { :char => 'c', :uchar => 'C', :short => 's_', :ushort => 'S_', :int => 'i_', :uint => 'I_', :float => 'f', :double => 'd', :complex => 'f', :dpcomplex => 'd' }[format] + '*' # and unpack into something like [1, 2, 3, 4 ..] array = memory.unpack(template) # gather band elements together pixel_array = array.each_slice(bands).to_a # build rows row_array = pixel_array.each_slice(width).to_a return row_array end
ruby
def to_a # we render the image to a big string, then unpack # as a Ruby array of the correct type memory = write_to_memory # make the template for unpack template = { :char => 'c', :uchar => 'C', :short => 's_', :ushort => 'S_', :int => 'i_', :uint => 'I_', :float => 'f', :double => 'd', :complex => 'f', :dpcomplex => 'd' }[format] + '*' # and unpack into something like [1, 2, 3, 4 ..] array = memory.unpack(template) # gather band elements together pixel_array = array.each_slice(bands).to_a # build rows row_array = pixel_array.each_slice(width).to_a return row_array end
[ "def", "to_a", "# we render the image to a big string, then unpack", "# as a Ruby array of the correct type", "memory", "=", "write_to_memory", "# make the template for unpack", "template", "=", "{", ":char", "=>", "'c'", ",", ":uchar", "=>", "'C'", ",", ":short", "=>", "'s_'", ",", ":ushort", "=>", "'S_'", ",", ":int", "=>", "'i_'", ",", ":uint", "=>", "'I_'", ",", ":float", "=>", "'f'", ",", ":double", "=>", "'d'", ",", ":complex", "=>", "'f'", ",", ":dpcomplex", "=>", "'d'", "}", "[", "format", "]", "+", "'*'", "# and unpack into something like [1, 2, 3, 4 ..]", "array", "=", "memory", ".", "unpack", "(", "template", ")", "# gather band elements together", "pixel_array", "=", "array", ".", "each_slice", "(", "bands", ")", ".", "to_a", "# build rows", "row_array", "=", "pixel_array", ".", "each_slice", "(", "width", ")", ".", "to_a", "return", "row_array", "end" ]
Convert to an Array. This will be slow for large images. @return [Array] array of Fixnum
[ "Convert", "to", "an", "Array", ".", "This", "will", "be", "slow", "for", "large", "images", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L957-L986
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.bandjoin
def bandjoin other unless other.is_a? Array other = [other] end # if other is just Numeric, we can use bandjoin_const not_all_real = !other.all?{|x| x.is_a? Numeric} if not_all_real Vips::Image.bandjoin([self] + other) else bandjoin_const other end end
ruby
def bandjoin other unless other.is_a? Array other = [other] end # if other is just Numeric, we can use bandjoin_const not_all_real = !other.all?{|x| x.is_a? Numeric} if not_all_real Vips::Image.bandjoin([self] + other) else bandjoin_const other end end
[ "def", "bandjoin", "other", "unless", "other", ".", "is_a?", "Array", "other", "=", "[", "other", "]", "end", "# if other is just Numeric, we can use bandjoin_const", "not_all_real", "=", "!", "other", ".", "all?", "{", "|", "x", "|", "x", ".", "is_a?", "Numeric", "}", "if", "not_all_real", "Vips", "::", "Image", ".", "bandjoin", "(", "[", "self", "]", "+", "other", ")", "else", "bandjoin_const", "other", "end", "end" ]
Join a set of images bandwise. @param other [Image, Array<Image>, Real, Array<Real>] bands to append @return [Image] many band image
[ "Join", "a", "set", "of", "images", "bandwise", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L1041-L1054
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.composite
def composite overlay, mode, opts = {} unless overlay.is_a? Array overlay = [overlay] end unless mode.is_a? Array mode = [mode] end mode = mode.map do |x| GObject::GValue.from_nick Vips::BLEND_MODE_TYPE, x end Vips::Image.composite([self] + overlay, mode, opts) end
ruby
def composite overlay, mode, opts = {} unless overlay.is_a? Array overlay = [overlay] end unless mode.is_a? Array mode = [mode] end mode = mode.map do |x| GObject::GValue.from_nick Vips::BLEND_MODE_TYPE, x end Vips::Image.composite([self] + overlay, mode, opts) end
[ "def", "composite", "overlay", ",", "mode", ",", "opts", "=", "{", "}", "unless", "overlay", ".", "is_a?", "Array", "overlay", "=", "[", "overlay", "]", "end", "unless", "mode", ".", "is_a?", "Array", "mode", "=", "[", "mode", "]", "end", "mode", "=", "mode", ".", "map", "do", "|", "x", "|", "GObject", "::", "GValue", ".", "from_nick", "Vips", "::", "BLEND_MODE_TYPE", ",", "x", "end", "Vips", "::", "Image", ".", "composite", "(", "[", "self", "]", "+", "overlay", ",", "mode", ",", "opts", ")", "end" ]
Composite a set of images with a set of blend modes. @param overlay [Image, Array<Image>] images to composite @param mode [BlendMode, Array<BlendMode>] blend modes to use @param opts [Hash] Set of options @option opts [Vips::Interpretation] :compositing_space Composite images in this colour space @option opts [Boolean] :premultiplied Images have premultiplied alpha @return [Image] blended image
[ "Composite", "a", "set", "of", "images", "with", "a", "set", "of", "blend", "modes", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L1064-L1077
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.maxpos
def maxpos v, opts = max x: true, y: true x = opts['x'] y = opts['y'] return v, x, y end
ruby
def maxpos v, opts = max x: true, y: true x = opts['x'] y = opts['y'] return v, x, y end
[ "def", "maxpos", "v", ",", "opts", "=", "max", "x", ":", "true", ",", "y", ":", "true", "x", "=", "opts", "[", "'x'", "]", "y", "=", "opts", "[", "'y'", "]", "return", "v", ",", "x", ",", "y", "end" ]
Return the coordinates of the image maximum. @return [Real, Real, Real] maximum value, x coordinate of maximum, y coordinate of maximum
[ "Return", "the", "coordinates", "of", "the", "image", "maximum", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L1083-L1088
train
libvips/ruby-vips
lib/vips/image.rb
Vips.Image.minpos
def minpos v, opts = min x: true, y: true x = opts['x'] y = opts['y'] return v, x, y end
ruby
def minpos v, opts = min x: true, y: true x = opts['x'] y = opts['y'] return v, x, y end
[ "def", "minpos", "v", ",", "opts", "=", "min", "x", ":", "true", ",", "y", ":", "true", "x", "=", "opts", "[", "'x'", "]", "y", "=", "opts", "[", "'y'", "]", "return", "v", ",", "x", ",", "y", "end" ]
Return the coordinates of the image minimum. @return [Real, Real, Real] minimum value, x coordinate of minimum, y coordinate of minimum
[ "Return", "the", "coordinates", "of", "the", "image", "minimum", "." ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/image.rb#L1094-L1099
train
libvips/ruby-vips
lib/vips/object.rb
Vips.Object.get_pspec
def get_pspec name pspec = GObject::GParamSpecPtr.new argument_class = Vips::ArgumentClassPtr.new argument_instance = Vips::ArgumentInstancePtr.new result = Vips::vips_object_get_argument self, name, pspec, argument_class, argument_instance return nil if result != 0 pspec end
ruby
def get_pspec name pspec = GObject::GParamSpecPtr.new argument_class = Vips::ArgumentClassPtr.new argument_instance = Vips::ArgumentInstancePtr.new result = Vips::vips_object_get_argument self, name, pspec, argument_class, argument_instance return nil if result != 0 pspec end
[ "def", "get_pspec", "name", "pspec", "=", "GObject", "::", "GParamSpecPtr", ".", "new", "argument_class", "=", "Vips", "::", "ArgumentClassPtr", ".", "new", "argument_instance", "=", "Vips", "::", "ArgumentInstancePtr", ".", "new", "result", "=", "Vips", "::", "vips_object_get_argument", "self", ",", "name", ",", "pspec", ",", "argument_class", ",", "argument_instance", "return", "nil", "if", "result", "!=", "0", "pspec", "end" ]
return a pspec, or nil ... nil wil leave a message in the error log which you must clear
[ "return", "a", "pspec", "or", "nil", "...", "nil", "wil", "leave", "a", "message", "in", "the", "error", "log", "which", "you", "must", "clear" ]
8f14b1afda91e1078d7a5e6afe94098fef2f2da1
https://github.com/libvips/ruby-vips/blob/8f14b1afda91e1078d7a5e6afe94098fef2f2da1/lib/vips/object.rb#L120-L130
train