query
stringlengths
7
9.5k
document
stringlengths
10
1.07M
negatives
listlengths
19
19
metadata
dict
Add null/not null SQL fragment to column creation SQL.
def column_definition_null_sql(sql, column) null = column.fetch(:null, column[:allow_null]) if null.nil? && !can_add_primary_key_constraint_on_nullable_columns? && column[:primary_key] null = false end case null when false sql << ' NOT NULL' when true sql << ...
[ "def generated_column_definition_null_sql(sql, column)\n null = column.fetch(:null, column[:allow_null])\n sql << NOT_NULL if null == false\n sql << NULL if null == true\n end", "def column_definition_null_sql(sql, column)\n null = column.fetch(:null, column[:allow_null])\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add primary key SQL fragment to column creation SQL.
def column_definition_primary_key_sql(sql, column) if column[:primary_key] if name = column[:primary_key_constraint_name] sql << " CONSTRAINT #{quote_identifier(name)}" end sql << " " << primary_key_constraint_sql_fragment(column) constraint_deferrable_sql_append(sql, col...
[ "def primary_key_constraint_sql_fragment(_)\n 'PRIMARY KEY'\n end", "def primary_key(table, field)\n execute \"ALTER TABLE #{table} ADD PRIMARY KEY(#{field_list(field)})\"\n end", "def column_definition_auto_increment_sql(sql, column)\n sql << \" #{auto_increment_sql}\" if column[:auto_incre...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add foreign key reference SQL fragment to column creation SQL.
def column_definition_references_sql(sql, column) if column[:table] if name = column[:foreign_key_constraint_name] sql << " CONSTRAINT #{quote_identifier(name)}" end sql << column_references_column_constraint_sql(column) end end
[ "def column_references_table_constraint_sql(constraint)\n \"FOREIGN KEY #{literal(constraint[:columns])}#{column_references_sql(constraint)}\"\n end", "def foreign_key(col_name, target_rel_type, opts = {})\n @db_rel[:columns][col_name] = { type: ID_TYPES[:id], foreign_key_rel_type: target_rel_type }....
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add unique constraint SQL fragment to column creation SQL.
def column_definition_unique_sql(sql, column) if column[:unique] if name = column[:unique_constraint_name] sql << " CONSTRAINT #{quote_identifier(name)}" end sql << ' ' << unique_constraint_sql_fragment(column) constraint_deferrable_sql_append(sql, column[:unique_deferrab...
[ "def generated_column_definition_unique_sql(sql, column)\n sql << UNIQUE if column[:unique]\n end", "def unique_constraint_sql_fragment(_)\n 'UNIQUE'\n end", "def unique_constraint(columns, options = {})\n table_constraints << PostgreSQLUniqueConstraint.new(@base, columns, options)\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
SQL fragment for table foreign key references (table constraints)
def column_references_table_constraint_sql(constraint) "FOREIGN KEY #{literal(constraint[:columns])}#{column_references_sql(constraint)}" end
[ "def column_definition_references_sql(sql, column)\n if column[:table]\n if name = column[:foreign_key_constraint_name]\n sql << \" CONSTRAINT #{quote_identifier(name)}\"\n end\n sql << column_references_column_constraint_sql(column)\n end\n end", "def dump_add_fk_constra...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Whether the given alter table operation is combinable.
def combinable_alter_table_op?(op) COMBINABLE_ALTER_TABLE_OPS.include?(op[:op]) end
[ "def combinable_alter_table_op?(op)\n false\n end", "def supports_combining_alter_table_ops?\n true\n end", "def supports_combining_alter_table_ops?\n false\n end", "def merge_commit?\n !squash?\n end", "def commutative?\n is_commutative\n end", "def can_com...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
SQL fragment specifying a constraint on a table.
def constraint_definition_sql(constraint) sql = String.new sql << "CONSTRAINT #{quote_identifier(constraint[:name])} " if constraint[:name] case constraint[:type] when :check check = constraint[:check] check = check.first if check.is_a?(Array) && check.length == 1 check ...
[ "def constraint_definition_sql(constraint)\n sql = constraint[:name] ? \"CONSTRAINT #{quote_identifier(constraint[:name])} \" : \"\"\n sql << \"CHECK #{filter_expr(constraint[:check])}\"\n sql\n end", "def validate_constraint(table_name, constraint_name); end", "def validate_check_cons...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
SQL fragment specifying the deferrable constraint attributes.
def constraint_deferrable_sql_append(sql, defer) case defer when nil when false sql << ' NOT DEFERRABLE' when :immediate sql << ' DEFERRABLE INITIALLY IMMEDIATE' else sql << ' DEFERRABLE INITIALLY DEFERRED' end end
[ "def constraint_definition_sql(constraint)\n sql = String.new\n sql << \"CONSTRAINT #{quote_identifier(constraint[:name])} \" if constraint[:name] \n case constraint[:type]\n when :check\n check = constraint[:check]\n check = check.first if check.is_a?(Array) && check.length == 1\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
The class used for create_table generators.
def create_table_generator_class Schema::CreateTableGenerator end
[ "def create_table_generator(&block)\n create_table_generator_class.new(self, &block)\n end", "def create_table_generator(&block)\n super do\n extend CreateTableGeneratorMethods\n @validations = []\n instance_eval(&block) if block\n end\n end", "def create(data_={})\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Execute the create index statements using the generator.
def create_table_indexes_from_generator(name, generator, options) e = options[:ignore_index_errors] || options[:if_not_exists] generator.indexes.each do |index| begin pr = proc{index_sql_list(name, [index]).each{|sql| execute_ddl(sql)}} supports_transactional_ddl? ? transaction(:...
[ "def create_index!\n # -> uncomment the next line to manually enable rule tracing\n # trace_in( __method__, 2 )\n\n type = CREATE_INDEX\n channel = ANTLR3::DEFAULT_CHANNEL\n\n \n # - - - - main rule block - - - -\n # at line 4:16: 'create index'\n match( \"create index\" )\n\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
SQL statement for creating a table from the result of a SELECT statement. +sql+ should be a string representing a SELECT query.
def create_table_as_sql(name, sql, options) "#{create_table_prefix_sql(name, options)} AS #{sql}" end
[ "def create_table_sql table = table_name\n execute(\"show create table `#{ table }`\").all_hashes.first['Create Table']\n end", "def create_table_sql table = table_name\n connection.execute(\"show create table `#{ table }`\").all_hashes.first['Create Table']\n end", "def add_select_into_table(new_ta...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
SQL fragment for initial part of CREATE VIEW statement
def create_view_prefix_sql(name, options) create_view_sql_append_columns("CREATE #{'OR REPLACE 'if options[:replace]}VIEW #{quote_schema_table(name)}", options[:columns]) end
[ "def create_view_prefix_sql(name, options)\n sql = create_view_sql_append_columns(\"CREATE #{'OR REPLACE 'if options[:replace]}#{'TEMPORARY 'if options[:temp]}#{'RECURSIVE ' if options[:recursive]}#{'MATERIALIZED ' if options[:materialized]}VIEW #{quote_schema_table(name)}\", options[:columns] || options[:re...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Get foreign key name for given table and columns.
def foreign_key_name(table_name, columns) keys = foreign_key_list(table_name).select{|key| key[:columns] == columns} raise(Error, "#{keys.empty? ? 'Missing' : 'Ambiguous'} foreign key for #{columns.inspect}") unless keys.size == 1 keys.first[:name] end
[ "def foreign_key_name(table_name, columns)\n \"#{table_name}_#{Array(columns).map(&:to_s).join(\"_\")}_fk\"\n end", "def foreign_key_column_name\n @foreign_key_column_name ||= begin\n out = options[:foreign_key]\n\n unless out\n out = \"#{@model_class.name.underscor...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Proxy the filter_expr call to the dataset, used for creating constraints. Support passing Proc arguments as blocks, as well as treating plain strings as literal strings, so that previous migrations that used this API do not break.
def filter_expr(arg=nil, &block) if arg.is_a?(Proc) && !block block = arg arg = nil elsif arg.is_a?(String) arg = Sequel.lit(arg) elsif arg.is_a?(Array) if arg.first.is_a?(String) arg = Sequel.lit(*arg) elsif arg.length > 1 arg = Sequel.&(*ar...
[ "def filter_expr(*args, &block)\n schema_utility_dataset.literal(schema_utility_dataset.send(:filter_expr, *args, &block))\n end", "def filter(expr); end", "def filter_expr(expr)\n case expr\n when Hash\n SQL::BooleanExpression.from_value_pairs(expr)\n when Array\n if St...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
SQL statement for creating an index for the table with the given name and index specifications.
def index_definition_sql(table_name, index) index_name = index[:name] || default_index_name(table_name, index[:columns]) raise Error, "Index types are not supported for this database" if index[:type] raise Error, "Partial indexes are not supported for this database" if index[:where] && !supports_parti...
[ "def create_index(table_name, index_spec)\n @iadmin ||= IndexedTableAdmin.new(@configuration)\n @iadmin.addIndex(table_name.to_java_bytes, index_spec)\nend", "def create_index(args)\n if args[:name]\n new_index = create_new_index(args)\n\n @conn.query({url_path: \"#{database}/_index\", opts: ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Array of SQL statements, one for each index specification, for the given table.
def index_sql_list(table_name, indexes) indexes.map{|i| index_definition_sql(table_name, i)} end
[ "def index_list_sql_list(table_name, indexes)\n indexes.map{|i| index_definition_sql(table_name, i)}\n end", "def table_indexes(table)\n ActiveRecord::Base.connection.indexes(table)\n end", "def to_create_index_sql\n queries = []\n unless indexes.blank?\n i...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Extract the join table name from the arguments given to create_join_table. Also does argument validation for the create_join_table method.
def join_table_name(hash, options) entries = hash.values raise Error, "must have 2 entries in hash given to (create|drop)_join_table" unless entries.length == 2 if options[:name] options[:name] else table_names = entries.map{|e| join_table_name_extract(e)} table_names.map...
[ "def join_table_name_extract(entry)\n case entry\n when Symbol, String\n entry\n when Hash\n join_table_name_extract(entry[:table])\n else\n raise Error, \"can't extract table name from #{entry.inspect}\"\n end\n end", "def join_table_name(first_table_name, second_...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Extract an individual join table name, which should either be a string or symbol, or a hash containing one of those as the value for :table.
def join_table_name_extract(entry) case entry when Symbol, String entry when Hash join_table_name_extract(entry[:table]) else raise Error, "can't extract table name from #{entry.inspect}" end end
[ "def join_table_name(hash, options)\n entries = hash.values\n raise Error, \"must have 2 entries in hash given to (create|drop)_join_table\" unless entries.length == 2\n if options[:name]\n options[:name]\n else\n table_names = entries.map{|e| join_table_name_extract(e)}\n t...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add fragment for primary key specification, separated for easier overridding.
def primary_key_constraint_sql_fragment(_) 'PRIMARY KEY' end
[ "def primary_key!\n # -> uncomment the next line to manually enable rule tracing\n # trace_in( __method__, 9 )\n\n type = PRIMARY_KEY\n channel = ANTLR3::DEFAULT_CHANNEL\n\n \n # - - - - main rule block - - - -\n # at line 11:15: 'primary key'\n match( \"primary key\" )\n\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Proxy the quote_schema_table method to the dataset
def quote_schema_table(table) schema_utility_dataset.quote_schema_table(table) end
[ "def quoted_table_name; end", "def quote_table_name(name); end", "def quote_schema_table(table)\n schema, table = schema_and_table(table)\n \"#{\"#{quote_identifier(schema)}.\" if schema}#{quote_identifier(table)}\"\n end", "def quoted_schema\n Squirm.quote_ident schema\n end", "def quo...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Return true if the given column schema represents an autoincrementing primary key.
def schema_autoincrementing_primary_key?(schema) !!(schema[:primary_key] && schema[:auto_increment]) end
[ "def primary_key?\n schema && schema[:primary_key]\n end", "def has_primary_key(db, table, key)\n return db.primary_key(table) == key.to_s if db.respond_to?(:primary_key)\n\n pk_column_info = db.schema(table).find { |column_info| column_info[0] == key }\n return false if pk_column_info.nil?\n\n pk_col...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sequel uses the bigint type by default for :Bignum symbol.
def type_literal_generic_bignum_symbol(column) :bigint end
[ "def type_literal_generic_bignum(column)\n :bigint\n end", "def type_literal_generic_bignum_symbol(column)\n column[:identity] ? 'BIGINT IDENTITY' : super\n end", "def type_literal_generic_bignum_symbol(column)\n column[:serial] ? :bigserial : super\n end", "def bignume...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sequel uses the date type by default for Dates.
def type_literal_generic_date(column) :date end
[ "def dates(field,kind,options = {})\n case kind.to_s.downcase.to_sym\n when :month\n kind = \"Month\"\n when :year\n kind = false\n when :day\n kind = \"Day\"\n else\n raise DateSet::DateKindError, \"`#{kind}` is not a valid date type. Must be one of [:year,:month,:day]\"\n end...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sequel uses the timestamp type by default for DateTimes.
def type_literal_generic_datetime(column) :timestamp end
[ "def typecast_value_datetime(value)\n Sequel.typecast_to_application_timestamp(value)\n end", "def literal_datetime_append(sql, v)\n v.is_a?(DateTime) ? literal_append(sql, Sequel::CURRENT_TIMESTAMP) : super\n end", "def type_literal_generic_date(column)\n :timestamp\n end", "d...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Alias for type_literal_generic_trueclass, to make overriding in a subclass easier.
def type_literal_generic_falseclass(column) type_literal_generic_trueclass(column) end
[ "def type_literal_generic_trueclass(column)\n :boolean\n end", "def type_class\n return String unless casted # This is rubbish, to handle validations\n return @type_class unless @type_class.nil?\n base = @type.is_a?(Array) ? @type.first : @type\n base = String if base.nil?\n base ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sequel uses the blob type by default for Files.
def type_literal_generic_file(column) :blob end
[ "def typecast_value_blob(value)\n value.is_a?(Sequel::SQL::Blob) ? value : Sequel::SQL::Blob.new(value)\n end", "def type_literal_generic_file(column)\n use_clob_as_blob ? :clob : :blob\n end", "def blob(s)\n if s.is_a?(SQL::Blob)\n s\n else\n SQL::Blob.new(s)...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Alias for type_literal_generic_integer, to make overriding in a subclass easier.
def type_literal_generic_fixnum(column) type_literal_generic_integer(column) end
[ "def type_literal_generic_integer(column)\n :int\n end", "def type_literal_generic_bignum_symbol(column)\n column[:identity] ? 'BIGINT IDENTITY' : super\n end", "def type_literal_generic_bignum(column)\n :bigint\n end", "def type_literal_generic_bignum_symbol(column)\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sequel uses the double precision type by default for Floats.
def type_literal_generic_float(column) :"double precision" end
[ "def type_literal_generic_float(column)\n :double\n end", "def use_real_precision(type)\n if type == \"double\"\n unless enable_double_precision?\n msg =\n \"\"\"\n your environment does not support double precision.\n \"\"\"\n raise msg\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sequel uses the numeric type by default for Numerics and BigDecimals. If a size is given, it is used, otherwise, it will default to whatever the database default is for an unsized value.
def type_literal_generic_numeric(column) column[:size] ? "numeric(#{Array(column[:size]).join(', ')})" : :numeric end
[ "def type_literal_generic_numeric(column)\n column[:size] ? \"decimal(#{Array(column[:size]).join(', ')})\" : :decimal\n end", "def size\n case self.type\n #strings in postgres can be unlimited length\n when :string then return (@options.has_key?(:length) || @options.h...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sequel uses the varchar type by default for Strings. If a size isn't present, Sequel assumes a size of 255. If the :fixed option is used, Sequel uses the char type. If the :text option is used, Sequel uses the :text type.
def type_literal_generic_string(column) if column[:text] uses_clob_for_text? ? :clob : :text elsif column[:fixed] "char(#{column[:size]||default_string_column_size})" else "varchar(#{column[:size]||default_string_column_size})" end end
[ "def type_literal_generic_string(column)\n if column[:text]\n :text\n elsif column[:fixed]\n \"char(#{column[:size]||default_string_column_size})\"\n elsif column[:text] == false || column[:size]\n \"varchar(#{column[:size]||default_string_column_size})\"\n els...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sequel uses the boolean type by default for TrueClass and FalseClass.
def type_literal_generic_trueclass(column) :boolean end
[ "def boolean_type\n 'BOOLEAN'\n end", "def boolean_type\n 'Boolean'\n end", "def bson_type\n Boolean::BSON_TYPE\n end", "def boolean(value = true)\n Types::Boolean.new(value)\n end", "def db_boolean(val)\n if adapter == :postgres\n val ? 'T...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add fragment for unique specification, separated for easier overridding.
def unique_constraint_sql_fragment(_) 'UNIQUE' end
[ "def validateFragments\n duplicates = []\n if fragments\n hash = Hash.new(0)\n fragments.each do |id|\n hash[id] += 1\n end\n hash.each do |id, count|\n duplicates << id if count > 1\n end\n end\n duplicates.each do |duplicate|\n addIssue Issue.new(\"The fragm...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Whether clob should be used for String text: true columns.
def uses_clob_for_text? false end
[ "def uses_clob_for_text?\n true\n end", "def has_lob?\n __boolean(OCI_ATTR_HAS_LOB)\n end", "def type_literal_generic_file(column)\n use_clob_as_blob ? :clob : :blob\n end", "def convert_varchar2_to_clob(table_name, column_name, temp_column_name = nil)\n convert_...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Find or create a new object by the given attributes. Will perform a find_by and, if not found, create using the given properties.
def find_or_create_by(attributes) find_by(attributes) || create(attributes) end
[ "def find_or_create_by(attrs = {})\n first(:conditions => attrs) || self.create(attrs)\n end", "def find_or_create_with_attributes(attributes)\n instance = self.new(attributes)\n\n begin \n self.find(instance.default_key)\n rescue Riak::HTTPFailedRequest \n instance\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns the scope key for indexing, considering associations
def slug_scope_key return nil unless slug_scope reflect_on_association(slug_scope).try(:key) || slug_scope end
[ "def index_scope(scope)\n scope\n end", "def indexing_key(input)\n input.object_id\n end", "def scope1_primkey\n self.companyid\n end", "def scope4_primkey\n self.id\n end", "def scope_id\n return @scope_id\n end", "def association_...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Builds slug then atomically sets it in the database. This method is adapted to use the :set method variants from both Mongoid 3 (two args) and Mongoid 4 (hash arg)
def set_slug! build_slug method(:set).arity == 1 ? set(_slugs: _slugs) : set(:_slugs, _slugs) end
[ "def _update_slug\n if self.class._friendly_use_key == :database\n current_slug = self.to_param\n unless _slug_exists?(current_slug)\n self.slug = current_slug\n else\n self.slug = [current_slug.to_s, SecureRandom.hex(6)].join(\"-\")\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Atomically unsets the slug field in the database. It is important to unset the field for the sparse index on slugs. This also resets the inmemory value of the slug field to its default (empty array)
def unset_slug! unset(:_slugs) clear_slug! end
[ "def reset_slug\n if sluggable_field.present?\n @old_slug = slug\n self.slug_field = nil\n end\n end", "def reset_slug!\n reset__slugs!\n end", "def reset_slug!\n reset_slugs!\n end", "def update_slug\n get_resource.slug = nil\n get_resource.save!\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Rolls back the slug value from the Mongoid changeset.
def reset_slug! reset__slugs! end
[ "def reset_slug\n if sluggable_field.present?\n @old_slug = slug\n self.slug_field = nil\n end\n end", "def reset_slug!\n reset_slugs!\n end", "def update_slug\n get_resource.slug = nil\n get_resource.save!\n end", "def manually_update_slug\n update_col...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Finds a unique slug, were specified string used to generate a slug. Returned slug will the same as the specified string when there are no duplicates.
def find_unique_slug UniqueSlug.new(self).find_unique end
[ "def find_next_unique_slug\n _index = 0\n _base = self._slug.gsub(/-\\d+$/, '')\n\n if _similar = similar_slug(_base)\n _index = _similar.scan(/-(\\d+)$/).flatten.last.to_i\n end\n\n loop do\n _index += 1\n self._slug = [_base, _index]...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns true if object is a new record and slugs are present
def new_with_slugs? if localized? # We need to check if slugs are present for the locale without falling back # to a default new_record? && _slugs_translations.fetch(I18n.locale.to_s, []).any? else new_record? && _slugs.present? end end
[ "def new_with_slugs?\n new_record? && slug.present?\n end", "def new_record?\n !@_existing_record\n end", "def record_object?(object)\n object.respond_to?(:new_record?)\n end", "def creating?\n dest_obj.new_record?\n end", "def new_record?\n !_persisted_obj\n end"...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns true if object has been persisted and has changes in the slug
def persisted_with_slug_changes? if localized? changes = _slugs_change return (persisted? && false) if changes.nil? # ensure we check for changes only between the same locale original = changes.first.try(:fetch, I18n.locale.to_s, nil) compare = changes.last.try(:fetch, I18...
[ "def persisted_with_slug_changes?\n persisted? && slug_changed?\n end", "def slug_changed?\n saved_change_to_slug?\n end", "def was_changed? \n if self.page && self.page.last_revision\n return !self.revision_model.exists?(:page_id => self.page.id, :number => self.page.last_re...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Return all possible locales for model Avoiding usage of I18n.available_locales in case the user hasn't set it properly, or is doing something crazy, but at the same time we need a fallback in case the model doesn't have any localized attributes at all (extreme edge case).
def all_locales locales = slugged_attributes .map { |attr| send("#{attr}_translations").keys if respond_to?("#{attr}_translations") } .flatten.compact.uniq locales = I18n.available_locales if locales.empty? locales end
[ "def available_locales\n translation_model.all(:fields => [:locale_tag], :unique => true).map { |t| t.locale }\n end", "def available_locales\n resource.translations.all(:fields => [:locale_tag], :unique => true).map { |t| t.locale }\n end", "def available_locales\n transl...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
choose a random word from words.txt
def choose_word input = File.open("words.txt", 'r') words = [] input.readlines.each do |line| words.push(line.strip().downcase) end input.close() words[rand(words.length)] end
[ "def choose_word\n open('word_list.txt') do |file|\n file_content = file.readlines\n file_content[rand(file_content.size)].strip\n end\n end", "def random_word\n wordpair = nil\n File.foreach(\"wordlist\").each_with_index do |line, number|\n wordpair = line if rand < 1.0/...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
parse the first letter from user input
def parse_letter(input) input = input.strip() letter = "" if input != "" letter = input[0].downcase end letter end
[ "def user_input_letter\n puts \"Type the first letter of the student names you want to see and press return.\".center(100)\n first_letter = STDIN.gets.chomp\nend", "def guess_letter()\n\t\tletter = gets\n\t\tletter = letter[0]\n\t\treturn letter.downcase\n\tend", "def first_letter(string)\n return string[0...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns array of only textual report fields.
def text_reports form_text_ids = @form_data.select do |field| field[:type] == 'text' end.map { |field| field['id'] } @report_data.select do |report_field| form_text_ids.include? report_field.report_id end end
[ "def texts\n @texts ||= fields.select { |f| f.class == Text }\n end", "def all_text_fields\n @text_fields ||= text_fields_hash.values.map { |set| set.to_a }.flatten\n end", "def fields\n @party.get(\"reports/#{@id}/fields\")['Fields']\n end", "def simple_fields\n fields.select(&:s...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
belongs_to :reseller attr_accessor :new_reseller_name before_save :create_reseller_from_name
def create_reseller_from_name # create_reseller(:name => new_reseller_name) unless new_reseller_name.blank? end
[ "def do_before_save\n self.name = \"#{title} #{first_name} #{middle_name + ' ' unless middle_name.blank?}#{last_name}\".squish\n # to ensure unique e-mail\n self.email = \"unknown@#{id}\" if email.blank?\nend", "def create\n @reseller = Reseller.new(params[:reseller])\n @user = current_user\n @title ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /listed_companies POST /listed_companies.json
def create @listed_company = ListedCompany.new(listed_company_params) respond_to do |format| if @listed_company.save format.html { redirect_to listed_companies_path, notice: 'Listed company was successfully created.' } format.json { render :show, status: :created, location: @listed_compan...
[ "def create_companies(model) path = \"/api/v2/companies\"\n post(path, model, {}, AvaTax::VERSION) end", "def create\n if @company = Company.find(entity_id_from_params(:company))\n respond_to do |format|\n current_user.account.companies << @company\n format.html { redirect...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /listed_companies/1 PATCH/PUT /listed_companies/1.json
def update respond_to do |format| if @listed_company.update(listed_company_params) format.html { redirect_to listed_companies_path, notice: 'Listed company was successfully updated.' } format.json { render :show, status: :ok, location: @listed_company } else format.html { render ...
[ "def update\n @company_id = company_params[:company_id]\n @reponse = HTTParty.put(\"https://rails-api-ipo.herokuapp.com/api/v1/companies/#{@company_id}.json\",\n :body => {:company_name => company_params[:company_name]}.to_json,\n :headers => { 'Content-Type' => 'application/json' } )\n respond_to do...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /listed_companies/1 DELETE /listed_companies/1.json
def destroy @listed_company.destroy respond_to do |format| format.html { redirect_to listed_companies_url, notice: 'Listed company was successfully destroyed.' } format.json { head :no_content } end end
[ "def destroy\n @company = Company.find(params[:id])\n @company.destroy\n \n render json: @company, status: :ok \n end", "def destroy\n @company.destroy\n respond_to do |format|\n format.json { head :no_content }\n end\n end", "def destroy\n @biz_company = BizCompany.find(params[:i...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Add a new child to the MergingHomogeneousList (push). Merge `attributes_to_merge` on a duplicate child id insert.
def <<(child) unless child.is_a?(self.class.type) && child.has_key?(self.class.child_id) raise TPX_2_2::ValidationError, "Element provided to #{self.class}#<< must be #{self.class.type} with key `#{self.class.child_id}`." end element = self.find {|e| e[self.class.child_id] == child[self.class....
[ "def <<(child)\n child_type = validate_expected_child_type(child)\n if child_id_of.has_key?(child_type[0]) && child_id_of[child_type[0]].has_key?(child[child_type[1]])\n self.class.attributes_to_merge.each do |attribute|\n child_id_of[child_type[0]][child[child_type[1]]][attribute].merge!(...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /formula_fields/1 GET /formula_fields/1.json
def show @field = FormulaField.find(params[:id]) @owner = Project.find(@field.project_id).user_id recur = params.key?(:recur) ? params[:recur] : false respond_to do |format| format.html { render text: @field.to_json } format.json { render json: @field.to_hash(recur) } end end
[ "def retrieve_form_fields()\n start.uri('/api/form/field')\n .get()\n .go()\n end", "def show\n @formula = Formula.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { render json: @formula }\n end\n end", "def create\n @fiel...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /formula_fields POST /formula_fields.json
def create @field = FormulaField.new(field_params) unless @field.valid? respond_to do |format| errs = @field.errors.full_messages.join ', ' format.json { render json: { msg: errs }, status: :unprocessable_entity } end return end @project = Project.find(params[:field][:...
[ "def update_formula_field(field, params)\n success = field.update_attributes(name: params[\"#{field.id}_name\"],\n unit: params[\"#{field.id}_unit\"],\n formula: params[\"#{field.id}_formula\"],\n index...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /bicycleposts GET /bicycleposts.json
def index @bicycleposts = Bicyclepost.page(params[:page]) @categories = Bicyclecategory.all end
[ "def get_posts\n url = 'https://www.fimfiction.net/api/v2/blog-posts?'\n url << Fimfiction::Utils.query_builder(@filters) unless @filters.length == 0\n url << \"fields[blog_post]=#{Fimfiction::Utils.query_builder(@attributes)}\" unless @attributes.length == 0\n begin\n request = Res...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /bicycleposts POST /bicycleposts.json
def create @bicyclepost = Bicyclepost.new(bicyclepost_params) respond_to do |format| if @bicyclepost.save format.html { redirect_to @bicyclepost, notice: 'Bicyclepost was successfully created.' } format.json { render :show, status: :created, location: @bicyclepost } else for...
[ "def publish\n @post = Post.new\n @post.title = params.require(:title)\n @post.body = params.require(:body)\n @post.tag_list = params.require(:tags)\n @post.save\n render :json => @post\n end", "def create\n @bikepost = Bikepost.new(bikepost_params)\n\n respond_to do |format|\n if @b...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /bicycleposts/1 PATCH/PUT /bicycleposts/1.json
def update respond_to do |format| if @bicyclepost.update(bicyclepost_params) format.html { redirect_to @bicyclepost, notice: 'Bicyclepost was successfully updated.' } format.json { render :show, status: :ok, location: @bicyclepost } else format.html { render :edit } forma...
[ "def update\n @api_v1_post = Post.find(params[:id])\n params[:post].delete :created_at\n params[:post].delete :updated_at\n respond_to do |format|\n if @api_v1_post.update_attributes(params[:post])\n format.html { redirect_to @api_v1_post, notice: 'Post was successfully updated.' }\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /bicycleposts/1 DELETE /bicycleposts/1.json
def destroy @bicyclepost.destroy respond_to do |format| format.html { redirect_to bicycleposts_url, notice: 'Bicyclepost was successfully destroyed.' } format.json { head :no_content } end end
[ "def destroy\n @post.destroy!\n render json: {status: :ok}\n end", "def destroy\r\n @post.destroy\r\n\r\n render json: {}, status: :ok\r\n end", "def destroy\n @post.destroy\n respond_to do |format|\n format.json { head :no_content }\n end\n end", "def delete_floor_plan(args = {})...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /comming_soons/1 GET /comming_soons/1.json
def show @comming_soon = CommingSoon.find(params[:id]) respond_to do |format| format.html # show.html.erb format.json { render json: @comming_soon } end end
[ "def new\n @comming_soon = CommingSoon.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @comming_soon }\n end\n end", "def show\n @soon = Soon.find(params[:id])\n\n respond_to do |format|\n format.html # show.html.erb\n format.json { rend...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /comming_soons/new GET /comming_soons/new.json
def new @comming_soon = CommingSoon.new respond_to do |format| format.html # new.html.erb format.json { render json: @comming_soon } end end
[ "def new\n @new_comm = NewComm.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @new_comm }\n end\n end", "def new\n @comm = Comm.new\n\n respond_to do |format|\n format.html # new.html.erb\n format.json { render json: @comm }\n end\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /comming_soons POST /comming_soons.json
def create @comming_soon = CommingSoon.new(params[:comming_soon]) respond_to do |format| if @comming_soon.save format.html { redirect_to @comming_soon, notice: 'Comming soon was successfully created.' } format.json { render json: @comming_soon, status: :created, location: @comming_soon } ...
[ "def create\n @soon = Soon.new(params[:soon])\n\n respond_to do |format|\n if @soon.save\n format.js { render :action => '../soons/ajax/newsletter'}\n else\n format.js { render :action => '../soons/ajax/error'}\n # format.html { render action: \"new\" }\n # format.json { ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PUT /comming_soons/1 PUT /comming_soons/1.json
def update @comming_soon = CommingSoon.find(params[:id]) respond_to do |format| if @comming_soon.update_attributes(params[:comming_soon]) format.html { redirect_to @comming_soon, notice: 'Comming soon was successfully updated.' } format.json { head :no_content } else format....
[ "def update\n @soon = Soon.find(params[:id])\n\n respond_to do |format|\n if @soon.update_attributes(params[:soon])\n format.html { redirect_to @soon, notice: 'Soon was successfully updated.' }\n format.json { head :no_content }\n else\n format.html { render action: \"edit\" }\n...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /comming_soons/1 DELETE /comming_soons/1.json
def destroy @comming_soon = CommingSoon.find(params[:id]) @comming_soon.destroy respond_to do |format| format.html { redirect_to comming_soons_url } format.json { head :no_content } end end
[ "def destroy\n @soon = Soon.find(params[:id])\n @soon.destroy\n\n respond_to do |format|\n format.html { redirect_to soons_url }\n format.json { head :no_content }\n end\n end", "def destroy\n @clients_has_conjoint.destroy\n respond_to do |format|\n format.html { redirect_to clie...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Return true si le visiteur est un homme
def homme? !identified? || sexe == 'H' end
[ "def shouldHoming()\n _dist = @pos.distanceTo(getStandByPosition()) ;\n\n return (_dist > getConf(:homingMargin) &&\n rand() < getConf(:homingProb)) ;\n end", "def est_vide?()\n return (@pile.size == 0)\n end", "def verbe?\n @is_verbe ||= @data_lemma && @data_lemma[:nature...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns the Beezup API base url.
def base_url "https://api.beezup.com/" end
[ "def base_url\n BASE_URL.dup % [\"%s\", \"%s\", @api_key, \"%s\"] \n end", "def api_base_url\n config.apis[config.environment]\n end", "def base_url\n @base_url ||= File.join(JsonApiServer.configuration.base_url, request.path)\n end", "def api_url\n base_url.concat api_qu...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /scheduled_products or /scheduled_products.json
def index @scheduled_products = ScheduledProduct.all end
[ "def get_product_list\n request_path = \"/products\"\n return RestClient.get(@api+request_path)\n end", "def products\n unless params.has_key?(:date) or (params.has_key?(:start_date) and params.has_key?(:end_date))\n render :json => {:error => I18n.t('date_required')}, :status => :bad_request and r...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /scheduled_products or /scheduled_products.json
def create @scheduled_product = ScheduledProduct.new(scheduled_product_params) respond_to do |format| if @scheduled_product.save format.html { redirect_to list_scheduled_product_url(@scheduled_product.schedule_id), notice: "Scheduled product was successfully created." } format.json { rend...
[ "def index\n @scheduled_products = ScheduledProduct.all\n end", "def create_product_activity_event(data = {})\n %i[provider action product_id name price].each do |key|\n raise ArgumentError, \"#{key}: parameter required\" unless data.key?(key)\n end\n\n data[:occurred_at] = Time....
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /scheduled_products/1 or /scheduled_products/1.json
def update respond_to do |format| if @scheduled_product.update(scheduled_product_params) format.html { redirect_to list_scheduled_product_url(@scheduled_product.schedule_id), notice: "Scheduled product was successfully updated." } format.json { render :show, status: :ok, location: @scheduled_p...
[ "def update\n begin\n @api_v1_product.update!(api_v1_product_params)\n head :no_content\n rescue => ex\n json_response({error: ex.message}, :unprocessable_entity)\n end\n end", "def update\n uri = \"#{API_BASE_URL}/products/#{params[:id]}\"\n payload = params.to_json\n rest_resou...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /scheduled_products/1 or /scheduled_products/1.json
def destroy @scheduled_product.destroy respond_to do |format| format.html { redirect_to list_scheduled_product_url(@scheduled_product.schedule_id), notice: "Scheduled product was successfully destroyed." } format.json { head :no_content } end end
[ "def delete(options = nil)\n request = Request.new(@client)\n path = \"/products/\" + CGI.escape(@id) + \"\"\n data = {\n\n }\n\n response = Response.new(request.delete(path, data, options))\n return_values = Array.new\n \n return_values.push(response.success)\n\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
GET /case_types GET /case_types.json
def index @case_types = CaseType.all end
[ "def get_case_types\n result = get('get_case_types')\n\n result.collect do |type|\n TestRail::CaseType.new(type.merge({ :api => self }))\n end\n end", "def types\n types = JSON.parse(connection.get(\"/Contact/Types\").body )\n end", "def index\n @types = Ty...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
POST /case_types POST /case_types.json
def create @case_type = CaseType.new(case_type_params) respond_to do |format| if @case_type.save format.html { redirect_to @case_type, notice: 'Case type was successfully created.' } format.json { render :show, status: :created, location: @case_type } else format.html { rend...
[ "def get_case_types\n result = get('get_case_types')\n\n result.collect do |type|\n TestRail::CaseType.new(type.merge({ :api => self }))\n end\n end", "def create\n field_type_ids = params[:entry_type].delete(\"field_type_ids\")\n @entry_type = EntryType.new(params[:entry_type])\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
PATCH/PUT /case_types/1 PATCH/PUT /case_types/1.json
def update respond_to do |format| if @case_type.update(case_type_params) format.html { redirect_to @case_type, notice: 'Case type was successfully updated.' } format.json { render :show, status: :ok, location: @case_type } else format.html { render :edit } format.json { r...
[ "def patch_entity_type(entity_type_id, request)\n start.uri('/api/entity/type')\n .url_segment(entity_type_id)\n .body_handler(FusionAuth::JSONBodyHandler.new(request))\n .patch()\n .go()\n end", "def update\n standard_update(ContactType, params[:id], contact_type_pa...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
DELETE /case_types/1 DELETE /case_types/1.json
def destroy @case_type.destroy respond_to do |format| format.html { redirect_to case_types_url, notice: 'Case type was successfully destroyed.' } format.json { head :no_content } end end
[ "def destroy\n @capital_type = CapitalType.find(params[:id])\n @capital_type.destroy\n\n respond_to do |format|\n format.html { redirect_to capital_types_url }\n format.json { head :ok }\n end\n end", "def destroy\n @c_type.destroy\n respond_to do |format|\n format.html { redirec...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
return name of first file in the list that is readable, otherwise log and return nil.
def get_readable_config_file_name(candidate_files) none_found = lambda { # TODO: replace with logger. puts "FATAL: #{self.class.to_s}:#{__method__}:#{__LINE__}: cannot readable configuration file: in [#{candidate_files}]" nil } candidate_files.detect(none_found) { |f| verify_file_is_usable(f) } end
[ "def filename\n # just checking the first file (which is the file where an object\n # is first declared)\n files.first\n end", "def filename\n # just checking the first file (which is the file where an\n # object is first declared)\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Assigns the root bone in skeleton
def root=(a); skeleton.root = a; end
[ "def root; skeleton.root; end", "def set_root comp, trans=Geom::Transformation.new, joint=[0,0,0]\r\n raise \"First set_root argument must be a ComponentDefinition\" unless comp.kind_of? Sketchup::ComponentDefinition\r\n @root_bone = Bone.new comp, trans, joint\r\n end", "def set_root(node)\n @...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns the root bone in skeleton
def root; skeleton.root; end
[ "def skeleton; @skeletons.first; end", "def root_node\n root_nodes.first\n end", "def root=(a); skeleton.root = a; end", "def root_node\n return constant_segments.first\n end", "def root\n roots.first\n end", "def root\n @levels[-1].first\n end", "def getRoot\n @...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns the last frame associated with this animation.
def last_frame; frames.last; end
[ "def last\r\n @frames.last\r\n end", "def last\n @msg_frames.last\n end", "def last_frame_no\n @ranges[-1].end\n end", "def find_current_frame\n if open_frame? || final_frame_with_bonus?\n @frame = player.frames.last\n end\n @frame\n end", "def last_defined_frame\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Sets the amount of time, in seconds, each frame occupies. Most BVH files have this set to 0.333333, which is equal to 30 frames per second.
def frame_time=(a); motion.frame_time = a; end
[ "def frames_per_second=(a); self.frame_time = 1 / a; end", "def frames_per_second=(a); motion.frames_per_second = a; end", "def frames_per_second; 1 / frame_time; end", "def update\n if @frameCounter < 60 then\n @frameCounter += 1\n else\n @frameCounter = 0\n if @totalTime != 0 then\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Assigns the frame_time by calculating it from (1 / frames_per_second)
def frames_per_second=(a); motion.frames_per_second = a; end
[ "def frames_per_second=(a); self.frame_time = 1 / a; end", "def frames_per_second; 1 / frame_time; end", "def frame_time=(a); motion.frame_time = a; end", "def frame_interval\n 1.0/@fps\n end", "def frame_rate frames, duration\n frames.to_f * 1000000 / duration\nend", "def update\n if @frameCoun...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns the number of frames in the motion capture data.
def frame_count; motion.frame_count; end
[ "def frame_count\n frames.length\n end", "def frame_count\n image.get(\"height\") / size.y\n end", "def frame_count; end", "def size\n frames.inject(0) do |sum, frame|\n sum += frame.bytesize\n end\n end", "def framecount\n return -1 if demo.nil?\n demos = decod...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns the first (and usually the only) skeleton in the skeletons array.
def skeleton; @skeletons.first; end
[ "def create_skeleton!; (@skeletons << Bvh::Skeleton.new).last; end", "def first\n self.take(1)[0]\n end", "def locate_head\n snake_matrix.first\n end", "def first flavor = nil\n self[0, flavor]\n end", "def first_element\n return nil if self.is_empty?\n @words[0]\n end", "def first\...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Creates a new skeleton, adds it to the skeletons array, and returns it.
def create_skeleton!; (@skeletons << Bvh::Skeleton.new).last; end
[ "def skeleton; @skeletons.first; end", "def skeleton\n puts \"Copying skeleton ...\"\n system(\"cp -Rf skeleton/* #{@dir}/\")\n end", "def root; skeleton.root; end", "def skeletonCreate template, desiredName\n t = ERB.new File.read template\n t.filename = template # to report errors relative ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Exports this BVH into the specified file.
def export(file) exporter = Bvh::Exporter.new(file) exporter.export(self) self end
[ "def export\n @scenario.export\n send_file \"#{@scenario.bin_file_name}.new\", type: 'application/octet-stream'\n end", "def write_back!\n File.open(@filename, 'w') do |file|\n export_to file\n end\n end", "def export_table_to_file(table)\n export_table.export_one_table(get_case_name()...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
include GMath3D Uses Parmeters for x, y, z if no vector is given mesh => TriMesh, :vector => Vector3, :x => Float, :y => Float, :z => Float
def translate(mesh, params = {}) raise StandardError, ":mesh is nil or not a TriMesh" if (mesh.nil? || !(mesh.kind_of? TriMesh)) raise StandardError, ":vector is not a Vector3" if not (params[:vector].kind_of? Vector3 ) and not params[:vector].nil? raise StandardError, "Choose :vector or :x,:y,:z to translate" if ((...
[ "def vector_class; Vec3d; end", "def initialize(x, y, z)\n raise \"Incorrect x argument for Vector3D, expected Numeric but got #{x.class}\" unless x.is_a?(Numeric)\n raise \"Incorrect y argument for Vector3D, expected Numeric but got #{y.class}\" unless y.is_a?(Numeric)\n raise \"Incorrect z argume...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Choose :factor or x,y,z. :vector is optional. mesh => TriMesh, :factor => Float, :vector => Vector3, :x => Float, :y => Float, :z => Float
def scale(mesh, params = {}) raise StandardError, ":mesh is nil or not a TriMesh" if (mesh.nil? || !(mesh.kind_of? TriMesh)) raise StandardError, "Choose one. :factor or :x,:y,:z " if ((not params[:factor].nil?) and ( not params[:x].nil? or not params[:y].nil? or not params[:z].nil?)) raise StandardError, ":vector i...
[ "def stretch(mesh, params = {})\n\traise StandardError, \":mesh is nil or not a TriMesh\" if (mesh.nil? || !(mesh.kind_of? TriMesh))\n\traise StandardError, \":axis is nil or not a Symbol\" if (params[:axis].nil? || !(params[:axis].kind_of? Symbol))\n\traise StandardError, \":axis should be :x :y or :z\" if (params...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
:vector is optional mesh => TriMesh, :degree => Float, :axis => Symbol/Line, :vector => Vector3
def rotate(mesh, params = {}) raise StandardError, ":mesh is nil or not a TriMesh" if (mesh.nil? or !(mesh.kind_of? TriMesh)) raise StandardError, ":degree is nil or not a Number" if (params[:degree].nil? or !(params[:degree].is_a? Numeric)) raise StandardError, "Define :axis with :x, :y, :z or as a Line" if (params...
[ "def vector_class; Vec3d; end", "def mirror(mesh,params = {})\n\traise StandardError, \":mesh is nil or not a TriMesh\" if (mesh.nil? || !(mesh.kind_of? TriMesh))\n\traise StandardError, \":axis is nil or not a Symbol\" if (params[:axis].nil? || !(params[:axis].kind_of? Symbol))\n\traise StandardError, \":axis sh...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
:vector is optional mesh => TriMesh, :axis => Symbol, :vetor => Vector3
def mirror(mesh,params = {}) raise StandardError, ":mesh is nil or not a TriMesh" if (mesh.nil? || !(mesh.kind_of? TriMesh)) raise StandardError, ":axis is nil or not a Symbol" if (params[:axis].nil? || !(params[:axis].kind_of? Symbol)) raise StandardError, ":axis should be :x :y or :z" if (params[:axis] != :x) and ...
[ "def vector_class; Vec3d; end", "def rotate(mesh, params = {})\n\traise StandardError, \":mesh is nil or not a TriMesh\" if (mesh.nil? or !(mesh.kind_of? TriMesh))\n\traise StandardError, \":degree is nil or not a Number\" if (params[:degree].nil? or !(params[:degree].is_a? Numeric))\n\traise StandardError, \"Def...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
:vector is optional :mesh => TriMesh, :factor => Float, :axis => Symbol, :vetor => Vector3
def stretch(mesh, params = {}) raise StandardError, ":mesh is nil or not a TriMesh" if (mesh.nil? || !(mesh.kind_of? TriMesh)) raise StandardError, ":axis is nil or not a Symbol" if (params[:axis].nil? || !(params[:axis].kind_of? Symbol)) raise StandardError, ":axis should be :x :y or :z" if (params[:axis] != :x) an...
[ "def vector_class; Vec3d; end", "def extract_vector3d!\n a = self\n if false and a.length == 0 then raise \"Expected vector coordinates\"\n elsif a.length >= 4 and a[0].kind_of? Numeric and a[1].kind_of? Numeric and a[2].kind_of? Numeric and\n a[3].kind_of? Numeric\n return Vector3d.new(a...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Set current rates timestamp
def rates_timestamp=(at) @rates_timestamp = Time.at(at) end
[ "def set_rate_with_time(from, to, rate)\n rate_d = BigDecimal.new(rate.to_s)\n @mutex.synchronize {\n @rates[rate_key_for(from, to)] = {rate: rate_d, created_at: Time.now}\n }\n rate_d\n end", "def rates_timestamp\n raw = raw_rates_careful\n raw.key?('timest...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Update all rates from openexchangerates JSON
def update_rates store.transaction do clear_rates! exchange_rates.each do |exchange_rate| rate = exchange_rate.last currency = exchange_rate.first next unless Money::Currency.find(currency) set_rate(source, currency, rate) set_rate...
[ "def update_rates\n clear_rates\n add_currency_rate(\"EUR\", 1)\n add_currency_rates(config[\"exchange_rates\"]) # rates from bank.yml\n \n fetch_rates.each do |currency_rate|\n add_currency_rate(currency_rate[:currency], currency_rate[:rate].to_f)\n end\n @@config['excha...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Expire rates when expired
def expire_rates return unless ttl_in_seconds return if rates_expiration > Time.now refresh_rates if force_refresh_rate_on_expire update_rates refresh_rates_expiration end
[ "def refresh_rates_expiration!\n @rates_expiration = Time.now + ttl_in_seconds\n end", "def expire_rates!\n if expired?\n update_rates(true)\n true\n elsif stale?\n update_rates\n true\n else\n false\n end\n end", "def...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Source url of openexchangerates defined with app_id
def source_url str = "#{oer_url}?app_id=#{app_id}" str = "#{str}&base=#{source}" unless source == OE_SOURCE str = "#{str}&show_alternative=#{show_alternative}" str = "#{str}&prettyprint=#{prettyprint}" str = "#{str}&symbols=#{symbols.join(',')}" if symbols&.is_a?(Array) s...
[ "def url_definer\n url = EBAYOPENURL+\"?callname=#{@callname}&responseencoding=#{RESPONSEENCODING}&appid=#{@app_id}&siteid=0&UserID=#{@user_id}&IncludeSelector=Details&version=#{APIVERSION}\"\n return url\n end", "def source_uri\n URI.parse(url_for(@software))\n end", "def app_url\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Save rates on cache Can raise InvalidCache
def save_cache store_in_cache(@json_response) if valid_rates?(@json_response) rescue Errno::ENOENT raise InvalidCache end
[ "def cache_rate(original, target, rate)\n Rails.cache.write(\"#{original}_#{target}_#{stringified_exchange_date}\", rate) if defined?(Rails)\n end", "def cache_pricing!\n cache_pricing\n save!\n end", "def set_rate(from_cur, to_cur, rate)\n\t\t@cache.transaction do\n\t\t\t@cache[ [from_cur,...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Latest url if no date given
def oer_url if date historical_url else latest_url end end
[ "def api_url(time=nil)\n today = Time.now\n [API_URL, time && (time.year != today.year || time.yday != today.yday) ? \"historical/#{time.strftime(\"%Y-%m-%d\")}.json\" : 'latest.json'].join('/')\n end", "def top_url_on_date(date)\n top_urls_on_date_query(date).limit(1).all\n end",...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Historical url generated from `date` attr_accessor
def historical_url URI.join(OER_HISTORICAL_URL, "#{date}.json") end
[ "def oer_url\n if date\n historical_url\n else\n latest_url\n end\n end", "def generate_history_url\n\n\t\t\t\turl = 'http://ichart.finance.yahoo.com/table.csv?s=%s&a=%s&b=%s&c=%s&d=%s&e=%s&f=%s&g=%s&ignore=.csv' % [\n\t\t\t\t\t@symbol,\n\t\t\t\t\t@start_date.to_date.mo...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Tries to calculate a pair rate using base currency rate
def calc_pair_rate_using_base(from_currency, to_currency, opts) from_base_rate = get_rate_or_calc_inverse(source, from_currency, opts) to_base_rate = get_rate_or_calc_inverse(source, to_currency, opts) return unless to_base_rate return unless from_base_rate rate = BigDecimal(t...
[ "def calc_pair_rate_using_base(from_currency, to_currency, opts = {})\n from_base_rate = get_rate_or_calc_inverse(source, from_currency, opts)\n to_base_rate = get_rate_or_calc_inverse(source, to_currency, opts)\n if to_base_rate && from_base_rate\n rate = to_base_rate / from_base_ra...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Clears cached rates in store
def clear_rates! store.each_rate do |iso_from, iso_to| add_rate(iso_from, iso_to, nil) end end
[ "def clear_rates\n transaction { @index = {} }\n end", "def clear_cache!\n # this should be overridden by concrete adapters\n end", "def clear_cache; end", "def clear!\n NastyCache.instance.delete(\"#{name}#all\")\n NastyCache.instance.delete(\"#{name}#records\")\n end", "de...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
250ml is 168calories Therefore...
def calories_per_liter 672 end
[ "def calculate_calories(bodyweight)\n\ttotal_calories = bodyweight * 13\n\treturn total_calories\nend", "def value_per_100g; nutr_val; end", "def defense_bonus(lv)\n (80 * 3 * lv.to_f / 2 + 250) / 100 + 5\n end", "def kilos\n grams.to_f / 1000\n end", "def convert_to_m(height_inches)\n height_inche...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
The block should return the response JSON data in case of not authorized requests. If the request is not authorized other +on__request+ functions simple will drop their blocks and this data will be send to Alexa.
def on_unauthorized_request if block_given? && !authorized? @response = yield end end
[ "def ignore_request(&block); end", "def on_intent_request\n if authorized? && request_type.intent? && block_given?\n @response = yield user\n end\n end", "def deny(&block)\n evaluate_with_response(false, &block)\n end", "def handle_request( request, &block )\n\t\tif...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
LaunchRequest is a simple type of request. It doesn't need its own handler class
def on_launch_request if authorized? && request_type.launch? && block_given? @response = yield user end end
[ "def launch_requests launch_key\n request :get, resource_uri(\"launchRequests\", @format), {:launch_key => launch_key}\n end", "def launch_request?\n lti_message_type == 'basic-lti-launch-request'\n end", "def message\n message = IMS::LTI::Models::Messages::BasicLTILaunchRequest.new(reque...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
IntentRequest type is not so simple as LaunchRequest is. Here need to pass to the block an instance of IntentHandler class with suitable functionality to deal with the request, rather than the user object.
def on_intent_request if authorized? && request_type.intent? && block_given? @response = yield user end end
[ "def on_launch_request\n if authorized? && request_type.launch? && block_given?\n @response = yield user\n end\n end", "def before_intent_handler(controller, intent)\n return intent\n end", "def on_global_request(type, &block); end", "def on_request &b\n @r...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
Returns billing amount (sum of net amount + taxes)
def billing_amount self.net_amount + self.taxes_amount end
[ "def calculate_tax_cost\n purchase_items.inject zero do |total, purchase|\n total += purchase.try(:tax_cost) || zero\n end\n end", "def calculate_billing_price\n show_items\n self.discount.get_discount(self)\n print_billing_details\n self\n end", "def total_tax\n ...
{ "objective": { "paired": [], "self": [], "triplet": [ [ "query", "document", "negatives" ] ] } }