query
stringlengths
7
9.55k
document
stringlengths
10
363k
metadata
dict
negatives
listlengths
0
101
negative_scores
listlengths
0
101
document_score
stringlengths
3
10
document_rank
stringclasses
102 values
comments/_comment expects Comment objects to have a comment_vote attribute with the current user's vote added by StoriesController.load_user_votes
def apply_current_vote @replies.each do |r| next unless r.current_vote_vote.present? r.comment.current_vote = { vote: r.current_vote_vote, reason: r.current_vote_reason.to_s, } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def set_commentvote\n @commentvote = @comment.commentvotes.find(params[:id])\n end", "def create_vote\n\n @comment = Comment.find(params[:id])\n\n if current_user.present?\n # upvote\n if params[:vote] == \"1\"\n # if user already upvoted, then 'unvote'\n if current_user.vot...
[ "0.7360153", "0.71245986", "0.6807405", "0.67968625", "0.67515254", "0.67418766", "0.66354275", "0.649712", "0.6465872", "0.6461343", "0.6428946", "0.6411353", "0.6401192", "0.63977134", "0.6390306", "0.63594574", "0.6354211", "0.6352512", "0.63429207", "0.63152915", "0.63106...
0.0
-1
Returns the connection currently associated with the class. This can also be used to "borrow" the connection to do database work that isn't easily done without going straight to SQL.
def connection self.class.connection end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def connection\n @connection_class.connection\n end", "def connection\n retrieve_connection\n end", "def connection\n if defined?(@active_connection_name) && (conn = active_connections[@active_connection_name])\n conn\n else\n # retrieve_connection sets the c...
[ "0.7434031", "0.7427701", "0.74006915", "0.7339419", "0.73326933", "0.7327713", "0.73135257", "0.72716516", "0.726274", "0.7160539", "0.71546453", "0.71371424", "0.710791", "0.70767236", "0.70614284", "0.6996787", "0.6987539", "0.6969524", "0.6949109", "0.693283", "0.69235486...
0.7325201
10
Works like find, but the record matching +id+ must also meet the +conditions+. +RecordNotFound+ is raised if no record can be found matching the +id+ or meeting the condition. Example: Person.find_on_conditions 5, "first_name LIKE '%dav%' AND last_name = 'heinemeier'"
def find_on_conditions(id, conditions) find_first("#{primary_key} = '#{sanitize(id)}' AND #{sanitize_conditions(conditions)}") || raise(RecordNotFound, "Couldn't find #{name} with #{primary_key} = #{id} on the condition of #{conditions}") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def find_by(conditions={})\n raise ArgumentError if conditions.empty?\n query = %(SELECT * FROM #{table_name} #{build_condition(conditions)})\n res = connection.execute(query).first\n\n if res.nil?\n raise RecordNotFound\n end\n res.extend Result::Behavior\n ...
[ "0.7193575", "0.66422355", "0.6584137", "0.6367957", "0.61102057", "0.60732067", "0.60459304", "0.6042565", "0.5993642", "0.59430516", "0.585085", "0.5849643", "0.5789775", "0.56721187", "0.559682", "0.5582276", "0.55526245", "0.5508145", "0.5506397", "0.5473242", "0.54669714...
0.83629453
0
Returns an array of all the objects that could be instantiated from the associated table in the database. The +conditions+ can be used to narrow the selection of objects (WHEREpart), such as by "color = 'red'", and arrangement of the selection can be done through +orderings+ (ORDER BYpart), such as by "last_name, first_name DESC". A maximum of returned objects can be specified in +limit+. Example: Project.find_all "category = 'accounts'", "last_accessed DESC", 15
def find_all(conditions = nil, orderings = nil, limit = nil, joins = nil) sql = "SELECT * FROM #{table_name} " sql << "#{joins} " if joins add_conditions!(sql, conditions) sql << "ORDER BY #{orderings} " unless orderings.nil? sql << "LIMIT #{limit} " unless limit.nil? find_by_sql(sql) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def all(conditions = [])\n conditions ||= []\n\n # query conditions must come first\n conditions.sort_by! { |v| v.is_a?(Hash) ? 0 : 1 }\n\n results = conditions.reduce(model.all) do |query, cond|\n case cond\n when Hash\n cond.reduce(query) { |query, (cond, val)| query.se...
[ "0.6421074", "0.62483066", "0.61236125", "0.60129184", "0.5856991", "0.58181053", "0.5798588", "0.57353926", "0.5702692", "0.5657031", "0.5635174", "0.56218916", "0.5610332", "0.56040746", "0.5576714", "0.5564902", "0.554641", "0.5510026", "0.55074215", "0.5486229", "0.54659"...
0.7211127
0
Works like find_all, but requires a complete SQL string. Example: Post.find_by_sql "SELECT p., c.author FROM posts p, comments c WHERE p.id = c.post_id"
def find_by_sql(sql) connection.select_all(sql, "#{name} Load").inject([]) { |objects, record| objects << instantiate(record) } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def find_by_sql(sql)\n raise \"not implemented\"\n end", "def find_by_sql(sql, binds = [], preparable: nil, &block)\n result_set = connection.select_all(sanitize_sql(sql), \"#{name} Load\", binds, preparable: preparable)\n column_types = {}\n message_bus = ActiveSupport::Notifica...
[ "0.6453624", "0.60727686", "0.5866462", "0.553484", "0.5443337", "0.5443107", "0.537442", "0.53309566", "0.53045595", "0.52735764", "0.5228147", "0.52122116", "0.51849616", "0.5174502", "0.51433486", "0.51168036", "0.51044166", "0.50949275", "0.5091601", "0.5081923", "0.50310...
0.6202287
1
Returns the object for the first record responding to the conditions in +conditions+, such as "group = 'master'". If more than one record is returned from the query, it's the first that'll be used to create the object. In such cases, it might be beneficial to also specify +orderings+, like "income DESC, name", to control exactly which record is to be used. Example: Employee.find_first "income > 50000", "income DESC, name"
def find_first(conditions = nil, orderings = nil) sql = "SELECT * FROM #{table_name} " add_conditions!(sql, conditions) sql << "ORDER BY #{orderings} " unless orderings.nil? sql << "LIMIT 1" record = connection.select_one(sql, "#{name} Load First") instantiate(record) unless record.nil? end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def first(*conditions)\n record = DB.client.query(query(conditions)).first\n return unless record\n\n instance_type.new(@record_type, record, @mapping)\n end", "def first_or_new(conditions = {}, attributes = {})\n first(conditions) || new(conditions.merge(attributes))\n ...
[ "0.78745914", "0.7124159", "0.70870703", "0.69695026", "0.692387", "0.6803515", "0.67914844", "0.67484206", "0.66949964", "0.66400146", "0.66400146", "0.6634829", "0.6628412", "0.6600696", "0.65242535", "0.648546", "0.6475553", "0.6453528", "0.6412244", "0.6408845", "0.638388...
0.7817769
1
Creates an object, instantly saves it as a record (if the validation permits it), and returns it. If the save fail under validations, the unsaved object is still returned.
def create(attributes = nil) object = new(attributes) object.save object end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def save\n valid? && create\n end", "def create(params_or_record)\n object = self.new(params_or_record).save\n return(object)\n end", "def create!\n raise \"#{self.inspect} failed to save\" unless self.create\n end", "def save!\n create_or_update or raise RecordNotSaved\n e...
[ "0.73186314", "0.72262406", "0.68885374", "0.68165386", "0.66781557", "0.6655675", "0.66357684", "0.65977985", "0.6521376", "0.65082353", "0.64985514", "0.64914024", "0.6489325", "0.6467419", "0.6456772", "0.6455353", "0.6445195", "0.6386386", "0.6375246", "0.6375246", "0.637...
0.0
-1
Finds the record from the passed +id+, instantly saves it with the passed +attributes+ (if the validation permits it), and returns it. If the save fail under validations, the unsaved object is still returned.
def update(id, attributes) object = find(id) object.attributes = attributes object.save object end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update_or_create(attributes = {})\n id = attributes.delete(:id)\n conditions = attributes.delete(:conditions)\n\n returning (id && find_by_id(id)) || find(:first, :conditions => conditions) || new do |record|\n attributes.each_pair { |key, value| record[key] = value }\n record.save...
[ "0.65191114", "0.6492113", "0.64524704", "0.63850814", "0.6243928", "0.62344337", "0.6184001", "0.61632425", "0.61381274", "0.6129781", "0.606567", "0.6064046", "0.6012709", "0.59707284", "0.59707284", "0.5953078", "0.59256876", "0.58967924", "0.5812175", "0.57668144", "0.576...
0.60920316
10
Updates all records with the SETpart of an SQL update statement in +updates+. A subset of the records can be selected by specifying +conditions+. Example: Billing.update_all "category = 'authorized', approved = 1", "author = 'David'"
def update_all(updates, conditions = nil) sql = "UPDATE #{table_name} SET #{updates} " add_conditions!(sql, conditions) connection.update(sql, "#{name} Update") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update_all(updates, conditions = nil)\n # TODO\n raise \"not implemented\"\n# sql = \"UPDATE #{table_name} SET #{sanitize_sql(updates)} \"\n# add_conditions!(sql, conditions, scope(:find))\n# connection.update(sql, \"#{name} Update\")\n end", "def update(*updates, ...
[ "0.8584458", "0.7496522", "0.70332855", "0.6911325", "0.6902273", "0.6869133", "0.6746684", "0.6698043", "0.66475546", "0.66107106", "0.6536667", "0.6504917", "0.65040004", "0.6492182", "0.64846104", "0.64835197", "0.64063174", "0.6379566", "0.6325436", "0.6278427", "0.623146...
0.8371964
1
Destroys the objects for all the records that matches the +condition+ by instantiating each object and calling the destroy method. Example: Person.destroy_all "last_login < '20040404'"
def destroy_all(conditions = nil) find_all(conditions).each { |object| object.destroy } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def destroy_all(conditions=nil)\n if conditions\n where(conditions).destroy_all\n else\n to_a.each {|object| object.destroy}\n @records\n end\n end", "def destroy_all\n klass.destroy_all(:conditions => selector)\n end", "def delete_all(conditions...
[ "0.75498116", "0.7085377", "0.6884821", "0.67255247", "0.67008513", "0.66999465", "0.66311044", "0.6518341", "0.6457921", "0.6286879", "0.6254199", "0.6238277", "0.6186769", "0.6182691", "0.6141057", "0.61219394", "0.6118138", "0.6024562", "0.60120493", "0.6011569", "0.598997...
0.7897421
0
Deletes all the records that matches the +condition+ without instantiating the objects first (and hence not calling the destroy method). Example: Post.destroy_all "person_id = 5 AND (category = 'Something' OR category = 'Else')"
def delete_all(conditions = nil) sql = "DELETE FROM #{table_name} " add_conditions!(sql, conditions) connection.delete(sql, "#{name} Delete all") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def delete_all(conditions = \"\")\n collection.remove(XGen::SQL::Parser.parse_where(conditions, true) || {})\n end", "def destroy_all(conditions = nil)\n find_all(conditions).each { |object| object.destroy }\n end", "def destroy_all(conditions=nil)\n if conditions\n wher...
[ "0.748002", "0.7457859", "0.7385467", "0.73071027", "0.6915436", "0.6912978", "0.63635284", "0.6356751", "0.6343812", "0.6304913", "0.62581444", "0.6207597", "0.614575", "0.6134835", "0.60775054", "0.60645384", "0.6018686", "0.60010386", "0.5960252", "0.59454095", "0.5921677"...
0.65202504
6
Returns the number of records that meets the +conditions+. Zero is returned if no records match. Example: Product.count "sales > 1"
def count(conditions = nil) sql = "SELECT COUNT(*) FROM #{table_name} " add_conditions!(sql, conditions) count_by_sql(sql) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def count\n filtered = apply_criteria(@data)\n filtered.count\n end", "def get_count conditions = []\n resp = $es.search(index: es_type_name, type: es_type_name, body: {\n query: get_query_body(conditions),\n size: 0\n })\n return resp['hits']['total']\n end", "def ...
[ "0.7877142", "0.747284", "0.72063774", "0.7065296", "0.68807256", "0.67597103", "0.67357916", "0.66544026", "0.66482913", "0.6636313", "0.6623195", "0.6597532", "0.65660876", "0.65582955", "0.6536554", "0.64953583", "0.6494122", "0.6494122", "0.6485449", "0.6476347", "0.64259...
0.80236846
0
Returns the result of an SQL statement that should only include a COUNT() in the SELECT part. Product.count "SELECT COUNT() FROM sales s, customers c WHERE s.customer_id = c.id"
def count_by_sql(sql) count = connection.select_one(sql, "#{name} Count").values.first return count ? count.to_i : 0 end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def db_query_transform__count query\n tmp_table = \"resultset_table\"\n make_tmp_table = db_query_transform__subquery query, tmp_table\n \"SELECT COUNT(*) FROM #{make_tmp_table}\"\n end", "def customer_count\n sql = \"SELECT c.* FROM customers c INNER JOIN tickets t ON t.customer_id = c.id WHERE t.film...
[ "0.7204354", "0.7122254", "0.6992073", "0.69248474", "0.6814859", "0.6721586", "0.6686181", "0.6663617", "0.6638476", "0.6615994", "0.6526876", "0.6445054", "0.6441789", "0.6441789", "0.6397782", "0.6393931", "0.63697493", "0.63532895", "0.63440096", "0.6341644", "0.6337527",...
0.67490566
5
Increments the specified counter by one. So DiscussionBoard.increment_counter("post_count", discussion_board_id) would increment the "post_count" counter on the board responding to discussion_board_id. This is used for caching aggregate values, so that they doesn't need to be computed every time. Especially important for looping over a collection where each element require a number of aggregate values. Like the DiscussionBoard that needs to list both the number of posts and comments.
def increment_counter(counter_name, id) update_all "#{counter_name} = #{counter_name} + 1", "#{primary_key} = #{id}" end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def increment_counter\n unless self.count.nil?\n self.count += 1\n else\n self.count = 1\n end\n end", "def increment_board_comments_counter\n Board.increment_counter(:comments_count, self.post.board.id)\n end", "def increment_counter(counter_name, id)\n rec = collect...
[ "0.7157974", "0.71031505", "0.6709966", "0.6649695", "0.65623504", "0.6538833", "0.6532185", "0.6519274", "0.64654934", "0.64308137", "0.63668984", "0.6360064", "0.6286406", "0.6276584", "0.6197685", "0.61895233", "0.6168963", "0.61363554", "0.60507125", "0.6022149", "0.59771...
0.6678114
3
Works like increment_counter, but decrements instead.
def decrement_counter(counter_name, id) update_all "#{counter_name} = #{counter_name} - 1", "#{primary_key} = #{id}" end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def decrement\n @counter = @counter - 1\n end", "def decr_counter!(name, decr = 1)\n counter = self.send(name.to_sym)\n counter.decr(val)\n save\n counter.reconcile!\n end", "def decrease(counter)\n counter -= 1\nend", "def decrease(counter)\r\n counter - 1\r\nend", "def decrem...
[ "0.8006142", "0.77532923", "0.75025594", "0.74317753", "0.7370954", "0.72830033", "0.72830033", "0.72830033", "0.72830033", "0.72830033", "0.727177", "0.7212647", "0.72107637", "0.7158711", "0.7142695", "0.7091533", "0.70880103", "0.69924366", "0.69786656", "0.69462985", "0.6...
0.7666841
2
Returns an array of all the attributes that have been protected from massassigment.
def protected_attributes # :nodoc: read_inheritable_attribute("attr_protected") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def attributes_protected_by_default\n []\n end", "def _filtered_attributes\n return accessible_attributes.to_a if accessible_attributes.present?\n\n return self.new.attributes.keys - protected_attributes.to_a\n end", "def allowed_attributes\n self.new.attributes.keys.reject ...
[ "0.69284916", "0.6890298", "0.6865867", "0.6626099", "0.656327", "0.6551074", "0.6540335", "0.6536151", "0.6482304", "0.6427557", "0.6415243", "0.6400707", "0.63915086", "0.6378748", "0.6365643", "0.6321173", "0.6317594", "0.6313826", "0.6260577", "0.6246865", "0.61385876", ...
0.6549659
6
If this macro is used, only those attributed named in it will be accessible for massassignment, such as new(attributes) and attributes=(attributes). This is the more conservative choice for massassignment protection. If you'd rather start from an allopen default and restrict attributes as needed, have a look at attr_protected.
def attr_accessible(*attributes) write_inheritable_array("attr_accessible", attributes) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def allowed_attributes=(_arg0); end", "def allowed_attributes=(_arg0); end", "def protected_attributes=(attributes = nil)\n attributes = attributes.is_a?(Hash) ? attributes.symbolize_keys : {}\n send :attributes=, attributes.only(:author, :email, :summary, :content, :attachment), false\n end", "def at...
[ "0.6674789", "0.6674789", "0.66704303", "0.65875965", "0.654351", "0.64841837", "0.6452346", "0.63946927", "0.63906246", "0.63245356", "0.6307896", "0.62943584", "0.6289147", "0.62836665", "0.62299967", "0.62299967", "0.62258655", "0.6179746", "0.61165524", "0.61146384", "0.6...
0.6040362
28
Returns an array of all the attributes that have been made accessible to massassigment.
def accessible_attributes # :nodoc: read_inheritable_attribute("attr_accessible") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def attributes\n @attributes ||= []\n @attributes\n end", "def attributes\n @allowed_attributes\n end", "def attributes\n @attrs.keys\n end", "def attributes\n @attributes ||= []\n end", "def get_attributes\n\t\t\t@@attributes\n\t\tend", "def attribu...
[ "0.708357", "0.701817", "0.701761", "0.69720477", "0.6929569", "0.68705064", "0.68070537", "0.68046045", "0.67750514", "0.6770461", "0.6765877", "0.6764538", "0.6751183", "0.6744065", "0.6729116", "0.6719858", "0.6719858", "0.6719858", "0.671883", "0.6716692", "0.6674559", ...
0.6843084
6
Specifies that the attribute by the name of +attr_name+ should be serialized before saving to the database and unserialized after loading from the database. The serialization is done through YAML. If +class_name+ is specified, the serialized object must be of that class on retrival or +SerializationTypeMismatch+ will be raised.
def serialize(attr_name, class_name = Object) write_inheritable_attribute("attr_serialized", serialized_attributes.update(attr_name.to_s => class_name)) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def unserialize_attribute(attr_name)\n unserialized_object = object_from_yaml(@attributes[attr_name])\n\n if unserialized_object.is_a?(self.class.serialized_attributes[attr_name])\n @attributes[attr_name] = unserialized_object\n else\n raise(\n SerializationTypeMis...
[ "0.6603017", "0.6203735", "0.53822124", "0.53492856", "0.52719975", "0.52719975", "0.526703", "0.526703", "0.526703", "0.526703", "0.526703", "0.5209125", "0.52029276", "0.51429605", "0.5069251", "0.50296044", "0.5025081", "0.4966969", "0.49576774", "0.49390504", "0.49388403"...
0.74359035
0
Returns a hash of all the attributes that have been specified for serialization as keys and their class restriction as values.
def serialized_attributes read_inheritable_attribute("attr_serialized") || { } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def attributes_hash\n attributes = @serializable.attributes\n if options[:only].any?\n attributes.slice(*options[:only])\n elsif options[:except].any?\n attributes.except(*options[:except])\n else\n attributes\n end\n ...
[ "0.77989084", "0.76965827", "0.7661096", "0.7657063", "0.7646766", "0.7547972", "0.750524", "0.74603325", "0.74318403", "0.74093866", "0.738598", "0.73435354", "0.734351", "0.7303109", "0.7301551", "0.7272169", "0.7239739", "0.7231333", "0.7229695", "0.7229695", "0.72291464",...
0.7173776
27
Guesses the table name (in forced lowercase) based on the name of the class in the inheritance hierarchy descending directly from ActiveRecord. So if the hierarchy looks like: Reply < Message < ActiveRecord, then Message is used to guess the table name from even when called on Reply. The guessing rules are as follows: Class name ends in "x", "ch" or "ss": "es" is appended, so a Search class becomes a searches table. Class name ends in "y" preceded by a consonant or "qu": The "y" is replaced with "ies", so a Category class becomes a categories table. Class name ends in "fe": The "fe" is replaced with "ves", so a Wife class becomes a wives table. Class name ends in "lf" or "rf": The "f" is replaced with "ves", so a Half class becomes a halves table. Class name ends in "person": The "person" is replaced with "people", so a Salesperson class becomes a salespeople table. Class name ends in "man": The "man" is replaced with "men", so a Spokesman class becomes a spokesmen table. Class name ends in "sis": The "i" is replaced with an "e", so a Basis class becomes a bases table. Class name ends in "tum" or "ium": The "um" is replaced with an "a", so a Datum class becomes a data table. Class name ends in "child": The "child" is replaced with "children", so a NodeChild class becomes a node_children table. Class name ends in an "s": No additional characters are added or removed. Class name doesn't end in "s": An "s" is appended, so a Comment class becomes a comments table. Class name with word compositions: Compositions are underscored, so CreditCard class becomes a credit_cards table. Additionally, the classlevel table_name_prefix is prepended to the table_name and the table_name_suffix is appended. So if you have "myapp_" as a prefix, the table name guess for an Account class becomes "myapp_accounts". You can also overwrite this class method to allow for unguessable links, such as a Mouse class with a link to a "mice" table. Example: class Mouse < ActiveRecord::Base def self.table_name() "mice" end end
def table_name(class_name = nil) if class_name.nil? class_name = class_name_of_active_record_descendant(self) table_name_prefix + undecorated_table_name(class_name) + table_name_suffix else table_name_prefix + undecorated_table_name(class_name) + table_name_suffix end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def undecorated_table_name(class_name = class_name_of_active_record_descendant(self))\n table_name = Inflector.underscore(Inflector.demodulize(class_name))\n table_name = Inflector.pluralize(table_name) if pluralize_table_names\n return table_name\n end", "def table_name\n ...
[ "0.6387122", "0.6376016", "0.6332701", "0.6220782", "0.6194269", "0.61544853", "0.6110727", "0.6075447", "0.6075447", "0.6067582", "0.6049635", "0.60493946", "0.6009812", "0.60055345", "0.59759593", "0.5942469", "0.59192234", "0.59156835", "0.58908576", "0.58880335", "0.58809...
0.6165768
5
Defines the primary key field can be overridden in subclasses. Overwritting will negate any effect of the primary_key_prefix_type setting, though.
def primary_key case primary_key_prefix_type when :table_name Inflector.foreign_key(class_name_of_active_record_descendant(self), false) when :table_name_with_underscore Inflector.foreign_key(class_name_of_active_record_descendant(self)) else "id" end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def primary_key(name, type = :primary_key, options = {})\n return super\n end", "def primary_key=(name, options = {})\n field name, options\n @config.primary_key = name.to_sym\n end", "def primary_key=(value)\n @primary_key = value && value.to_s\n @quoted_p...
[ "0.77812845", "0.7453644", "0.7387993", "0.7305334", "0.7240913", "0.7190154", "0.71548146", "0.71363854", "0.7098043", "0.7080675", "0.7080675", "0.70638335", "0.70500916", "0.7000786", "0.7000786", "0.69975483", "0.6949377", "0.6949377", "0.69484836", "0.6942483", "0.690840...
0.74435806
2
Defines the column name for use with single table inheritance can be overridden in subclasses.
def inheritance_column "type" end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def column_name\n ensure_setup!\n column.name.to_sym\n end", "def polymorphic_column_name(reflection, column_name)\n # self.polymorphic_namespace_name.to_s + '.' + (reflection.options[:as] ? reflection.options[:as].to_s.classify : reflection.class_name.to_s) + '#' + column_name.to_s\n ...
[ "0.78226936", "0.754619", "0.7434576", "0.7328593", "0.73234254", "0.72974706", "0.7287831", "0.7260215", "0.71721977", "0.70947134", "0.7018866", "0.6971021", "0.6901635", "0.68464214", "0.6811663", "0.68006206", "0.67950594", "0.6764073", "0.6755768", "0.6699804", "0.669971...
0.6169851
68
Turns the +table_name+ back into a class name following the reverse rules of +table_name+.
def class_name(table_name = table_name) # :nodoc: # remove any prefix and/or suffix from the table name class_name = Inflector.camelize(table_name[table_name_prefix.length..-(table_name_suffix.length + 1)]) class_name = Inflector.singularize(class_name) if pluralize_table_names return class_name end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def clean_table_name(table_name)\n class_from_table_name(table_name)&.table_name\n end", "def undecorated_table_name(class_name = base_class.name)\n table_name = class_name.to_s.demodulize.underscore\n table_name = table_name.pluralize if pluralize_table_names\n table_name\n end...
[ "0.80704665", "0.8056342", "0.7907185", "0.7696416", "0.768585", "0.7595949", "0.7595949", "0.7470158", "0.74437195", "0.7328504", "0.7281118", "0.7213628", "0.71811235", "0.71702677", "0.7159116", "0.71508384", "0.7146398", "0.7111226", "0.7031255", "0.7031255", "0.6984563",...
0.8081715
0
Returns an array of column objects for the table associated with this class.
def columns @columns ||= connection.columns(table_name, "#{name} Columns") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def columns\n self.class.const_get(:COLUMNS) rescue []\n end", "def table_columns\n klass.column_names\n end", "def columns\n self.class.instance_variable_get(:@columns)\n end", "def columns\n @columns ||= [];\n end", "def columns\n @columns = @clazz.columns...
[ "0.78562075", "0.78300214", "0.77173525", "0.76844615", "0.7610461", "0.7609238", "0.7593524", "0.7593524", "0.75041723", "0.74318117", "0.7413033", "0.7409511", "0.7398146", "0.7384385", "0.7375594", "0.736996", "0.73405904", "0.72981364", "0.72981364", "0.7296383", "0.72963...
0.7170225
26
Returns an array of column objects for the table associated with this class.
def columns_hash @columns_hash ||= columns.inject({}) { |hash, column| hash[column.name] = column; hash } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def columns\n self.class.const_get(:COLUMNS) rescue []\n end", "def table_columns\n klass.column_names\n end", "def columns\n self.class.instance_variable_get(:@columns)\n end", "def columns\n @columns ||= [];\n end", "def columns\n @columns = @clazz.columns...
[ "0.78562075", "0.78300214", "0.77173525", "0.76844615", "0.7610461", "0.7609238", "0.7593524", "0.7593524", "0.75041723", "0.74318117", "0.7413033", "0.7409511", "0.7398146", "0.7384385", "0.7375594", "0.736996", "0.73405904", "0.72981364", "0.72981364", "0.7296383", "0.72963...
0.0
-1
Returns an array of columns objects where the primary id, all columns ending in "_id" or "_count", and columns used for single table inheritance has been removed.
def content_columns @content_columns ||= columns.reject { |c| c.name == primary_key || c.name =~ /(_id|_count)$/ || c.name == inheritance_column } end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def columns\n @columns ||= [].tap do |fields|\n @model.columns.reject { |a| a.name.match(/_id$/) }.each do |column|\n fields << resolve(column.type, column.name)\n end\n end\n end", "def columns_without_id\n singular_table_name.classify.constantize.columns.select{ |c| c.nam...
[ "0.7580825", "0.75081676", "0.73573184", "0.7209683", "0.7200502", "0.7184944", "0.71238947", "0.70656514", "0.70104134", "0.70104134", "0.6996355", "0.6993256", "0.69479287", "0.69001293", "0.6872512", "0.6870953", "0.6782549", "0.67746687", "0.67558795", "0.6730151", "0.672...
0.67386186
19
Returns a hash of all the methods added to query each of the columns in the table with the name of the method as the key and true as the value. This makes it possible to do O(1) lookups in respond_to? to check if a given method for attribute is available.
def column_methods_hash @dynamic_methods_hash ||= columns_hash.keys.inject(Hash.new(false)) do |methods, attr| methods[attr.to_sym] = true methods["#{attr}=".to_sym] = true methods["#{attr}?".to_sym] = true methods end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def column_methods_hash #:nodoc:\n @dynamic_methods_hash ||= column_names.inject(Hash.new(false)) do |methods, attr|\n attr_name = attr.to_s\n methods[attr.to_sym] = attr_name\n methods[\"#{attr}=\".to_sym] = attr_name\n methods[\"#{attr}?\".to_sym] = attr_name\n ...
[ "0.790694", "0.6925769", "0.65229917", "0.64735603", "0.6316967", "0.6290776", "0.6269291", "0.62040746", "0.61645246", "0.6125041", "0.61043036", "0.6095794", "0.60854566", "0.60393375", "0.5994893", "0.59791505", "0.5945238", "0.58835876", "0.58527696", "0.5849391", "0.5848...
0.8154394
0
Transforms attribute key names into a more humane format, such as "First name" instead of "first_name". Example: Person.human_attribute_name("first_name") => "First name"
def human_attribute_name(attribute_key_name) attribute_key_name.gsub(/_/, " ").capitalize unless attribute_key_name.nil? end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def human_attribute_name(attribute_key_name) #:nodoc:\n attribute_key_name.humanize\n end", "def human_attribute_name(attribute, options={})\n attribute = Ldaptic.encode(attribute)\n if at = namespace.attribute_type(attribute)\n attribute = at.verbose_name\n end\n ...
[ "0.832379", "0.77316904", "0.7524305", "0.74633354", "0.74298227", "0.7421665", "0.7354102", "0.73200524", "0.69086313", "0.69086313", "0.69083667", "0.69077796", "0.68454516", "0.6844236", "0.6824289", "0.6824289", "0.67961335", "0.67961335", "0.6783996", "0.67674124", "0.67...
0.8188296
1
Used to sanitize objects before they're used in an SELECT SQLstatement.
def sanitize(object) # :nodoc: return object if Fixnum === object object.to_s.gsub(/([;:])/, "").gsub('##', '\#\#').gsub(/'/, "''") # ' (for ruby-mode) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def sanitize(object) #:nodoc:\n quote_value(object)\n end", "def sanitize\n return @conditions if @conditions\n merge_conditions(*(objects.collect { |object| object.sanitize } << {:any => any}))\n end", "def sanitize_sql(*args)\n klass.send(:sanitize_sql, args)\n end"...
[ "0.72177136", "0.71193177", "0.7015651", "0.6937062", "0.6778566", "0.6749635", "0.6712005", "0.66994196", "0.6605479", "0.6495178", "0.63991725", "0.6354344", "0.6354344", "0.62588197", "0.62011784", "0.615603", "0.6153296", "0.6153296", "0.6106879", "0.6097217", "0.6052035"...
0.5891074
30
Used to aggregate logging and benchmark, so you can measure and represent multiple statements in a single block. Usage (hides all the SQL calls for the individual actions and calculates total runtime for them all): Project.benchmark("Creating project") do project = Project.create("name" => "stuff") project.create_manager("name" => "David") project.milestones << Milestone.find_all end
def benchmark(title) result = nil logger.level = Logger::ERROR bm = Benchmark.measure { result = yield } logger.level = Logger::DEBUG logger.info "#{title} (#{sprintf("%f", bm.real)})" return result end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def main\n require 'benchmark'\n result_hash = nil\n \n time = Benchmark.measure { result_hash = build_pcrs_hash }\n show do\n title \"operations batched\"\n note \"#{time.to_s}\" \n end\n \n log_info result_hash\n {}\n end", "def ...
[ "0.6199363", "0.61691475", "0.6147292", "0.6099667", "0.607818", "0.5948215", "0.58986604", "0.58986604", "0.5894525", "0.58811885", "0.58642834", "0.58351934", "0.58338857", "0.5821936", "0.579012", "0.5787561", "0.5763721", "0.5745146", "0.57102865", "0.57088286", "0.570505...
0.55084276
38
Loads the file_name if reload_associations is true or requires if it's false.
def require_or_load(file_name) if !associations_loaded.include?(file_name) associations_loaded << file_name reload_associations ? load("#{file_name}.rb") : require(file_name) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def reload\n load @filename\n end", "def load_associated_objects(opts, reload=false)\n name = opts[:name]\n if @associations.include?(name) and !reload\n @associations[name]\n else\n objs = if opts.returns_array?\n send(opts.dataset_method).all\n else\n i...
[ "0.6461976", "0.63092804", "0.59614825", "0.5926432", "0.58789915", "0.5837854", "0.58251786", "0.58251786", "0.58030283", "0.5789981", "0.57898605", "0.5756675", "0.57558435", "0.5738304", "0.57381725", "0.57351434", "0.572545", "0.572545", "0.57196933", "0.57159996", "0.571...
0.80201703
0
Resets the list of dependencies loaded (typically to be called by the end of a request), so when require_or_load is called for that dependency it'll be loaded anew.
def reset_associations_loaded associations_loaded = [] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def reset\n @dependencies_are_ready = nil\n @dependencies_have_failed = nil\n reset_forward\n end", "def flush_cache!\n @cached_dependencies = {}\n end", "def clear\n @autoloaded_classes.to_a.reverse_each do |klass|\n RubyCodeAutoreloader::ClassLoader.remove_constant(klass)\n ...
[ "0.7048898", "0.6756045", "0.6537157", "0.6467689", "0.646544", "0.6463294", "0.6448089", "0.6446947", "0.636866", "0.63419396", "0.6333633", "0.63182575", "0.62807316", "0.6252021", "0.61994225", "0.6180695", "0.6082159", "0.60730463", "0.6045663", "0.6037105", "0.603241", ...
0.55187166
56
Finder methods must instantiate through this method to work with the singletable inheritance model that makes it possible to create objects of different types from the same table.
def instantiate(record) object = record_with_type?(record) ? compute_type(record[inheritance_column]).allocate : allocate object.instance_variable_set("@attributes", record) return object end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def discriminate_class_for_record(record)\n if using_single_table_inheritance?(record)\n find_sti_class(record[inheritance_column])\n else\n super\n end\n end", "def discriminate_class_for_record(record)\n if using_single_table_inheritance?(record)...
[ "0.6013516", "0.6013516", "0.57649875", "0.5741629", "0.5739135", "0.57193875", "0.57191837", "0.5601691", "0.55917317", "0.55761445", "0.5540848", "0.5504844", "0.54648286", "0.54503626", "0.54404265", "0.54397213", "0.54370373", "0.54120475", "0.53432226", "0.53356344", "0....
0.0
-1
Returns true if the +record+ has a single table inheritance column and is using it.
def record_with_type?(record) record.include?(inheritance_column) && !record[inheritance_column].nil? && !record[inheritance_column].empty? end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def inheritable?\n @klass.columns_hash.has_key?( inheritance_column )\n end", "def descends_from_active_record?\n if self == Base\n false\n elsif superclass.abstract_class?\n superclass.descends_from_active_record?\n else\n superclass == Base || !column...
[ "0.8264854", "0.7128515", "0.7128515", "0.6720243", "0.66707826", "0.6646685", "0.6599493", "0.6566987", "0.6503848", "0.6437268", "0.63924724", "0.63834965", "0.63177603", "0.62888837", "0.62464285", "0.62023646", "0.617802", "0.61578894", "0.61261374", "0.6120877", "0.60958...
0.8226742
1
Returns the name of the type of the record using the current module as a prefix. So descendents of MyApp::Business::Account would be appear as "MyApp::Business::AccountSubclass".
def type_name_with_module(type_name) self.name =~ /::/ ? self.name.scan(/(.*)::/).first.first + "::" + type_name : type_name end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def type_name\n self.class.name.split('::').last.upcase\n end", "def type_name\n @type_name ||= self.name.demodulize.underscore\n end", "def class_name\n (self.type.to_s || self.class.name).demodulize\n end", "def type\n name = self.class.name.split('::').last\n ...
[ "0.73647285", "0.7133345", "0.7066359", "0.7052021", "0.70427203", "0.70394665", "0.70174164", "0.69602716", "0.6914488", "0.68955517", "0.67703944", "0.67134154", "0.66962636", "0.66758543", "0.66110915", "0.6588917", "0.6587153", "0.65809596", "0.65726537", "0.65614694", "0...
0.66518885
14
Adds a sanitized version of +conditions+ to the +sql+ string. Note that it's the passed +sql+ string is changed.
def add_conditions!(sql, conditions) sql << "WHERE #{sanitize_conditions(conditions)} " unless conditions.nil? sql << (conditions.nil? ? "WHERE " : " AND ") + type_condition unless descends_from_active_record? end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def sanitize_sql(conditions)\n if conditions.is_a?(Hash)\n sanitize_sql_activerecord5(conditions)\n else\n @model_class.send(:sanitize_sql, conditions)\n end\n end", "def sanitize_sql(conditions)\n if conditions.is_a?(Hash)\n sanitize_sql_activerecord5(...
[ "0.780176", "0.780176", "0.72911876", "0.7204284", "0.6860319", "0.6788182", "0.676615", "0.67052287", "0.64939094", "0.63504404", "0.62539655", "0.61971205", "0.61454195", "0.61043274", "0.6078045", "0.6062426", "0.60335016", "0.59917426", "0.5989291", "0.59425724", "0.59342...
0.75823075
2
Guesses the table name, but does not decorate it with prefix and suffix information.
def undecorated_table_name(class_name = class_name_of_active_record_descendant(self)) table_name = Inflector.underscore(Inflector.demodulize(class_name)) table_name = Inflector.pluralize(table_name) if pluralize_table_names return table_name end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def table_alias_for(table_name)\n table_name.gsub(/\\./, '_')\n end", "def undecorated_table_name(class_name = base_class.name)\n table_name = class_name.to_s.demodulize.underscore\n table_name = table_name.pluralize if pluralize_table_names\n table_name\n end", "def pgt_m...
[ "0.77087224", "0.75147164", "0.7501445", "0.7486034", "0.73789424", "0.7291564", "0.7265343", "0.723434", "0.721462", "0.7209501", "0.7209501", "0.7203508", "0.7202016", "0.7152413", "0.71198756", "0.7023221", "0.6994866", "0.69792557", "0.69248194", "0.69020426", "0.6891009"...
0.71917695
13
Returns the class type of the record using the current module as a prefix. So descendents of MyApp::Business::Account would be appear as MyApp::Business::AccountSubclass.
def compute_type(type_name) type_name_with_module(type_name).split("::").inject(Object) do |final_type, part| final_type = final_type.const_get(part) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def klass\n class_name = self[\"_type\"]\n class_name ? class_name.constantize : nil\n end", "def klass\n type.to_s.classify.constantize\n end", "def class_name\n (self.type.to_s || self.class.name).demodulize\n end", "def type\n klass = self.class.name\n...
[ "0.66728777", "0.6608134", "0.65893227", "0.6531153", "0.6504158", "0.649285", "0.6469633", "0.6463587", "0.64161015", "0.64107263", "0.6362263", "0.63493204", "0.62897146", "0.62897146", "0.62897146", "0.6258354", "0.6248265", "0.6230371", "0.62292576", "0.6227376", "0.62273...
0.0
-1
Returns the name of the class descending directly from ActiveRecord in the inheritance hierarchy.
def class_name_of_active_record_descendant(klass) if klass.superclass == Base return klass.name elsif klass.superclass.nil? raise ActiveRecordError, "#{name} doesn't belong in a hierarchy descending from ActiveRecord" else class_name_of_active_record_descendant(klass.superclass) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def class_name\n @class_name ||= active_record.name\n end", "def class_name\n name = @klass.name\n name.name\n end", "def class_name\n klass = single_class\n while klass.name == ''\n klass = klass.superclass\n end\n if list_context?\n \"[#{klass}]\"\n e...
[ "0.79955876", "0.7924037", "0.78505355", "0.77900165", "0.7734788", "0.7718186", "0.77154803", "0.77033395", "0.76602566", "0.7573118", "0.75521696", "0.7545339", "0.74930054", "0.74711686", "0.74711686", "0.74477106", "0.74477106", "0.7445227", "0.74438864", "0.7412161", "0....
0.7798359
3
Accepts either a condition array or string. The string is returned untouched, but the array has each of the condition values sanitized.
def sanitize_conditions(conditions) if Array === conditions statement, values = conditions[0], conditions[1..-1] values.collect! { |value| sanitize(value) } conditions = statement % values end return conditions end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def criteria_from_array(condition) # :nodoc:\n str, *values = condition\n sql = if values.first.kind_of?(Hash) and str =~ /:\\w+/\n replace_named_bind_variables(str, values.first)\n elsif str.include?('?')\n replace_bind_variables(str, values)\n ...
[ "0.69056094", "0.6676505", "0.6500697", "0.6432102", "0.6415661", "0.63230723", "0.62132657", "0.6176637", "0.61028236", "0.60636765", "0.59566855", "0.59218127", "0.5861413", "0.58384943", "0.58149004", "0.5802816", "0.57859504", "0.57851946", "0.57653594", "0.5758929", "0.5...
0.72369474
0
New objects can be instantiated as either empty (pass no construction parameter) or preset with attributes but not yet saved (pass a hash with key names matching the associated table column names). In both instances, valid attribute keys are determined by the column names of the associated table hence you can't have attributes that aren't part of the table columns.
def initialize(attributes = nil) @attributes = attributes_from_column_definition @new_record = true ensure_proper_type self.attributes = attributes unless attributes.nil? yield self if block_given? end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def initialize(params = {})\n params.each do |k,v|\n k = k.to_sym\n if self.class.columns.include?(k)\n self.send(k.to_s+'=', v)\n else\n raise \"unknown attribute '#{k}'\"\n end\n end\n end", "def initialize(params = {}) # <- ?is params a hash representing a new row ob...
[ "0.7075576", "0.69585264", "0.69185865", "0.6883749", "0.6876595", "0.6850823", "0.683087", "0.66985965", "0.6688291", "0.6682992", "0.6660089", "0.6631663", "0.6604891", "0.6534278", "0.651785", "0.64884156", "0.64718765", "0.6467999", "0.64610994", "0.6456888", "0.6453541",...
0.6176426
48
Every Active Record class must use "id" as their primary ID. This getter overwrites the native id method, which isn't being used in this context.
def id read_attribute(self.class.primary_key) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def id\n attr_name = self.class.primary_key\n c = column_for_attribute(attr_name)\n define_read_method(:id, attr_name, c) if self.class.generate_read_methods\n read_attribute(attr_name)\n end", "def id\n attributes[self.class.primary_key]\n end", "def id\n read_attr :id\n ...
[ "0.81901634", "0.8098744", "0.79087263", "0.78256375", "0.78076226", "0.7769945", "0.77556354", "0.77551144", "0.77526045", "0.7721875", "0.7712388", "0.7712388", "0.7712388", "0.7712388", "0.7689112", "0.7689112", "0.7689112", "0.7689112", "0.7686023", "0.7676192", "0.765979...
0.82900494
1
Sets the primary ID.
def id=(value) write_attribute(self.class.primary_key, value) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def primary_id=(v)\n @primary_id = alma_string v\n end", "def id=(value)\n write_attribute(self.class.primary_key, value) if self.class.primary_key\n end", "def id=(value)\n write_attribute(self.class.primary_key, value)\n end", "def set_primary\n @primary = Primary.find(params[:...
[ "0.8011882", "0.77993226", "0.7736149", "0.7610082", "0.7610082", "0.757052", "0.72868776", "0.72269577", "0.72144634", "0.7139137", "0.7065338", "0.70568395", "0.7049024", "0.70013654", "0.69884944", "0.6912043", "0.6911241", "0.6911241", "0.6855019", "0.68379956", "0.683799...
0.77303517
3
Returns true if this object hasn't been saved yet that is, a record for the object doesn't exist yet.
def new_record? @new_record end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def new_record?\n !_persisted_obj\n end", "def new_record?(object)\n false\n end", "def new_record?\n !self.persisted?\n end", "def new_record?\n !defined?(@new_record) || @new_record\n end", "def null_record?\n self == self.class.null_record\n end", "def n...
[ "0.7568456", "0.74203277", "0.7315502", "0.7258721", "0.724511", "0.724511", "0.7231685", "0.7228141", "0.7203454", "0.71722656", "0.7171572", "0.71625024", "0.71608454", "0.7147161", "0.7120969", "0.71160865", "0.70932037", "0.7072884", "0.7059164", "0.7052371", "0.7050281",...
0.0
-1
No record exists: Creates a new record with values matching those of the object attributes. A record does exist: Updates the record with values matching those of the object attributes.
def save create_or_update return true end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def create_or_update record\n db_name = database_name_for(record)\n coll_name = collection_name_for(record)\n id = id_for(record)\n pointer = \"/#{db_name}/#{coll_name}/#{id}\"\n if id\n res = collection_for(record).update({:_id => id}, interpret(record), :ups...
[ "0.75486445", "0.70807093", "0.6764977", "0.66983175", "0.66816056", "0.6589929", "0.65808487", "0.6569382", "0.651553", "0.6515329", "0.6471616", "0.6438333", "0.6423777", "0.63831574", "0.6382539", "0.63786674", "0.63707244", "0.63701284", "0.63659394", "0.63433546", "0.632...
0.0
-1
Deletes the record in the database and freezes this instance to reflect that no changes should be made (since they can't be persisted).
def destroy unless new_record? connection.delete( "DELETE FROM #{self.class.table_name} " + "WHERE #{self.class.primary_key} = '#{id}'", "#{self.class.name} Destroy" ) end freeze end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def delete\n delete_record\n freeze\n end", "def delete\n del unless new_record?\n set_deleted_properties\n end", "def destroy\n db.delete(id)\n self.freeze\n end", "def delete(record)\n record.del\n end", "def destroy\n unless new_record?\n ...
[ "0.8096271", "0.76274526", "0.751534", "0.75089604", "0.7422058", "0.7411766", "0.7406429", "0.7398655", "0.7381032", "0.73572886", "0.73211235", "0.7288478", "0.72460675", "0.7244676", "0.72316796", "0.7197915", "0.7192112", "0.71910214", "0.7169398", "0.7158418", "0.7151782...
0.7744809
1
Returns a clone of the record that hasn't been assigned an id yet and is treated as a new record.
def clone attr = Hash.new self.attribute_names.each do |name| begin attr[name] = read_attribute(name).clone rescue TypeError attr[name] = read_attribute(name) end end cloned_record = self.class.new(attr) cloned_record.instance_variable_set "@new_record", true cloned_record.id = nil cloned_record end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def clone\n newobj = Marshal.load(Marshal.dump(self))\n props = newobj.instance_variable_get(:@props)\n props[:id] = Engine.instance.db.getid\n put_object(newobj)\n newobj\n rescue\n log.error \"Clone failed\"\n nil\n end", "def clone\n self.class.new(@attributes.except(:_id).except(:...
[ "0.7223236", "0.6958723", "0.6796813", "0.6583778", "0.65410244", "0.64839166", "0.64269626", "0.6421062", "0.6338344", "0.63297844", "0.63053924", "0.6301103", "0.62903297", "0.6255982", "0.6255982", "0.62398", "0.6217718", "0.62131715", "0.61913306", "0.61611766", "0.615803...
0.7280505
0
Updates a single attribute and saves the record. This is especially useful for boolean flags on existing records.
def update_attribute(name, value) self[name] = value save end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update_attribute!(attribute, value)\n send(\"#{attribute}=\", value)\n self.save!\n end", "def update_attribute(name, value)\n send(\"#{name}=\", value)\n save\n end", "def update_attribute(name, value)\n send(\"#{name}=\", value)\n save\n end", "def update_attribut...
[ "0.7347231", "0.7143223", "0.7143223", "0.713022", "0.7106531", "0.7017236", "0.69711024", "0.69212115", "0.68547136", "0.68547136", "0.6763246", "0.6704214", "0.66835046", "0.6620866", "0.6601267", "0.65833247", "0.6512519", "0.6501324", "0.6468284", "0.6440494", "0.64047873...
0.70559263
5
Returns the value of attribute identified by attr_name after it has been type cast (for example, "20041212" in a data column is cast to a date object, like Date.new(2004, 12, 12)). (Alias for the protected read_attribute method).
def [](attr_name) read_attribute(attr_name) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def read_attribute(attr_name)\n attr_name = attr_name.to_s\n if !(value = @attributes[attr_name]).nil?\n if column = column_for_attribute(attr_name)\n if unserializable_attribute?(attr_name, column)\n unserialize_attribute(attr_name)\n elsif [:date, :time, :datetime].i...
[ "0.80374163", "0.7985092", "0.7954797", "0.76699084", "0.74570286", "0.7451236", "0.73535436", "0.7177394", "0.7165804", "0.70893735", "0.707945", "0.707646", "0.7058703", "0.7058703", "0.6921307", "0.6893329", "0.6808193", "0.6714082", "0.6675539", "0.66306114", "0.6495627",...
0.5882316
73
Updates the attribute identified by attr_name with the specified +value+. (Alias for the protected write_attribute method).
def []= (attr_name, value) write_attribute(attr_name, value) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update_attribute(attr_name, attr_value)\n update_attributes(attr_name => attr_value)\n end", "def update_attribute(name, value)\n respond_to?(\"#{name}=\") ? send(\"#{name}=\", value) : self[name] = value\n save(:validate => false)\n end", "def update_attribute(name, value)\n...
[ "0.8921033", "0.84120375", "0.84120375", "0.840153", "0.836069", "0.8328027", "0.8320795", "0.83201", "0.83201", "0.83201", "0.83180934", "0.8314598", "0.8298591", "0.8298591", "0.8114936", "0.7996278", "0.7962724", "0.7908644", "0.79043055", "0.7770255", "0.76767933", "0.7...
0.815992
14
Allows you to set all the attributes at once by passing in a hash with keys matching the attribute names (which again matches the column names). Sensitive attributes can be protected from this form of massassignment by using the +attr_protected+ macro. Or you can alternatively specify which attributes can be accessed in with the +attr_accessible+ macro. Then all the attributes not included in that won't be allowed to be massassigned.
def attributes=(attributes) return if attributes.nil? multi_parameter_attributes = [] remove_attributes_protected_from_mass_assignment(attributes).each do |k, v| k.include?("(") ? multi_parameter_attributes << [ k, v ] : send(k + "=", v) end assign_multiparameter_attributes(multi_parameter_attributes) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def attributes=(attrs)\n unless attrs.respond_to?(:symbolize_keys)\n raise ArgumentError, 'You must pass a hash when assigning attributes'\n end\n\n return if attrs.blank?\n\n attrs = attrs.symbolize_keys\n # First deal with sanitizing for mass assignment\n # this raises an err...
[ "0.77068424", "0.7271758", "0.7147767", "0.71125937", "0.7073458", "0.7059004", "0.7009061", "0.70084035", "0.6923528", "0.6901435", "0.6862078", "0.6846393", "0.6794626", "0.6763884", "0.673296", "0.67271256", "0.6697726", "0.6694997", "0.6642289", "0.6633882", "0.6623047", ...
0.6566784
27
Returns true if the specified +attribute+ has been set by the user or by a database load and is neither nil nor empty? (the latter only applies to objects that responds to empty?, most notably Strings).
def attribute_present?(attribute) is_empty = read_attribute(attribute).respond_to?("empty?") ? read_attribute(attribute).empty? : false @attributes.include?(attribute) && !@attributes[attribute].nil? && !is_empty end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def attribute_present?(attribute)\n value = respond_to?(attribute) ? send(attribute) : nil\n !value.nil? || (value.respond_to?(:empty?) && !value.empty?)\n end", "def attribute_present?(attribute)\n value = read_attribute(attribute)\n !value.blank?\n end", "def attribute_present?(attr...
[ "0.815164", "0.81139654", "0.7860971", "0.74666315", "0.732745", "0.71513844", "0.7073689", "0.7073689", "0.7073689", "0.7073689", "0.6927675", "0.6866585", "0.6783585", "0.6719639", "0.67079175", "0.667579", "0.6665477", "0.6650526", "0.6619465", "0.66037947", "0.6590791", ...
0.79982424
2
Returns an array of names for the attributes available on this object sorted alphabetically.
def attribute_names @attributes.keys.sort end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def attribute_names\n @attributes.keys.sort\n end", "def attribute_names\n attributes.keys.sort\n end", "def attribute_names\n attributes.keys.sort\n end", "def attribute_names\r\n translated_attribute_names.map(&:to_s) + @attributes.keys.sort\r\n end", "def attribute_names\...
[ "0.8908073", "0.88858676", "0.88858676", "0.8432948", "0.82795346", "0.81553423", "0.81553423", "0.81553423", "0.81553423", "0.81241137", "0.8109694", "0.8108706", "0.80726206", "0.79042315", "0.788282", "0.7797647", "0.77818024", "0.77528346", "0.76977813", "0.76495224", "0....
0.8888889
1
Returns the column object for the named attribute.
def column_for_attribute(name) self.class.columns_hash[name] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def column_for_attribute(name)\n self.class.columns_hash[name.to_s]\n end", "def column_for_attribute(name)\n name = name.to_sym\n return self.faux_columns[name] if self.faux_columns.has_key?(name)\n super\n end", "def column_for_attribute(column)\n attribute_info = self.class._a...
[ "0.84108883", "0.78040314", "0.74527514", "0.74527514", "0.7343118", "0.727963", "0.7277907", "0.7247576", "0.7166508", "0.7122307", "0.7005713", "0.7005713", "0.6984722", "0.69528127", "0.69250524", "0.6835067", "0.68188083", "0.6804693", "0.68030095", "0.6780211", "0.668435...
0.83001786
1
Returns true if the +comparison_object+ is of the same type and has the same id.
def ==(comparison_object) comparison_object.instance_of?(self.class) && comparison_object.id == id end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def ==(comparison_object)\n comparison_object.equal?(self) ||\n (comparison_object.instance_of?(self.class) &&\n comparison_object.id == id &&\n !comparison_object.new?)\n end", "def ==(comparison_object)\n comparison_object.equal?(self) ||\n (comparison_object.instance_o...
[ "0.7877784", "0.785061", "0.7824907", "0.7707864", "0.76286787", "0.75496495", "0.7243207", "0.7087887", "0.6988438", "0.69400966", "0.69274175", "0.68617773", "0.68613994", "0.6794421", "0.67652607", "0.6750103", "0.674637", "0.6725655", "0.67179346", "0.67117006", "0.670302...
0.8167142
0
Delegates to id in order to allow two records of the same type and id to work with something like: [ Person.find(1), Person.find(2), Person.find(3) ] & [ Person.find(1), Person.find(4) ] => [ Person.find(1) ]
def hash id end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def id ; @record.id if @record ; end", "def find(id); end", "def find(id); end", "def id_obj(type, id = nil, copy: false, **)\n # noinspection RubyMismatchedReturnType\n if type.is_a?(PublicationIdentifier)\n Log.warn(\"#{__method__}: ignoring id #{id.inspect}\") if id\n copy ? type.dup : typ...
[ "0.62193996", "0.61772686", "0.61772686", "0.6109537", "0.6060535", "0.60027003", "0.58801204", "0.5876206", "0.58506787", "0.5815465", "0.5812927", "0.57598495", "0.574026", "0.5714612", "0.57059246", "0.5694185", "0.56861824", "0.56741023", "0.5658637", "0.5658067", "0.5657...
0.0
-1
A Person object with a name attribute can ask person.respond_to?("name"), person.respond_to?("name="), and person.respond_to?("name?") which will all return true.
def respond_to?(method) self.class.column_methods_hash[method.to_sym] || respond_to_without_attributes?(method) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def test_respond_to\n matz = Person.find(1)\n assert_respond_to matz, :name\n assert_respond_to matz, :name=\n assert_respond_to matz, :name?\n assert_not matz.respond_to?(:super_scalable_stuff)\n end", "def respond_to?(mname)\n return true if is_real_method?(mname)\n mname = mname.to_s...
[ "0.71248114", "0.65477514", "0.64826685", "0.64697754", "0.6466118", "0.64380985", "0.6345879", "0.63352513", "0.63115835", "0.62898004", "0.62819743", "0.62819743", "0.6268254", "0.62610257", "0.62516177", "0.62454194", "0.6237082", "0.62266946", "0.6223255", "0.6222353", "0...
0.0
-1
Updates the associated record with values matching those of the instant attributes.
def update connection.update( "UPDATE #{self.class.table_name} " + "SET #{quoted_comma_pair_list(connection, attributes_with_quotes)} " + "WHERE #{self.class.primary_key} = '#{id}'", "#{self.class.name} Update" ) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update\n record.assign_attributes(data)\n record.save! if record.changed?\n end", "def update_attributes(datas)\n search_attributes.each do |val|\n self.send(\"#{val.field}=\", val.cast_value(datas[val.field]))\n end\n end", "def update\n\n DBConnection.execute2(<<-SQL, ...
[ "0.6473228", "0.6399006", "0.6305629", "0.6288487", "0.6270629", "0.6237672", "0.6177414", "0.61623114", "0.6159041", "0.61242193", "0.6102502", "0.60860145", "0.6056111", "0.6003508", "0.599352", "0.5978646", "0.59773886", "0.59744096", "0.59727323", "0.59570247", "0.5941583...
0.57095796
56
Creates a new record with values matching those of the instant attributes.
def create self.id = connection.insert( "INSERT INTO #{self.class.table_name} " + "(#{quoted_column_names.join(', ')}) " + "VALUES(#{attributes_with_quotes.values.join(', ')})", "#{self.class.name} Create", self.class.primary_key, self.id ) @new_record = false end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def create(atts = {})\n rec = self.new(atts)\n rec.save && rec\n end", "def create_record attributes\n creator = @creator_class.new attributes, @context\n FactoryGirl.create @clazz.name.underscore.to_sym, creator.factorygirl_attributes\n end", "def new_record(model, *args)\n ...
[ "0.68991244", "0.68555105", "0.67365193", "0.67269045", "0.67265284", "0.6725027", "0.6611084", "0.6582644", "0.65577996", "0.6514337", "0.6502961", "0.65010744", "0.6461292", "0.6432898", "0.6432898", "0.6419372", "0.63542235", "0.62774956", "0.6277334", "0.6277334", "0.6270...
0.63878286
16
Sets the attribute used for single table inheritance to this class name if this is not the ActiveRecord descendant. Considering the hierarchy Reply < Message < ActiveRecord, this makes it possible to do Reply.new without having to set Reply[Reply.inheritance_column] = "Reply" yourself. No such attribute would be set for objects of the Message class in that example.
def ensure_proper_type unless self.class.descends_from_active_record? write_attribute(self.class.inheritance_column, Inflector.demodulize(self.class.name)) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def inheritance_column\n @inheritance_column ||= @klass.inheritance_column.to_s\n end", "def builtin_inheritance_column # :nodoc:\n # Can this be made less brittle?\n if self == ActiveRecord::Base\n 'type'\n else\n (@builtin_inheritance_column ||= nil) || super...
[ "0.66203254", "0.588574", "0.5730844", "0.57073325", "0.56103367", "0.55712056", "0.55658996", "0.55658996", "0.5561046", "0.55023617", "0.549911", "0.5466521", "0.5439994", "0.5365268", "0.53513026", "0.5316586", "0.53125805", "0.5309516", "0.5308195", "0.52876705", "0.52626...
0.57959825
2
Returns the value of attribute identified by attr_name after it has been type cast (for example, "20041212" in a data column is cast to a date object, like Date.new(2004, 12, 12)).
def read_attribute(attr_name) #:doc: if @attributes.keys.include? attr_name if column = column_for_attribute(attr_name) @attributes[attr_name] = unserializable_attribute?(attr_name, column) ? unserialize_attribute(attr_name) : column.type_cast(@attributes[attr_name]) end @attributes[attr_name] else nil end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def read_attribute(attr_name)\n attr_name = attr_name.to_s\n if !(value = @attributes[attr_name]).nil?\n if column = column_for_attribute(attr_name)\n if unserializable_attribute?(attr_name, column)\n unserialize_attribute(attr_name)\n elsif [:date, :time, :datetime].i...
[ "0.77382016", "0.772512", "0.76347345", "0.7389419", "0.7266454", "0.71555877", "0.71140665", "0.7098828", "0.7086074", "0.7086074", "0.70458364", "0.69509876", "0.6865451", "0.6770501", "0.67088926", "0.670044", "0.6572081", "0.656021", "0.6519102", "0.6481414", "0.6478697",...
0.7133754
6
Returns true if the attribute is of a text column and marked for serialization.
def unserializable_attribute?(attr_name, column) @attributes[attr_name] && column.send(:type) == :text && @attributes[attr_name].is_a?(String) && self.class.serialized_attributes[attr_name] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def unmarshalizable_attribute?(attr_name, column)\n column.text? && self.class.marshalized_attributes[attr_name]\n end", "def text?\n type == :text\n end", "def text?\n [:ascii, :text].include?(type)\n end", "def string?\n data_type == String\n end", "def is_string?\n c...
[ "0.75921243", "0.7160686", "0.6794015", "0.67638636", "0.6720153", "0.66765577", "0.6604493", "0.6600339", "0.6474233", "0.6473524", "0.6444633", "0.6432955", "0.63782215", "0.6328983", "0.63116914", "0.6297969", "0.62591374", "0.6247571", "0.61586195", "0.6098438", "0.603875...
0.79573506
0
Returns the unserialized object of the attribute.
def unserialize_attribute(attr_name) unserialized_object = object_from_yaml(@attributes[attr_name]) if unserialized_object.is_a?(self.class.serialized_attributes[attr_name]) @attributes[attr_name] = unserialized_object else raise( SerializationTypeMismatch, "#{attr_name} was supposed to be a #{self.class.serialized_attributes[attr_name]}, " + "but was a #{unserialized_object.class.to_s}" ) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def unmarshalize_attribute(attr_name)\n attr_name = attr_name.to_s\n if @attributes[attr_name].nil? || @attributes[attr_name] == ''\n initialize_marshalized_attribute(attr_name, self.class.marshalized_attributes[attr_name])\n end\n unmarshalized_object = Marshal.load(decode_attribute(@at...
[ "0.6829847", "0.65484864", "0.6337954", "0.6156596", "0.6023339", "0.5992766", "0.5982603", "0.59587634", "0.59331834", "0.5908719", "0.58875793", "0.5871496", "0.5803301", "0.5794739", "0.5764437", "0.5744628", "0.5744628", "0.5744628", "0.5744628", "0.5744628", "0.5709112",...
0.6353788
2
Updates the attribute identified by attr_name with the specified +value+. Empty strings for fixnum and float columns are turned into nil.
def write_attribute(attr_name, value) #:doc: @attributes[attr_name] = empty_string_for_number_column?(attr_name, value) ? nil : value end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update_attribute(attr_name, attr_value)\n update_attributes(attr_name => attr_value)\n end", "def update_attribute(attr_name, value)\n if self.class.has_custom_attribute?(attr_name.to_sym)\n find_or_build_custom_attribute_by_name(attr_name).update_attribute(:value, value)\n else\...
[ "0.7834465", "0.7706975", "0.7664361", "0.7664361", "0.7467814", "0.7354818", "0.7354818", "0.7329888", "0.7300568", "0.7233348", "0.713683", "0.712116", "0.71203893", "0.7106173", "0.70785916", "0.70775115", "0.70775115", "0.70775115", "0.70448613", "0.69958305", "0.69958305...
0.71978074
10
Returns copy of the attributes hash where all the values have been safely quoted for use in an SQL statement.
def attributes_with_quotes columns_hash = self.class.columns_hash @attributes.inject({}) do |attrs_quoted, pair| attrs_quoted[pair.first] = quote(pair.last, columns_hash[pair.first]) attrs_quoted end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def special_attributes_with_quotes(include_primary_key = true) #:nodoc:\n attributes.inject({}) do |quoted, (name, value)|\n if column = column_for_attribute(name)\n quoted[name] = quote_value(value, column) unless (!include_primary_key && column.primary) || [acts_as_nested_s...
[ "0.67472243", "0.65352833", "0.6386068", "0.62054586", "0.61682874", "0.61363614", "0.6130211", "0.60208064", "0.6012408", "0.58681786", "0.576962", "0.5754275", "0.5738419", "0.5726264", "0.5716449", "0.5716449", "0.5716449", "0.5703898", "0.5696172", "0.5696172", "0.5668815...
0.74439555
0
Quote strings appropriately for SQL statements.
def quote(value, column = nil) connection.quote(value, column) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def quoted(value)\n sql _scope.connection.quote(value)\n end", "def quoted(value)\n sql _scope.connection.quote(value)\n end", "def format_quote(q)\n if q == \"'\"\n '\"\\'\"'\n else\n \"'#{q}'\"\n end\n end", "def quote(s, column = nil)\n dummy_conn.quote(s)\n ...
[ "0.77635926", "0.77635926", "0.73617744", "0.7352961", "0.73331505", "0.7327687", "0.7196098", "0.7195194", "0.7184707", "0.7182869", "0.71362627", "0.7133151", "0.70814407", "0.7043931", "0.7035564", "0.7030494", "0.69738144", "0.69566494", "0.68935364", "0.68935364", "0.688...
0.67414296
35
Interpolate custom sql string in instance context. Optional record argument is meant for custom insert_sql.
def interpolate_sql(sql, record = nil) instance_eval("%(#{sql})") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def with_sql(sql, *args)\n if sql.is_a?(Symbol)\n sql = public_send(sql, *args)\n else\n sql = SQL::PlaceholderLiteralString.new(sql, args) unless args.empty?\n end\n clone(:sql=>sql)\n end", "def sql_insert(record)\n flds, vals = parse_fldsvalues(record)\n ph = val...
[ "0.65826744", "0.65737915", "0.6367349", "0.595435", "0.59188753", "0.5846009", "0.5840756", "0.58173174", "0.5761048", "0.5754723", "0.57529306", "0.57074124", "0.57025504", "0.56616575", "0.566084", "0.564891", "0.56101865", "0.5575381", "0.5566975", "0.5566686", "0.5566003...
0.8228903
0
Initializes the attributes array with keys matching the columns from the linked table and the values matching the corresponding default value of that column, so that a new instance, or one populated from a passedin Hash, still has all the attributes that instances loaded from the database would.
def attributes_from_column_definition connection.columns(self.class.table_name, "#{self.class.name} Columns").inject({}) do |attributes, column| attributes[column.name] = column.default unless column.name == self.class.primary_key attributes end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def initialize_attributes()\n @attributes ||= {}\n merged_attributes = {}\n defaults = self.class.schema.defaults(self)\n\n # Merge the defaults in where attributes don't have a value defined.\n defaults.each do |name, value|\n merged_attributes[name] = attributes[nam...
[ "0.7166673", "0.67303675", "0.66293657", "0.6594002", "0.65562314", "0.6472226", "0.64642423", "0.6399467", "0.6375481", "0.6348445", "0.6330958", "0.6309328", "0.6295495", "0.62933993", "0.6276614", "0.6244329", "0.62410975", "0.6209228", "0.6186286", "0.6179348", "0.616795"...
0.59918517
48
Instantiates objects for all attribute classes that needs more than one constructor parameter. This is done by calling new on the column type or aggregation type (through composed_of) object with these parameters. So having the pairs written_on(1) = "2004", written_on(2) = "6", written_on(3) = "24", will instantiate written_on (a date type) with Date.new("2004", "6", "24"). You can also specify a typecast character in the parenteses to have the parameters typecasted before they're used in the constructor. Use i for Fixnum, f for Float, s for String, and a for Array. If all the values for a given attribute is empty, the attribute will be set to nil.
def assign_multiparameter_attributes(pairs) execute_callstack_for_multiparameter_attributes( extract_callstack_for_multiparameter_attributes(pairs) ) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def initialize(params = {})\n params.each do |attr_name, value|\n attr_name_sym = attr_name.to_sym\n\n unless self.class.columns.include?(attr_name_sym)\n raise \"unknown attribute \\'#{attr_name_sym}\\'\"\n end\n attr_setter = (attr_name.to_s + \"=\").to_sym\n send(attr_setter, ...
[ "0.6199704", "0.600615", "0.60058326", "0.5956926", "0.5953558", "0.59359795", "0.5836511", "0.5794431", "0.5686391", "0.56702983", "0.5553427", "0.5539036", "0.55323493", "0.5504904", "0.548794", "0.5473924", "0.5467135", "0.54453063", "0.5416881", "0.5413817", "0.53990895",...
0.0
-1
Includes an ugly hack for Time.local instead of Time.new because the latter is reserved by Time itself.
def execute_callstack_for_multiparameter_attributes(callstack) callstack.each do |name, values| klass = (self.class.reflect_on_aggregation(name) || column_for_attribute(name)).klass if values.empty? send(name + "=", nil) else send(name + "=", Time == klass ? klass.local(*values) : klass.new(*values)) end end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def local(*args)\n time = Time.utc(*args)\n ActiveSupport::TimeWithZone.new(nil, self, time)\n end", "def local_time(time)\n return nil unless time.is_a?(Time)\n time.utc? ? time.getlocal : time\n end", "def to_local_time\n Time.local(1970, 1, 1, @hour, @minute, @second)\n end", "...
[ "0.78094184", "0.76802236", "0.722525", "0.71486694", "0.7148634", "0.7135645", "0.71041465", "0.70939314", "0.6998775", "0.68977773", "0.67190194", "0.67025566", "0.6646674", "0.66186464", "0.6572634", "0.65112805", "0.6495381", "0.64741445", "0.64567703", "0.6447599", "0.64...
0.0
-1
Returns a commaseparated pair list, like "key1 = val1, key2 = val2".
def comma_pair_list(hash) hash.inject([]) { |list, pair| list << "#{pair.first} = #{pair.last}" }.join(", ") end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def header_pairs headers\n header_pairs = []\n headers.each do |header|\n header_pairs.append \"#{header[:name]}=#{header[:value]}\"\n end\n header_pairs.join \",\"\nend", "def solution2(pairs)\r\n # TODO: complete\r\n pairs.map{|k,v| \"#{k} = #{v}\"}.join(',')\r\nend", "def build_pair *args\n ar...
[ "0.627735", "0.6204398", "0.61288285", "0.61147535", "0.60137755", "0.584503", "0.5797968", "0.57179046", "0.5715735", "0.56844324", "0.56646025", "0.56403387", "0.56298476", "0.56112075", "0.5590491", "0.55555016", "0.55555016", "0.55555016", "0.55555016", "0.55555016", "0.5...
0.70050067
0
Same as enqueue_future excepts it allows manually setting the UUID for the future object.
def enqueue_future_with_uuid(uuid, klass, *args) ResqueFuture::FutureJob.create(queue_from_class(klass), uuid, klass, *args) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def initialize(queue, uuid, payload)\n @uuid = uuid || self.generate_uuid\n payload[\"args\"].unshift(@uuid)\n super(queue, payload)\n set_result('enqueued_at' => Time.now.utc)\n end", "def perform_async_with_uuid(*args)\n id = SecureRandom.uuid\n args.unshift id\n document ...
[ "0.652896", "0.64289397", "0.5976139", "0.59648824", "0.59334", "0.5783949", "0.5602815", "0.5532297", "0.5509479", "0.5465733", "0.5403103", "0.5371683", "0.5346136", "0.53081656", "0.529592", "0.52601516", "0.52426773", "0.523128", "0.52012944", "0.518133", "0.51783264", ...
0.80389196
0
Get a future job
def get_future_job(uuid, klass) ResqueFuture::FutureJob.get(queue_from_class(klass), uuid) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def job\n @job\n end", "def job\n @job\n end", "def job\n @job\n end", "def job \n @job\n end", "def retrieve_job\n json = Server.redis { |c| c.brpop(Server.keys[:perform_list]) }\n Job.new(JSON.parse(json.last))\n rescue => e\n raise ServerError,...
[ "0.7143885", "0.7143885", "0.7048516", "0.69208956", "0.6822545", "0.6765672", "0.6718306", "0.6696742", "0.6576366", "0.6546589", "0.6536244", "0.64962703", "0.64952654", "0.6436272", "0.6406558", "0.6373722", "0.63727295", "0.63369584", "0.6334866", "0.633309", "0.6292801",...
0.75318784
0
Add a comment to an group
def comment # Get the group in question group = Group.find(params[:id]) # Require an authenticated user that has joined the group group = Group.find(params[:id]) raise HTTPStatus::Unauthorized if User.current.nil? || !group.users.include?(User.current) # Create the comment comment = group.create_comment(params[:comment]) # save and get the proper message if comment.save message = {:type => :success, :message => "Successfully added comment.", :id => comment.id} self.log_analytic(:user_comment_in_group, "User has commented in group.", comment, [], :groups) else message = {:type => :error, :message => "There was an error posting your comment."} end # Respond with either html or json respond_to do |format| format.html { flash[message[:type]] = message[:message]; redirect_to :back } format.json { render :json => message } end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def add_comment(comment); end", "def set_group_comment\n @group_comment = GroupComment.find(params[:id])\n end", "def add_comment(samp, comm, snd = selected_sound(), chn = selected_channel())\n if array?(comments = channel_property(:comments, snd, chn))\n comments.push([samp, comm])\n else\n...
[ "0.7079287", "0.68825686", "0.66936123", "0.66131294", "0.6555661", "0.653179", "0.64997935", "0.6482839", "0.6409314", "0.64028937", "0.63836384", "0.63820875", "0.6372838", "0.63707745", "0.6360967", "0.6360967", "0.6332849", "0.63169724", "0.6295939", "0.627596", "0.625510...
0.72947085
0
To initialize a new player
def initialize(name, value) @name = name.capitalize @value = value end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def initialize_player\n\n Player.new\n\nend", "def initialize_players\n\n end", "def initialize(player)\n @player = player\n end", "def initialize(playerClass)\n @player = initialize_player playerClass\n end", "def initialize\n greeting\n init_players\n end", "def initialize\n @pla...
[ "0.82734805", "0.8224603", "0.8137319", "0.80124694", "0.7820363", "0.7812184", "0.7771827", "0.77695215", "0.7582248", "0.7561953", "0.7459185", "0.7459185", "0.7457083", "0.7442281", "0.7429483", "0.7419374", "0.7394261", "0.7394261", "0.7391467", "0.7382005", "0.7369251", ...
0.0
-1
Delegates to I18n.localize with no additional functionality.
def localize(*args) I18n.localize *args end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def localize(*args)\n I18n.localize(*args)\n end", "def localize(*args)\n I18n.localize(*args)\n end", "def localize(*args)\n I18n.localize(*args)\n end", "def localize(*args)\n I18n.localize(*args)\n end", "def localize\n helpers.localize\n end", "def ...
[ "0.7808993", "0.7808993", "0.7808993", "0.7787418", "0.7621188", "0.7147704", "0.7079637", "0.7079637", "0.6975049", "0.69713527", "0.69222504", "0.690898", "0.6907692", "0.67984885", "0.66950536", "0.64819795", "0.6430831", "0.6418238", "0.6405334", "0.639519", "0.63838077",...
0.78108793
1
attempts to commit all changed files returns current sha
def try_freeze(msg, allow_empty=false) @git.add_all @git.execute(%Q[commit -m "#{msg}"#{allow_empty ? " --allow-empty" : ""}]) @git.head_sha end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def get_committed_files\n # set the current branch name to be the current branch you're on --> need to check that this works as part of push\n curr_branch_name = `git rev-parse --abbrev-ref HEAD`\n\n # raw_sha_list lists all the local, unpushed commit SHAs from your current branch\n raw_sha_list = `git log --g...
[ "0.7293918", "0.7170104", "0.7112983", "0.6893486", "0.6805594", "0.6761244", "0.66906077", "0.6622634", "0.65596366", "0.6517227", "0.64900446", "0.64896125", "0.647046", "0.64215297", "0.641783", "0.64120644", "0.6385194", "0.6355827", "0.6344067", "0.6315974", "0.6275555",...
0.0
-1
commits the current state of the working tree reverts every commit to shaw (not including) commits the restored state as a new state on top of everything (to not lose history)
def restore(shaw, current_state_msg, restored_state_msg) @git.add_all @git.execute(%Q[commit -m "#{current_state_msg}"]) @git.execute(%Q[revert -n #{shaw}..HEAD]) @git.execute(%Q[commit -m "#{restored_state_msg}"]) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def commit(opts = {:use_dirstate => true, :update_dirstate => true})\n valid = false # don't update the DirState if this is set!\n \n commit = ((modified || []) + (added || [])).sort\n remove = removed\n xtra = extra.dup\n branchname = xtra[\"branch\"]\n text = desc...
[ "0.6195848", "0.60888964", "0.5992785", "0.59549046", "0.59468126", "0.5927779", "0.5885494", "0.5837507", "0.580167", "0.5785005", "0.5683455", "0.56042427", "0.55971974", "0.5580477", "0.5526165", "0.55108213", "0.5507765", "0.55002797", "0.5487138", "0.54556525", "0.544013...
0.6112285
1
another way to set names)
def name=(new_name) #why is no spaces allowed between the left and right side? if new_name.is_a?(Numeric) puts "Name Can't be a number" else @name = new_name end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def name=(value); end", "def name=(_); end", "def name=(_); end", "def name=(_); end", "def name=(_); end", "def name=(_); end", "def name=(_); end", "def name=(_); end", "def name=(_); end", "def setName(n)\n @name = n\n end", "def name=(p0) end", "def name=(p0) end", "def set_name...
[ "0.74968225", "0.7375619", "0.7375619", "0.7375619", "0.7375619", "0.7375619", "0.7375619", "0.7375619", "0.7375619", "0.724888", "0.7168143", "0.7168143", "0.71681327", "0.7123754", "0.7079339", "0.7029809", "0.69825447", "0.69825447", "0.69825447", "0.69825447", "0.69825447...
0.0
-1
GET /users/1 def show render json: user end
def selfMedia myMedia = Medium.all.filter{|media| media.user_id == decoded_token} # ItinActiv = Activity.all.filter{ |activity| activity.itinerary_id == myItin.id } render json: myMedia end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def show\n render json: @user\n end", "def show\n user = User.find(params[:id])\n render json: user\n end", "def show\n user = User.find(params[:id])\n\n render json: user\n end", "def show\n user = User.find(params[:id])\n render json: user\n end", "def s...
[ "0.89024675", "0.8892518", "0.8876445", "0.8873672", "0.88573563", "0.8852768", "0.8851586", "0.88504016", "0.88504016", "0.88504016", "0.88504016", "0.88504016", "0.88504016", "0.88504016", "0.88504016", "0.8843728", "0.8843728", "0.8843728", "0.8843728", "0.8843728", "0.884...
0.0
-1
Use callbacks to share common setup or constraints between actions.
def set_user user = User.find(params[:id]) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def set_required_actions\n # TODO: check what fields change to asign required fields\n end", "def action_hook; end", "def run_actions; end", "def define_action_hook; end", "def actions; end", "def define_action_helpers\n if super && action == :save\n @instance_helper_module.class_...
[ "0.6163163", "0.6045976", "0.5946146", "0.591683", "0.5890051", "0.58349305", "0.5776858", "0.5703237", "0.5703237", "0.5652805", "0.5621621", "0.54210985", "0.5411113", "0.5411113", "0.5411113", "0.5391541", "0.53794575", "0.5357573", "0.53402257", "0.53394014", "0.53321576"...
0.0
-1
Only allow a trusted parameter "white list" through.
def user_params params.require(:user).permit(:username, :password) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def allowed_params\n ALLOWED_PARAMS\n end", "def expected_permitted_parameter_names; end", "def param_whitelist\n [:role, :title]\n end", "def default_param_whitelist\n [\"mode\"]\n end", "def permitir_parametros\n \t\tparams.permit!\n \tend", "def permitted_params\n []\n end", ...
[ "0.7121987", "0.70541996", "0.69483954", "0.6902367", "0.6733912", "0.6717838", "0.6687021", "0.6676254", "0.66612333", "0.6555296", "0.6527056", "0.6456324", "0.6450841", "0.6450127", "0.6447226", "0.6434961", "0.64121825", "0.64121825", "0.63913447", "0.63804525", "0.638045...
0.0
-1
validate working dirs return working dir from hoster
def getWorkingDir if(@workingDir != nil) return @workingDir end currDir = Dir.pwd dr = "" currDir.split("/").each{ |entry| dr = dr+entry+"/" #puts dr if(File.directory? dr+".hoster") @workingDir = dr+".hoster" end } @workingDir end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def getWorkingDir\n currDir = Dir.pwd\n dr = \"\"\n currDir.split(\"/\").each{ |entry|\n dr = dr+entry+\"/\"\n #puts dr\n if(File.directory? dr+\".hoster\")\n @workingDir = dr+\".hoster\"\n end\n }\n @workingDir\n end", "def working_dir\n ENV['PWD'] || Dir.pwd\...
[ "0.8024987", "0.69051206", "0.6808647", "0.6657322", "0.6641898", "0.6641898", "0.6641898", "0.6604515", "0.650876", "0.64121854", "0.6403523", "0.6393437", "0.6268059", "0.6246778", "0.62371033", "0.6178636", "0.6166335", "0.61659175", "0.6164491", "0.6152297", "0.6149088", ...
0.8010878
1
controls the verbosity from Hoster
def setVerbosity(v) @verbose = v end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def verbosity\n get_value :verbosity\n end", "def verbosity\n options[:verbosity] || NONE\n end", "def verbosity\n runopts(:verbosity) || 1\n end", "def verbosity (value = nil)\n\t\tif value\n\t\t\traise_if_error C.glyr_opt_verbosity(to_native, value)\n\t\telse\n\t\t\tto_native[:verbosity]\n\...
[ "0.6928093", "0.688858", "0.6859978", "0.6445701", "0.6173735", "0.6111996", "0.59563106", "0.5946382", "0.57861227", "0.5752039", "0.5745845", "0.57265395", "0.5703812", "0.56752396", "0.5665948", "0.5641108", "0.56184417", "0.5573524", "0.55657905", "0.5562949", "0.5557186"...
0.62691903
4
load Data into memory
def loadData! v = validateWorkingDir! @plataforms = YAML::load_file(File.open(getWorkingDir+'/data.host', 'r')) if(@plataforms == false) @plataforms = Hash.new end return v end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def load(data)\n end", "def load_data\n\t\tload_using_arr(train_file,train_hash,0,1)\n\t\tload_using_arr(train_file,movie_hash,1,0)\n\tend", "def load_data\n raise NotImplementedError\n end", "def preload_data\n @file.seek(0)\n @contents = StringIO.new(@file.read)\n @file.close\n end",...
[ "0.7278913", "0.72122157", "0.69835025", "0.6659714", "0.66365623", "0.66365623", "0.66365623", "0.66084826", "0.6607027", "0.65730476", "0.65687656", "0.6559745", "0.6532756", "0.6532756", "0.65316576", "0.6491057", "0.64116645", "0.639727", "0.63820183", "0.63719857", "0.63...
0.0
-1
persist data from memory
def persistData! File.open(getWorkingDir+'/data.host', 'w') do |f| f.write(@plataforms.to_yaml) end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def persist; end", "def persist; end", "def persist; end", "def persist\n \n end", "def persist(data)\n\t\tupdate_design_for self.shared_data_context\n\t\t\n\t\td = CouchRest::Document.new\n\t\td.database = proxy_database\n\n\t\t#copy data in to document\n\t\tdata.each do |key,value|\n\t\t\td[\...
[ "0.7563288", "0.7563288", "0.7563288", "0.7295846", "0.7213842", "0.717317", "0.717317", "0.717317", "0.71317965", "0.70339483", "0.6998801", "0.6919415", "0.6917812", "0.6917812", "0.6876511", "0.68251747", "0.68198377", "0.68198377", "0.6785881", "0.6777529", "0.6776586", ...
0.6725502
22
Methods from Apply, Remove, Add
def show! puts 'Current Hosts:' @plataforms.each do |key, plataform| puts plataform.toString end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def apply\n\t\t\n\tend", "def apply\n\t\t\n\tend", "def apply\n raise NotImplementedError\n end", "def apply\n\t\tunless @already_added\n\t\t\t@space.entities.add @clone\n\t\t\t@already_added = true\n\t\tend\n\t\t\n\t\t@move_action.apply\n\tend", "def add(p)\nq = self.dup\nq.add!(p)\nend", "d...
[ "0.6032514", "0.6032514", "0.60012543", "0.59078157", "0.5901869", "0.5813557", "0.580484", "0.580235", "0.5779988", "0.57524306", "0.5748541", "0.5727367", "0.5703548", "0.56755364", "0.56755364", "0.56755364", "0.56755364", "0.56562793", "0.565046", "0.565046", "0.56446546"...
0.0
-1
add the HOST to the respective plataform
def add(host, ip, plataform) #verify if we have the plataform name initialized if(! (@plataforms.keys.include? plataform)) @plataforms[plataform] = Plataform.new(plataform, projectName); end if( @plataforms[plataform].add(Host.new(ip, host, @plataforms[plataform]))) puts "Added succefully." end if(@verbosity) puts "Generating Files ..." end generateFiles! @plataforms[plataform] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def host=(new_host); end", "def host=(_); end", "def host(s) self.host_value = s ; self end", "def host=(value)\n @host = value\n end", "def host=(value)\n @host = value\n end", "def host=(new_host)\n unless new_host =~ /^http(s)?:\\/\\//\n ...
[ "0.68673056", "0.63795775", "0.63635963", "0.6347594", "0.6347594", "0.6257089", "0.62550664", "0.62172955", "0.6183394", "0.6181174", "0.61500925", "0.61392605", "0.6134259", "0.61319536", "0.6102989", "0.6087763", "0.6068078", "0.6065847", "0.60443157", "0.60375726", "0.602...
0.6701258
1
add the HOST to the respective plataform
def edit(host, ip, plataform) #verify if we have the plataform name initialized if(! (@plataforms.keys.include? plataform)) add(host,ip,plataform) else #replace the old with the new host if( @plataforms[plataform].edit(Host.new(ip, host, @plataforms[plataform])) ) puts "Edited succefully." end end if(@verbosity) puts "Generating Files ..." end generateFiles! @plataforms[plataform] end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def host=(new_host); end", "def add(host, ip, plataform)\n #verify if we have the plataform name initialized\n if(! (@plataforms.keys.include? plataform))\n @plataforms[plataform] = Plataform.new(plataform, projectName);\n end\n if( @plataforms[plataform].add(Host.new(ip, host, @plataforms[pla...
[ "0.68673056", "0.6701258", "0.63795775", "0.63635963", "0.6347594", "0.6347594", "0.6257089", "0.62550664", "0.62172955", "0.6183394", "0.6181174", "0.61500925", "0.61392605", "0.6134259", "0.61319536", "0.6102989", "0.6087763", "0.6068078", "0.6065847", "0.60443157", "0.6027...
0.60375726
20
remove HOST form the respective plataform
def remove(host, plataform) @plataforms[plataform].rem(host) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def strip_host(path)\n hosts.each do |host|\n return path if path !~ @@scheme_pattern\n\n path = path.sub(%r{^#{host}}, '')\n end\n\n return path\n end", "def normalized_host; end", "def delete_unused_host_only_networks\n end", "def unmanage_host(host)\n ...
[ "0.6652897", "0.6532928", "0.65280247", "0.6481765", "0.6442432", "0.64030874", "0.6345936", "0.6337107", "0.6192116", "0.60996276", "0.6082445", "0.6067963", "0.6047224", "0.6023887", "0.6006783", "0.6003179", "0.5997041", "0.5989398", "0.59365314", "0.59354264", "0.5930268"...
0.7410735
0
Quick comparision with another IO. Returns true if another == self, or if both are filetype IOs and their paths are equal.
def quick_compare(another) self == another || ( (self.kind_of?(File) || self.kind_of?(Tempfile)) && (another.kind_of?(File) || another.kind_of?(Tempfile)) && self.path == another.path) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def quick_compare(another)\n self == another || (self.kind_of?(File) && another.kind_of?(File) && self.path == another.path)\n end", "def ==(other)\n return false unless @path && @file_id && other.path && other.file_id\n @path == other.path && @file_id == other.file_id\n end", "def =...
[ "0.8097233", "0.7386953", "0.7266518", "0.72146535", "0.7074251", "0.69913596", "0.6990512", "0.6990512", "0.698051", "0.68272704", "0.67647535", "0.6738696", "0.66772026", "0.6676267", "0.6659377", "0.6644103", "0.66244817", "0.6623184", "0.65180176", "0.65079373", "0.646903...
0.78625375
1
rubocop: enable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity 10. multiply_els
def multiply_els(array) array.my_inject(:*) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def multiply_els\n\t\tself.my_inject(:*, self[0])\n\tend", "def multiply_els\n my_inject do |x, y|\n x * y\n end\n end", "def multiply_els(ary = nil)\n\t\treturn self.my_inject(1) { |product, x| product * x }\n\tend", "def multiply_els(arr)\n\n arr.my_inject { |memo, e| memo * e }\n\n end...
[ "0.7970351", "0.741206", "0.73961663", "0.7267877", "0.717649", "0.7050706", "0.6983096", "0.6802686", "0.67815655", "0.67814475", "0.67587227", "0.67576605", "0.6708712", "0.66827965", "0.66827965", "0.66827965", "0.66827965", "0.66604173", "0.66604173", "0.66604173", "0.665...
0.6696836
15
Use the specified default font size or fall back to 40.
def default_font_size (options[:default] and options[:default][:size]) ? options[:default][:size] : 40 end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def font_size(size=nil)\n cur_page.font_size(size)\n end", "def font_size\r\n @style.font_size || @default_font_size\r\n end", "def default_size_multiplier(font)\n\n # Define font hash.\n factors = {\n across_the_road: 0.7,\n alabama: 0.8,\n arty_signature: 2.5,\n asem...
[ "0.75812197", "0.75523794", "0.7510447", "0.7406985", "0.72944874", "0.70432246", "0.6961955", "0.6874849", "0.6847032", "0.68153447", "0.6799136", "0.6778315", "0.676928", "0.6746436", "0.6735783", "0.6735783", "0.67226326", "0.67226326", "0.67053723", "0.6665793", "0.654002...
0.8409858
0
Use the specified default font name or fall back to Gosu's default font name.
def default_font_name (options[:default] and options[:default][:name]) ? options[:default][:name] : Gosu::default_font_name end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def default_font_name()\n end", "def default_font; \"example.font\"; end", "def font(name=nil, size=nil, options={})\n cur_page.font(name, size, options)\n end", "def font(name)\n primitive \"font \\'#{name}\\'\"\n end", "def font(name=\"Helvetica\", size=nil)\n fontsize(size) if siz...
[ "0.77926874", "0.74798536", "0.74032587", "0.731019", "0.7048216", "0.67985547", "0.6775121", "0.6764476", "0.66966456", "0.6695606", "0.6651855", "0.6609098", "0.66037035", "0.6599288", "0.65974", "0.6560158", "0.6537228", "0.6537228", "0.6535306", "0.65063345", "0.64784485"...
0.8513925
0
Returns the cosine of the angle between the vectors associated with 2 points Params: a, b: list of coordinates (float or integer)
def cosine_similarity(a, b) dot_product(a, b) / (magnitude(a) * magnitude(b)) end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def angle_to(a,b)\n a,b = *[a,b].map(&:to_np)\n d0,d1 = dist_from(a), a.dist_from(b)\n z = self.to(a,1+d1/d0)\n dz = z.dist_from(b)\n Math.asin(dz/2/d1)*2\n end", "def angle(*args)\n Math.acos(self.dot(*args))\n end", "def angle(vector1,vector2)\n\n small = 0.00000001\n un...
[ "0.7424524", "0.70340157", "0.70094156", "0.687473", "0.6712788", "0.66427666", "0.6603376", "0.6596083", "0.6489769", "0.64886653", "0.6485239", "0.64732546", "0.64638937", "0.6392698", "0.6374051", "0.6361054", "0.63344693", "0.63325167", "0.6321235", "0.620299", "0.6198962...
0.6572983
8
////////////////////////////////////////////////////////////////////////// Public Methods ////////////////////////////////////////////////////////////////////////// Frame update (contents are defined by the subclasses)
def update() end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def update\n super\n # update_bitmap # Not needed for now\n update_screen # Update the position the graphic should be displayed\n # update_frame # Update the frame count (if wanted later)\n end", "def update\n @currentFrame += 1\n self.updateElements\n if !@totalFrames.nil? && @totalFr...
[ "0.70874745", "0.6894044", "0.6889739", "0.6754784", "0.67061424", "0.6639494", "0.6388879", "0.63321644", "0.63241845", "0.62872374", "0.6242672", "0.6241001", "0.6218439", "0.6198013", "0.6185239", "0.61530936", "0.6129666", "0.6084949", "0.6077006", "0.60464555", "0.603723...
0.0
-1
plays until a win or the player runs out of turns
def play while !win && @turns < TURNS turn end # counter increments at start of turn, so must be less than max turns if win play_again else puts "\n Sorry, you ran out of turns. The word was #{@secret_word}" play_again end end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def play\n #turns = 0\n until over?\n turn\n end\nend", "def play\nturn until over?\nif won?\n puts \"Congratulations #{winner}!\"\nelsif draw? == true\n puts \"Game over! Thanks for playing.\"\nend\nend", "def play\n until over? == true\n turn\n end\n\n if won? != false\n puts \"Con...
[ "0.7959072", "0.7871622", "0.7830902", "0.77981", "0.77513725", "0.7718744", "0.7692074", "0.76839626", "0.764572", "0.7626004", "0.7593268", "0.75839317", "0.7575653", "0.75661635", "0.75650746", "0.7530873", "0.7516912", "0.7512089", "0.75036705", "0.7488666", "0.7476639", ...
0.80432403
0
accepts one character from user and checks for matches and win
def turn @turns += 1 @guess_letter = gets[0].downcase show_matches check_win end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def guess\n loop do\n input = gets.chomp\n (\"a\"..\"z\").include?(input) ? (return input) : (puts \"Invalid input - single English-alphabet characters only\")\n end\n end", "def guess char\n #get 1st char\n \n if char.nil?\n raise ArgumentError, 'Argument is not string' \n re...
[ "0.73862773", "0.7365805", "0.7151134", "0.71241593", "0.7113469", "0.71099156", "0.7055931", "0.69584954", "0.6923531", "0.6896129", "0.6883255", "0.687538", "0.6868289", "0.68646324", "0.6858497", "0.68534243", "0.6837086", "0.6822091", "0.6777266", "0.6777198", "0.67570883...
0.63218516
84
win when cumulative guesses equal the secret word
def win @guess_word == @secret_word end
{ "objective": { "self": [], "paired": [], "triplet": [ [ "query", "document", "negatives" ] ] } }
[ "def check_win\r\n\t\tif @guess_word == @secret_word \r\n\t\t\t@is_over = true \r\n\t\t\tputs \"Congrats! You won!\"\r\n\t\telse\r\n\t\t\tfalse \r\n\t\tend \r\n\r\n\t\tif @num_guess == 0 \r\n\t\t\t@is_over = true\r\n\t\t\tputs \"No more tries! You have lost.\"\r\n\t\telse \r\n\t\t\tfalse\r\n\t\tend \r\n\tend", "d...
[ "0.74198985", "0.71510345", "0.7075354", "0.7052938", "0.7051208", "0.7026164", "0.6980449", "0.69685405", "0.69194674", "0.68709517", "0.686824", "0.68665", "0.6821736", "0.68119997", "0.6767848", "0.67658025", "0.67444605", "0.6741859", "0.6736668", "0.66978693", "0.6692688...
0.7675303
0