id
int32
0
24.9k
repo
stringlengths
5
58
path
stringlengths
9
168
func_name
stringlengths
9
130
original_string
stringlengths
66
10.5k
language
stringclasses
1 value
code
stringlengths
66
10.5k
code_tokens
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
1,600
mynameisrufus/sorted
lib/sorted/set.rb
Sorted.Set.c
def c(memo) each do |order| unless memo.keys.include?(order[0]) memo << order end end end
ruby
def c(memo) each do |order| unless memo.keys.include?(order[0]) memo << order end end end
[ "def", "c", "(", "memo", ")", "each", "do", "|", "order", "|", "unless", "memo", ".", "keys", ".", "include?", "(", "order", "[", "0", "]", ")", "memo", "<<", "order", "end", "end", "end" ]
Add items not in memo
[ "Add", "items", "not", "in", "memo" ]
6490682f7970e27b692ff0c931f04cf86a52ec0a
https://github.com/mynameisrufus/sorted/blob/6490682f7970e27b692ff0c931f04cf86a52ec0a/lib/sorted/set.rb#L214-L220
1,601
mynameisrufus/sorted
lib/sorted/set.rb
Sorted.Set.d
def d(memo, other) other.each do |sort| unless memo.keys.include?(sort[0]) memo << sort end end end
ruby
def d(memo, other) other.each do |sort| unless memo.keys.include?(sort[0]) memo << sort end end end
[ "def", "d", "(", "memo", ",", "other", ")", "other", ".", "each", "do", "|", "sort", "|", "unless", "memo", ".", "keys", ".", "include?", "(", "sort", "[", "0", "]", ")", "memo", "<<", "sort", "end", "end", "end" ]
Add items from other not in memo
[ "Add", "items", "from", "other", "not", "in", "memo" ]
6490682f7970e27b692ff0c931f04cf86a52ec0a
https://github.com/mynameisrufus/sorted/blob/6490682f7970e27b692ff0c931f04cf86a52ec0a/lib/sorted/set.rb#L223-L229
1,602
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.list_triggers
def list_triggers(ids = [], tags = []) query = generate_query_params 'triggerIds' => ids, 'tags' => tags sub_url = '/triggers' + query ret = http_get(sub_url) val = [] ret.each { |t| val.push(Trigger.new(t)) } val end
ruby
def list_triggers(ids = [], tags = []) query = generate_query_params 'triggerIds' => ids, 'tags' => tags sub_url = '/triggers' + query ret = http_get(sub_url) val = [] ret.each { |t| val.push(Trigger.new(t)) } val end
[ "def", "list_triggers", "(", "ids", "=", "[", "]", ",", "tags", "=", "[", "]", ")", "query", "=", "generate_query_params", "'triggerIds'", "=>", "ids", ",", "'tags'", "=>", "tags", "sub_url", "=", "'/triggers'", "+", "query", "ret", "=", "http_get", "(", "sub_url", ")", "val", "=", "[", "]", "ret", ".", "each", "{", "|", "t", "|", "val", ".", "push", "(", "Trigger", ".", "new", "(", "t", ")", ")", "}", "val", "end" ]
Lists defined triggers in the system @param [Array] ids List of trigger ids. If provided, limits to the given triggers @param [Array] tags List of tags. If provided, limits to the given tags. Individual tags are of the format # key|value. Tags are OR'd together. If a tag-key shows up more than once, only the last one is accepted @return [Array<Trigger>] Triggers found
[ "Lists", "defined", "triggers", "in", "the", "system" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L37-L46
1,603
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.get_single_trigger
def get_single_trigger(trigger_id, full = false) the_trigger = '/triggers/' + trigger_id ret = http_get(the_trigger) trigger = Trigger.new(ret) if full ret = http_get(the_trigger + '/conditions') ret.each { |c| trigger.conditions.push(Trigger::Condition.new(c)) } ret = http_get(the_trigger + '/dampenings') ret.each { |c| trigger.dampenings.push(Trigger::Dampening.new(c)) } end trigger end
ruby
def get_single_trigger(trigger_id, full = false) the_trigger = '/triggers/' + trigger_id ret = http_get(the_trigger) trigger = Trigger.new(ret) if full ret = http_get(the_trigger + '/conditions') ret.each { |c| trigger.conditions.push(Trigger::Condition.new(c)) } ret = http_get(the_trigger + '/dampenings') ret.each { |c| trigger.dampenings.push(Trigger::Dampening.new(c)) } end trigger end
[ "def", "get_single_trigger", "(", "trigger_id", ",", "full", "=", "false", ")", "the_trigger", "=", "'/triggers/'", "+", "trigger_id", "ret", "=", "http_get", "(", "the_trigger", ")", "trigger", "=", "Trigger", ".", "new", "(", "ret", ")", "if", "full", "ret", "=", "http_get", "(", "the_trigger", "+", "'/conditions'", ")", "ret", ".", "each", "{", "|", "c", "|", "trigger", ".", "conditions", ".", "push", "(", "Trigger", "::", "Condition", ".", "new", "(", "c", ")", ")", "}", "ret", "=", "http_get", "(", "the_trigger", "+", "'/dampenings'", ")", "ret", ".", "each", "{", "|", "c", "|", "trigger", ".", "dampenings", ".", "push", "(", "Trigger", "::", "Dampening", ".", "new", "(", "c", ")", ")", "}", "end", "trigger", "end" ]
Obtains one Trigger definition from the server. @param [String] trigger_id Id of the trigger to fetch @param full If true then conditions and dampenings for the trigger are also fetched @return [Trigger] the selected trigger
[ "Obtains", "one", "Trigger", "definition", "from", "the", "server", "." ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L52-L65
1,604
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.create_trigger
def create_trigger(trigger, conditions = [], dampenings = [], _actions = []) full_trigger = {} full_trigger[:trigger] = trigger.to_h conds = [] conditions.each { |c| conds.push(c.to_h) } full_trigger[:conditions] = conds damps = [] dampenings.each { |d| damps.push(d.to_h) } unless dampenings.nil? full_trigger[:dampenings] = damps http_post 'triggers/trigger', full_trigger end
ruby
def create_trigger(trigger, conditions = [], dampenings = [], _actions = []) full_trigger = {} full_trigger[:trigger] = trigger.to_h conds = [] conditions.each { |c| conds.push(c.to_h) } full_trigger[:conditions] = conds damps = [] dampenings.each { |d| damps.push(d.to_h) } unless dampenings.nil? full_trigger[:dampenings] = damps http_post 'triggers/trigger', full_trigger end
[ "def", "create_trigger", "(", "trigger", ",", "conditions", "=", "[", "]", ",", "dampenings", "=", "[", "]", ",", "_actions", "=", "[", "]", ")", "full_trigger", "=", "{", "}", "full_trigger", "[", ":trigger", "]", "=", "trigger", ".", "to_h", "conds", "=", "[", "]", "conditions", ".", "each", "{", "|", "c", "|", "conds", ".", "push", "(", "c", ".", "to_h", ")", "}", "full_trigger", "[", ":conditions", "]", "=", "conds", "damps", "=", "[", "]", "dampenings", ".", "each", "{", "|", "d", "|", "damps", ".", "push", "(", "d", ".", "to_h", ")", "}", "unless", "dampenings", ".", "nil?", "full_trigger", "[", ":dampenings", "]", "=", "damps", "http_post", "'triggers/trigger'", ",", "full_trigger", "end" ]
Creates the trigger definition. @param [Trigger] trigger The trigger to be created @param [Array<Condition>] conditions Array of associated conditions @param [Array<Dampening>] dampenings Array of associated dampenings @return [Trigger] The newly created trigger
[ "Creates", "the", "trigger", "definition", "." ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L80-L91
1,605
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.set_group_conditions
def set_group_conditions(trigger_id, trigger_mode, group_conditions_info) ret = http_put "triggers/groups/#{trigger_id}/conditions/#{trigger_mode}", group_conditions_info.to_h conditions = [] ret.each { |c| conditions.push(Trigger::Condition.new(c)) } conditions end
ruby
def set_group_conditions(trigger_id, trigger_mode, group_conditions_info) ret = http_put "triggers/groups/#{trigger_id}/conditions/#{trigger_mode}", group_conditions_info.to_h conditions = [] ret.each { |c| conditions.push(Trigger::Condition.new(c)) } conditions end
[ "def", "set_group_conditions", "(", "trigger_id", ",", "trigger_mode", ",", "group_conditions_info", ")", "ret", "=", "http_put", "\"triggers/groups/#{trigger_id}/conditions/#{trigger_mode}\"", ",", "group_conditions_info", ".", "to_h", "conditions", "=", "[", "]", "ret", ".", "each", "{", "|", "c", "|", "conditions", ".", "push", "(", "Trigger", "::", "Condition", ".", "new", "(", "c", ")", ")", "}", "conditions", "end" ]
Creates the group conditions definitions. @param [String] trigger_id ID of the group trigger to set conditions @param [String] trigger_mode Mode of the trigger where conditions are attached (:FIRING, :AUTORESOLVE) @param [GroupConditionsInfo] group_conditions_info the conditions to set into the group trigger with the mapping with the data_id members map @return [Array<Condition>] conditions Array of associated conditions
[ "Creates", "the", "group", "conditions", "definitions", "." ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L115-L120
1,606
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.list_members
def list_members(trigger_id, orphans = false) ret = http_get "triggers/groups/#{trigger_id}/members?includeOrphans=#{orphans}" ret.collect { |t| Trigger.new(t) } end
ruby
def list_members(trigger_id, orphans = false) ret = http_get "triggers/groups/#{trigger_id}/members?includeOrphans=#{orphans}" ret.collect { |t| Trigger.new(t) } end
[ "def", "list_members", "(", "trigger_id", ",", "orphans", "=", "false", ")", "ret", "=", "http_get", "\"triggers/groups/#{trigger_id}/members?includeOrphans=#{orphans}\"", "ret", ".", "collect", "{", "|", "t", "|", "Trigger", ".", "new", "(", "t", ")", "}", "end" ]
Lists members of a group trigger @param [String] trigger_id ID of the group trigger to list members @param [boolean] orphans flag to include orphans @return [Array<Trigger>] Members found
[ "Lists", "members", "of", "a", "group", "trigger" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L142-L145
1,607
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.create_group_dampening
def create_group_dampening(dampening) ret = http_post "triggers/groups/#{dampening.trigger_id}/dampenings", dampening.to_h Trigger::Dampening.new(ret) end
ruby
def create_group_dampening(dampening) ret = http_post "triggers/groups/#{dampening.trigger_id}/dampenings", dampening.to_h Trigger::Dampening.new(ret) end
[ "def", "create_group_dampening", "(", "dampening", ")", "ret", "=", "http_post", "\"triggers/groups/#{dampening.trigger_id}/dampenings\"", ",", "dampening", ".", "to_h", "Trigger", "::", "Dampening", ".", "new", "(", "ret", ")", "end" ]
Creates a dampening for a group trigger @param [Dampening] dampening the dampening to create @return [Dampening] the newly created dampening
[ "Creates", "a", "dampening", "for", "a", "group", "trigger" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L150-L153
1,608
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.update_group_dampening
def update_group_dampening(dampening) ret = http_put "triggers/groups/#{dampening.trigger_id}/dampenings/#{dampening.dampening_id}", dampening.to_h Trigger::Dampening.new(ret) end
ruby
def update_group_dampening(dampening) ret = http_put "triggers/groups/#{dampening.trigger_id}/dampenings/#{dampening.dampening_id}", dampening.to_h Trigger::Dampening.new(ret) end
[ "def", "update_group_dampening", "(", "dampening", ")", "ret", "=", "http_put", "\"triggers/groups/#{dampening.trigger_id}/dampenings/#{dampening.dampening_id}\"", ",", "dampening", ".", "to_h", "Trigger", "::", "Dampening", ".", "new", "(", "ret", ")", "end" ]
Updates a dampening for a group trigger @param [Dampening] dampening the dampening to update @return [Dampening] the updated dampening
[ "Updates", "a", "dampening", "for", "a", "group", "trigger" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L158-L161
1,609
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.create_action
def create_action(plugin, action_id, properties = {}) the_plugin = hawk_escape plugin # Check if plugin exists http_get("/plugins/#{the_plugin}") payload = { actionId: action_id, actionPlugin: plugin, properties: properties } ret = http_post('/actions', payload) Trigger::Action.new(ret) end
ruby
def create_action(plugin, action_id, properties = {}) the_plugin = hawk_escape plugin # Check if plugin exists http_get("/plugins/#{the_plugin}") payload = { actionId: action_id, actionPlugin: plugin, properties: properties } ret = http_post('/actions', payload) Trigger::Action.new(ret) end
[ "def", "create_action", "(", "plugin", ",", "action_id", ",", "properties", "=", "{", "}", ")", "the_plugin", "=", "hawk_escape", "plugin", "# Check if plugin exists", "http_get", "(", "\"/plugins/#{the_plugin}\"", ")", "payload", "=", "{", "actionId", ":", "action_id", ",", "actionPlugin", ":", "plugin", ",", "properties", ":", "properties", "}", "ret", "=", "http_post", "(", "'/actions'", ",", "payload", ")", "Trigger", "::", "Action", ".", "new", "(", "ret", ")", "end" ]
Creates the action. @param [String] plugin The id of action definition/plugin @param [String] action_id The id of action @param [Hash] properties Troperties of action @return [Action] The newly created action
[ "Creates", "the", "action", "." ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L198-L206
1,610
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.get_action
def get_action(plugin, action_id) the_plugin = hawk_escape plugin the_action_id = hawk_escape action_id ret = http_get "/actions/#{the_plugin}/#{the_action_id}" Trigger::Action.new(ret) end
ruby
def get_action(plugin, action_id) the_plugin = hawk_escape plugin the_action_id = hawk_escape action_id ret = http_get "/actions/#{the_plugin}/#{the_action_id}" Trigger::Action.new(ret) end
[ "def", "get_action", "(", "plugin", ",", "action_id", ")", "the_plugin", "=", "hawk_escape", "plugin", "the_action_id", "=", "hawk_escape", "action_id", "ret", "=", "http_get", "\"/actions/#{the_plugin}/#{the_action_id}\"", "Trigger", "::", "Action", ".", "new", "(", "ret", ")", "end" ]
Obtains one action of given action plugin from the server. @param [String] plugin Id of the action plugin @param [String] action_id Id of the action @return [Action] the selected trigger
[ "Obtains", "one", "action", "of", "given", "action", "plugin", "from", "the", "server", "." ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L212-L217
1,611
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.delete_action
def delete_action(plugin, action_id) the_plugin = hawk_escape plugin the_action_id = hawk_escape action_id http_delete "/actions/#{the_plugin}/#{the_action_id}" end
ruby
def delete_action(plugin, action_id) the_plugin = hawk_escape plugin the_action_id = hawk_escape action_id http_delete "/actions/#{the_plugin}/#{the_action_id}" end
[ "def", "delete_action", "(", "plugin", ",", "action_id", ")", "the_plugin", "=", "hawk_escape", "plugin", "the_action_id", "=", "hawk_escape", "action_id", "http_delete", "\"/actions/#{the_plugin}/#{the_action_id}\"", "end" ]
Deletes the action of given action plugin. @param [String] plugin Id of the action plugin @param [String] action_id Id of the action
[ "Deletes", "the", "action", "of", "given", "action", "plugin", "." ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L222-L226
1,612
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.get_alerts_for_trigger
def get_alerts_for_trigger(trigger_id) # TODO: add additional filters return [] unless trigger_id url = '/?triggerIds=' + trigger_id ret = http_get(url) val = [] ret.each { |a| val.push(Alert.new(a)) } val end
ruby
def get_alerts_for_trigger(trigger_id) # TODO: add additional filters return [] unless trigger_id url = '/?triggerIds=' + trigger_id ret = http_get(url) val = [] ret.each { |a| val.push(Alert.new(a)) } val end
[ "def", "get_alerts_for_trigger", "(", "trigger_id", ")", "# TODO: add additional filters", "return", "[", "]", "unless", "trigger_id", "url", "=", "'/?triggerIds='", "+", "trigger_id", "ret", "=", "http_get", "(", "url", ")", "val", "=", "[", "]", "ret", ".", "each", "{", "|", "a", "|", "val", ".", "push", "(", "Alert", ".", "new", "(", "a", ")", ")", "}", "val", "end" ]
Obtain the alerts for the Trigger with the passed id @param [String] trigger_id Id of the trigger that has fired the alerts @return [Array<Alert>] List of alerts for the trigger. Can be empty
[ "Obtain", "the", "alerts", "for", "the", "Trigger", "with", "the", "passed", "id" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L231-L240
1,613
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.alerts
def alerts(criteria: {}, tenants: nil) query = generate_query_params(criteria) uri = tenants ? '/admin/alerts/' : '/' ret = http_get(uri + query, multi_tenants_header(tenants)) val = [] ret.each { |a| val.push(Alert.new(a)) } val end
ruby
def alerts(criteria: {}, tenants: nil) query = generate_query_params(criteria) uri = tenants ? '/admin/alerts/' : '/' ret = http_get(uri + query, multi_tenants_header(tenants)) val = [] ret.each { |a| val.push(Alert.new(a)) } val end
[ "def", "alerts", "(", "criteria", ":", "{", "}", ",", "tenants", ":", "nil", ")", "query", "=", "generate_query_params", "(", "criteria", ")", "uri", "=", "tenants", "?", "'/admin/alerts/'", ":", "'/'", "ret", "=", "http_get", "(", "uri", "+", "query", ",", "multi_tenants_header", "(", "tenants", ")", ")", "val", "=", "[", "]", "ret", ".", "each", "{", "|", "a", "|", "val", ".", "push", "(", "Alert", ".", "new", "(", "a", ")", ")", "}", "val", "end" ]
List fired alerts @param [Hash] criteria optional query criteria @param [Array] tenants optional list of tenants. The elements of the array can be any object convertible to a string @return [Array<Alert>] List of alerts in the system. Can be empty
[ "List", "fired", "alerts" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L254-L261
1,614
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.get_single_alert
def get_single_alert(alert_id) ret = http_get('/alert/' + alert_id) val = Alert.new(ret) val end
ruby
def get_single_alert(alert_id) ret = http_get('/alert/' + alert_id) val = Alert.new(ret) val end
[ "def", "get_single_alert", "(", "alert_id", ")", "ret", "=", "http_get", "(", "'/alert/'", "+", "alert_id", ")", "val", "=", "Alert", ".", "new", "(", "ret", ")", "val", "end" ]
Retrieve a single Alert by its id @param [String] alert_id id of the alert to fetch @return [Alert] Alert object retrieved
[ "Retrieve", "a", "single", "Alert", "by", "its", "id" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L266-L270
1,615
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.resolve_alert
def resolve_alert(alert_id, by = nil, comment = nil) sub_url = "/resolve/#{alert_id}" query = generate_query_params 'resolvedBy' => by, 'resolvedNotes' => comment sub_url += query http_put(sub_url, {}) true end
ruby
def resolve_alert(alert_id, by = nil, comment = nil) sub_url = "/resolve/#{alert_id}" query = generate_query_params 'resolvedBy' => by, 'resolvedNotes' => comment sub_url += query http_put(sub_url, {}) true end
[ "def", "resolve_alert", "(", "alert_id", ",", "by", "=", "nil", ",", "comment", "=", "nil", ")", "sub_url", "=", "\"/resolve/#{alert_id}\"", "query", "=", "generate_query_params", "'resolvedBy'", "=>", "by", ",", "'resolvedNotes'", "=>", "comment", "sub_url", "+=", "query", "http_put", "(", "sub_url", ",", "{", "}", ")", "true", "end" ]
Mark one alert as resolved @param [String] alert_id Id of the alert to resolve @param [String] by name of the user resolving the alert @param [String] comment A comment on the resolution
[ "Mark", "one", "alert", "as", "resolved" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L276-L283
1,616
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.create_event
def create_event(id, category, text, extras) event = {} event['id'] = id event['ctime'] = Time.now.to_i * 1000 event['category'] = category event['text'] = text event.merge!(extras) { |_key, v1, _v2| v1 } http_post('/events', event) end
ruby
def create_event(id, category, text, extras) event = {} event['id'] = id event['ctime'] = Time.now.to_i * 1000 event['category'] = category event['text'] = text event.merge!(extras) { |_key, v1, _v2| v1 } http_post('/events', event) end
[ "def", "create_event", "(", "id", ",", "category", ",", "text", ",", "extras", ")", "event", "=", "{", "}", "event", "[", "'id'", "]", "=", "id", "event", "[", "'ctime'", "]", "=", "Time", ".", "now", ".", "to_i", "*", "1000", "event", "[", "'category'", "]", "=", "category", "event", "[", "'text'", "]", "=", "text", "event", ".", "merge!", "(", "extras", ")", "{", "|", "_key", ",", "v1", ",", "_v2", "|", "v1", "}", "http_post", "(", "'/events'", ",", "event", ")", "end" ]
Inject an event into Hawkular-alerts @param [String] id Id of the event must be unique @param [String] category Event category for further distinction @param [String] text Some text to the user @param [Hash<String,Object>] extras additional parameters
[ "Inject", "an", "event", "into", "Hawkular", "-", "alerts" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L335-L344
1,617
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.add_tags
def add_tags(alert_ids, tags) query = generate_query_params(alertIds: alert_ids, tags: tags) http_put('/tags' + query, {}) end
ruby
def add_tags(alert_ids, tags) query = generate_query_params(alertIds: alert_ids, tags: tags) http_put('/tags' + query, {}) end
[ "def", "add_tags", "(", "alert_ids", ",", "tags", ")", "query", "=", "generate_query_params", "(", "alertIds", ":", "alert_ids", ",", "tags", ":", "tags", ")", "http_put", "(", "'/tags'", "+", "query", ",", "{", "}", ")", "end" ]
Add tags to existing Alerts. @param [Array<numeric>] alert_ids List of alert IDs @param [Array<String>] tags List of tags. Each tag of format 'name|value'.
[ "Add", "tags", "to", "existing", "Alerts", "." ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L353-L356
1,618
hawkular/hawkular-client-ruby
lib/hawkular/alerts/alerts_api.rb
Hawkular::Alerts.Client.remove_tags
def remove_tags(alert_ids, tag_names) query = generate_query_params(alertIds: alert_ids, tagNames: tag_names) http_delete('/tags' + query) end
ruby
def remove_tags(alert_ids, tag_names) query = generate_query_params(alertIds: alert_ids, tagNames: tag_names) http_delete('/tags' + query) end
[ "def", "remove_tags", "(", "alert_ids", ",", "tag_names", ")", "query", "=", "generate_query_params", "(", "alertIds", ":", "alert_ids", ",", "tagNames", ":", "tag_names", ")", "http_delete", "(", "'/tags'", "+", "query", ")", "end" ]
Remove tags from existing Alerts. @param [Array<numeric>] alert_ids List of alert IDs @param [Array<String>] tag_names List of tag names.
[ "Remove", "tags", "from", "existing", "Alerts", "." ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/alerts/alerts_api.rb#L361-L364
1,619
paddor/cztop
lib/cztop/cert_store.rb
CZTop.CertStore.lookup
def lookup(pubkey) ptr = ffi_delegate.lookup(pubkey) return nil if ptr.null? Certificate.from_ffi_delegate(ptr) end
ruby
def lookup(pubkey) ptr = ffi_delegate.lookup(pubkey) return nil if ptr.null? Certificate.from_ffi_delegate(ptr) end
[ "def", "lookup", "(", "pubkey", ")", "ptr", "=", "ffi_delegate", ".", "lookup", "(", "pubkey", ")", "return", "nil", "if", "ptr", ".", "null?", "Certificate", ".", "from_ffi_delegate", "(", "ptr", ")", "end" ]
Initializes a new certificate store. @param location [String, #to_s, nil] location the path to the directories to load certificates from, or nil if no certificates need to be loaded from the disk Looks up a certificate in the store by its public key. @param pubkey [String] the public key in question, in Z85 format @return [Certificate] the matching certificate, if found @return [nil] if no matching certificate was found
[ "Initializes", "a", "new", "certificate", "store", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/cert_store.rb#L29-L33
1,620
paddor/cztop
lib/cztop/cert_store.rb
CZTop.CertStore.insert
def insert(cert) raise ArgumentError unless cert.is_a?(Certificate) @_inserted_pubkeys ||= Set.new pubkey = cert.public_key raise ArgumentError if @_inserted_pubkeys.include? pubkey ffi_delegate.insert(cert.ffi_delegate) @_inserted_pubkeys << pubkey end
ruby
def insert(cert) raise ArgumentError unless cert.is_a?(Certificate) @_inserted_pubkeys ||= Set.new pubkey = cert.public_key raise ArgumentError if @_inserted_pubkeys.include? pubkey ffi_delegate.insert(cert.ffi_delegate) @_inserted_pubkeys << pubkey end
[ "def", "insert", "(", "cert", ")", "raise", "ArgumentError", "unless", "cert", ".", "is_a?", "(", "Certificate", ")", "@_inserted_pubkeys", "||=", "Set", ".", "new", "pubkey", "=", "cert", ".", "public_key", "raise", "ArgumentError", "if", "@_inserted_pubkeys", ".", "include?", "pubkey", "ffi_delegate", ".", "insert", "(", "cert", ".", "ffi_delegate", ")", "@_inserted_pubkeys", "<<", "pubkey", "end" ]
Inserts a new certificate into the store. @note The same public key must not be inserted more than once. @param cert [Certificate] the certificate to insert @return [void] @raise [ArgumentError] if the given certificate is not a Certificate object or has been inserted before already
[ "Inserts", "a", "new", "certificate", "into", "the", "store", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/cert_store.rb#L42-L51
1,621
apotonick/declarative
lib/declarative/heritage.rb
Declarative.Heritage.record
def record(method, *args, &block) self << {method: method, args: DeepDup.(args), block: block} # DISCUSS: options.dup. end
ruby
def record(method, *args, &block) self << {method: method, args: DeepDup.(args), block: block} # DISCUSS: options.dup. end
[ "def", "record", "(", "method", ",", "*", "args", ",", "&", "block", ")", "self", "<<", "{", "method", ":", "method", ",", "args", ":", "DeepDup", ".", "(", "args", ")", ",", "block", ":", "block", "}", "# DISCUSS: options.dup.", "end" ]
Record inheritable assignments for replay in an inheriting class.
[ "Record", "inheritable", "assignments", "for", "replay", "in", "an", "inheriting", "class", "." ]
927ecf53fd9b94b85be29a5a0bab115057ecee9b
https://github.com/apotonick/declarative/blob/927ecf53fd9b94b85be29a5a0bab115057ecee9b/lib/declarative/heritage.rb#L6-L8
1,622
flori/protocol
lib/protocol/utilities.rb
Protocol.Utilities.find_method_module
def find_method_module(methodname, ancestors) methodname = methodname.to_s ancestors.each do |a| begin a.instance_method(methodname) return a rescue NameError end end nil end
ruby
def find_method_module(methodname, ancestors) methodname = methodname.to_s ancestors.each do |a| begin a.instance_method(methodname) return a rescue NameError end end nil end
[ "def", "find_method_module", "(", "methodname", ",", "ancestors", ")", "methodname", "=", "methodname", ".", "to_s", "ancestors", ".", "each", "do", "|", "a", "|", "begin", "a", ".", "instance_method", "(", "methodname", ")", "return", "a", "rescue", "NameError", "end", "end", "nil", "end" ]
This Method tries to find the first module that implements the method named +methodname+ in the array of +ancestors+. If this fails nil is returned.
[ "This", "Method", "tries", "to", "find", "the", "first", "module", "that", "implements", "the", "method", "named", "+", "methodname", "+", "in", "the", "array", "of", "+", "ancestors", "+", ".", "If", "this", "fails", "nil", "is", "returned", "." ]
528f250f84a46b0f3e6fccf06430ed413c7d994c
https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/utilities.rb#L9-L19
1,623
paddor/cztop
lib/cztop/monitor.rb
CZTop.Monitor.listen
def listen(*events) events.each do |event| EVENTS.include?(event) or raise ArgumentError, "invalid event: #{event.inspect}" end @actor << [ "LISTEN", *events ] end
ruby
def listen(*events) events.each do |event| EVENTS.include?(event) or raise ArgumentError, "invalid event: #{event.inspect}" end @actor << [ "LISTEN", *events ] end
[ "def", "listen", "(", "*", "events", ")", "events", ".", "each", "do", "|", "event", "|", "EVENTS", ".", "include?", "(", "event", ")", "or", "raise", "ArgumentError", ",", "\"invalid event: #{event.inspect}\"", "end", "@actor", "<<", "[", "\"LISTEN\"", ",", "events", "]", "end" ]
Configure monitor to listen for specific events. @param events [String] one or more events from {EVENTS} @return [void]
[ "Configure", "monitor", "to", "listen", "for", "specific", "events", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/monitor.rb#L63-L69
1,624
damian/jshint
lib/jshint/reporters/junit.rb
Jshint::Reporters.Junit.print_errors_for_code
def print_errors_for_code(code, errors) name = fetch_error_messages(code, errors) output << " <testcase classname=\"jshint.#{code}\" name=\"#{escape(name)}\">\n" errors.each do |error| output << add_error_message(code, error) end output << " </testcase>\n" output end
ruby
def print_errors_for_code(code, errors) name = fetch_error_messages(code, errors) output << " <testcase classname=\"jshint.#{code}\" name=\"#{escape(name)}\">\n" errors.each do |error| output << add_error_message(code, error) end output << " </testcase>\n" output end
[ "def", "print_errors_for_code", "(", "code", ",", "errors", ")", "name", "=", "fetch_error_messages", "(", "code", ",", "errors", ")", "output", "<<", "\" <testcase classname=\\\"jshint.#{code}\\\" name=\\\"#{escape(name)}\\\">\\n\"", "errors", ".", "each", "do", "|", "error", "|", "output", "<<", "add_error_message", "(", "code", ",", "error", ")", "end", "output", "<<", "\" </testcase>\\n\"", "output", "end" ]
Appends new error elements to the Report output @example <testcase classname="JUnitXmlReporter.constructor" name="should default path to an empty string" time="0.006"> <failure message="test failure">Assertion failed</failure> </testcase> @param code [String] The error code @param errors [Array] The errors for the code @return [void]
[ "Appends", "new", "error", "elements", "to", "the", "Report", "output" ]
d7dc6f1913bad5927ac0de3e34714ef920e86cbe
https://github.com/damian/jshint/blob/d7dc6f1913bad5927ac0de3e34714ef920e86cbe/lib/jshint/reporters/junit.rb#L74-L82
1,625
flori/protocol
lib/protocol/protocol_module.rb
Protocol.ProtocolModule.to_ruby
def to_ruby(result = '') result << "#{name} = Protocol do" first = true if messages.empty? result << "\n" else messages.each do |m| result << "\n" m.to_ruby(result) end end result << "end\n" end
ruby
def to_ruby(result = '') result << "#{name} = Protocol do" first = true if messages.empty? result << "\n" else messages.each do |m| result << "\n" m.to_ruby(result) end end result << "end\n" end
[ "def", "to_ruby", "(", "result", "=", "''", ")", "result", "<<", "\"#{name} = Protocol do\"", "first", "=", "true", "if", "messages", ".", "empty?", "result", "<<", "\"\\n\"", "else", "messages", ".", "each", "do", "|", "m", "|", "result", "<<", "\"\\n\"", "m", ".", "to_ruby", "(", "result", ")", "end", "end", "result", "<<", "\"end\\n\"", "end" ]
Concatenates the protocol as Ruby code to the +result+ string and return it. At the moment this method only supports method signatures with generic argument names.
[ "Concatenates", "the", "protocol", "as", "Ruby", "code", "to", "the", "+", "result", "+", "string", "and", "return", "it", ".", "At", "the", "moment", "this", "method", "only", "supports", "method", "signatures", "with", "generic", "argument", "names", "." ]
528f250f84a46b0f3e6fccf06430ed413c7d994c
https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L31-L43
1,626
flori/protocol
lib/protocol/protocol_module.rb
Protocol.ProtocolModule.understand?
def understand?(name, arity = nil) name = name.to_s !!find { |m| m.name == name && (!arity || m.arity == arity) } end
ruby
def understand?(name, arity = nil) name = name.to_s !!find { |m| m.name == name && (!arity || m.arity == arity) } end
[ "def", "understand?", "(", "name", ",", "arity", "=", "nil", ")", "name", "=", "name", ".", "to_s", "!", "!", "find", "{", "|", "m", "|", "m", ".", "name", "==", "name", "&&", "(", "!", "arity", "||", "m", ".", "arity", "==", "arity", ")", "}", "end" ]
Returns true if it is required to understand the
[ "Returns", "true", "if", "it", "is", "required", "to", "understand", "the" ]
528f250f84a46b0f3e6fccf06430ed413c7d994c
https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L75-L78
1,627
flori/protocol
lib/protocol/protocol_module.rb
Protocol.ProtocolModule.check_failures
def check_failures(object) check object rescue CheckFailed => e return e.errors.map { |e| e.protocol_message } end
ruby
def check_failures(object) check object rescue CheckFailed => e return e.errors.map { |e| e.protocol_message } end
[ "def", "check_failures", "(", "object", ")", "check", "object", "rescue", "CheckFailed", "=>", "e", "return", "e", ".", "errors", ".", "map", "{", "|", "e", "|", "e", ".", "protocol_message", "}", "end" ]
Return all messages for whick a check failed.
[ "Return", "all", "messages", "for", "whick", "a", "check", "failed", "." ]
528f250f84a46b0f3e6fccf06430ed413c7d994c
https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L161-L165
1,628
flori/protocol
lib/protocol/protocol_module.rb
Protocol.ProtocolModule.inherit
def inherit(modul, methodname, block_expected = nil) Module === modul or raise TypeError, "expected Module not #{modul.class} as modul argument" methodnames = methodname.respond_to?(:to_ary) ? methodname.to_ary : [ methodname ] methodnames.each do |methodname| m = parse_instance_method_signature(modul, methodname) block_expected and m.block_expected = block_expected @descriptor.add_message m end self end
ruby
def inherit(modul, methodname, block_expected = nil) Module === modul or raise TypeError, "expected Module not #{modul.class} as modul argument" methodnames = methodname.respond_to?(:to_ary) ? methodname.to_ary : [ methodname ] methodnames.each do |methodname| m = parse_instance_method_signature(modul, methodname) block_expected and m.block_expected = block_expected @descriptor.add_message m end self end
[ "def", "inherit", "(", "modul", ",", "methodname", ",", "block_expected", "=", "nil", ")", "Module", "===", "modul", "or", "raise", "TypeError", ",", "\"expected Module not #{modul.class} as modul argument\"", "methodnames", "=", "methodname", ".", "respond_to?", "(", ":to_ary", ")", "?", "methodname", ".", "to_ary", ":", "[", "methodname", "]", "methodnames", ".", "each", "do", "|", "methodname", "|", "m", "=", "parse_instance_method_signature", "(", "modul", ",", "methodname", ")", "block_expected", "and", "m", ".", "block_expected", "=", "block_expected", "@descriptor", ".", "add_message", "m", "end", "self", "end" ]
Inherit a method signature from an instance method named +methodname+ of +modul+. This means that this protocol should understand these instance methods with their arity and block expectation. Note that automatic detection of blocks does not work for Ruby methods defined in C. You can set the +block_expected+ argument if you want to do this manually.
[ "Inherit", "a", "method", "signature", "from", "an", "instance", "method", "named", "+", "methodname", "+", "of", "+", "modul", "+", ".", "This", "means", "that", "this", "protocol", "should", "understand", "these", "instance", "methods", "with", "their", "arity", "and", "block", "expectation", ".", "Note", "that", "automatic", "detection", "of", "blocks", "does", "not", "work", "for", "Ruby", "methods", "defined", "in", "C", ".", "You", "can", "set", "the", "+", "block_expected", "+", "argument", "if", "you", "want", "to", "do", "this", "manually", "." ]
528f250f84a46b0f3e6fccf06430ed413c7d994c
https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L234-L246
1,629
flori/protocol
lib/protocol/protocol_module.rb
Protocol.ProtocolModule.method_added
def method_added(methodname) methodname = methodname.to_s if specification? and methodname !~ /^__protocol_check_/ protocol_check = instance_method(methodname) parser = MethodParser.new(self, methodname) if parser.complex? define_method("__protocol_check_#{methodname}", protocol_check) understand methodname, protocol_check.arity, parser.block_arg? else understand methodname, protocol_check.arity, parser.block_arg? end remove_method methodname else super end end
ruby
def method_added(methodname) methodname = methodname.to_s if specification? and methodname !~ /^__protocol_check_/ protocol_check = instance_method(methodname) parser = MethodParser.new(self, methodname) if parser.complex? define_method("__protocol_check_#{methodname}", protocol_check) understand methodname, protocol_check.arity, parser.block_arg? else understand methodname, protocol_check.arity, parser.block_arg? end remove_method methodname else super end end
[ "def", "method_added", "(", "methodname", ")", "methodname", "=", "methodname", ".", "to_s", "if", "specification?", "and", "methodname", "!~", "/", "/", "protocol_check", "=", "instance_method", "(", "methodname", ")", "parser", "=", "MethodParser", ".", "new", "(", "self", ",", "methodname", ")", "if", "parser", ".", "complex?", "define_method", "(", "\"__protocol_check_#{methodname}\"", ",", "protocol_check", ")", "understand", "methodname", ",", "protocol_check", ".", "arity", ",", "parser", ".", "block_arg?", "else", "understand", "methodname", ",", "protocol_check", ".", "arity", ",", "parser", ".", "block_arg?", "end", "remove_method", "methodname", "else", "super", "end", "end" ]
Capture all added methods and either leave the implementation in place or add them to the protocol description.
[ "Capture", "all", "added", "methods", "and", "either", "leave", "the", "implementation", "in", "place", "or", "add", "them", "to", "the", "protocol", "description", "." ]
528f250f84a46b0f3e6fccf06430ed413c7d994c
https://github.com/flori/protocol/blob/528f250f84a46b0f3e6fccf06430ed413c7d994c/lib/protocol/protocol_module.rb#L274-L289
1,630
paddor/cztop
lib/cztop/actor.rb
CZTop.Actor.<<
def <<(message) message = Message.coerce(message) if TERM == message[0] # NOTE: can't just send this to the actor. The sender might call # #terminate immediately, which most likely causes a hang due to race # conditions. terminate else begin @mtx.synchronize do raise DeadActorError if not @running message.send_to(self) end rescue IO::EAGAINWaitWritable # The sndtimeo has been reached. # # This should fix the race condition (mainly on JRuby) between # @running not being set to false yet but the actor handler already # terminating and thus not able to receive messages anymore. # # This shouldn't result in an infinite loop, since it'll stop as # soon as @running is set to false by #signal_shimmed_handler_death, # at least when using a Ruby handler. # # In case of a C function handler, it MUST NOT crash and only # terminate when being sent the "$TERM" message using #terminate (so # #await_handler_death can set # @running to false). retry end end self end
ruby
def <<(message) message = Message.coerce(message) if TERM == message[0] # NOTE: can't just send this to the actor. The sender might call # #terminate immediately, which most likely causes a hang due to race # conditions. terminate else begin @mtx.synchronize do raise DeadActorError if not @running message.send_to(self) end rescue IO::EAGAINWaitWritable # The sndtimeo has been reached. # # This should fix the race condition (mainly on JRuby) between # @running not being set to false yet but the actor handler already # terminating and thus not able to receive messages anymore. # # This shouldn't result in an infinite loop, since it'll stop as # soon as @running is set to false by #signal_shimmed_handler_death, # at least when using a Ruby handler. # # In case of a C function handler, it MUST NOT crash and only # terminate when being sent the "$TERM" message using #terminate (so # #await_handler_death can set # @running to false). retry end end self end
[ "def", "<<", "(", "message", ")", "message", "=", "Message", ".", "coerce", "(", "message", ")", "if", "TERM", "==", "message", "[", "0", "]", "# NOTE: can't just send this to the actor. The sender might call", "# #terminate immediately, which most likely causes a hang due to race", "# conditions.", "terminate", "else", "begin", "@mtx", ".", "synchronize", "do", "raise", "DeadActorError", "if", "not", "@running", "message", ".", "send_to", "(", "self", ")", "end", "rescue", "IO", "::", "EAGAINWaitWritable", "# The sndtimeo has been reached.", "#", "# This should fix the race condition (mainly on JRuby) between", "# @running not being set to false yet but the actor handler already", "# terminating and thus not able to receive messages anymore.", "#", "# This shouldn't result in an infinite loop, since it'll stop as", "# soon as @running is set to false by #signal_shimmed_handler_death,", "# at least when using a Ruby handler.", "#", "# In case of a C function handler, it MUST NOT crash and only", "# terminate when being sent the \"$TERM\" message using #terminate (so", "# #await_handler_death can set", "# @running to false).", "retry", "end", "end", "self", "end" ]
Creates a new actor. Either pass a callback directly or a block. The block will be called for every received message. In case the given callback is an FFI::Pointer (to a C function), it's used as-is. It is expected to do the handshake (signal) itself. @param callback [FFI::Pointer, Proc, #call] pointer to a C function or just anything callable @param c_args [FFI::Pointer, nil] args, only useful if callback is an FFI::Pointer @yieldparam message [Message] @yieldparam pipe [Socket::PAIR] @see #process_messages Send a message to the actor. @param message [Object] message to send to the actor, see {Message.coerce} @return [self] so it's chainable @raise [DeadActorError] if actor is terminated @raise [IO::EAGAINWaitWritable, RuntimeError] anything that could be raised by {Message#send_to} @note Normally this method is asynchronous, but if the message is "$TERM", it blocks until the actor is terminated.
[ "Creates", "a", "new", "actor", ".", "Either", "pass", "a", "callback", "directly", "or", "a", "block", ".", "The", "block", "will", "be", "called", "for", "every", "received", "message", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/actor.rb#L80-L113
1,631
paddor/cztop
lib/cztop/actor.rb
CZTop.Actor.send_picture
def send_picture(picture, *args) @mtx.synchronize do raise DeadActorError if not @running Zsock.send(ffi_delegate, picture, *args) end end
ruby
def send_picture(picture, *args) @mtx.synchronize do raise DeadActorError if not @running Zsock.send(ffi_delegate, picture, *args) end end
[ "def", "send_picture", "(", "picture", ",", "*", "args", ")", "@mtx", ".", "synchronize", "do", "raise", "DeadActorError", "if", "not", "@running", "Zsock", ".", "send", "(", "ffi_delegate", ",", "picture", ",", "args", ")", "end", "end" ]
Sends a message according to a "picture". @see zsock_send() on http://api.zeromq.org/czmq3-0:zsock @note Mainly added for {Beacon}. If implemented there, it wouldn't be thread safe. And it's not that useful to be added to {SendReceiveMethods}. @param picture [String] message's part types @param args [String, Integer, ...] values, in FFI style (each one preceeded with it's type, like <tt>:string, "foo"</tt>) @return [void]
[ "Sends", "a", "message", "according", "to", "a", "picture", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/actor.rb#L152-L157
1,632
paddor/cztop
lib/cztop/actor.rb
CZTop.Actor.terminate
def terminate @mtx.synchronize do return false if not @running Message.new(TERM).send_to(self) await_handler_death true end rescue IO::EAGAINWaitWritable # same as in #<< retry end
ruby
def terminate @mtx.synchronize do return false if not @running Message.new(TERM).send_to(self) await_handler_death true end rescue IO::EAGAINWaitWritable # same as in #<< retry end
[ "def", "terminate", "@mtx", ".", "synchronize", "do", "return", "false", "if", "not", "@running", "Message", ".", "new", "(", "TERM", ")", ".", "send_to", "(", "self", ")", "await_handler_death", "true", "end", "rescue", "IO", "::", "EAGAINWaitWritable", "# same as in #<<", "retry", "end" ]
Tells the actor to terminate and waits for it. Idempotent. @return [Boolean] whether it died just now (+false+ if it was dead already)
[ "Tells", "the", "actor", "to", "terminate", "and", "waits", "for", "it", ".", "Idempotent", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/actor.rb#L170-L180
1,633
masciugo/genealogy
lib/genealogy/query_methods.rb
Genealogy.QueryMethods.ancestors
def ancestors(options = {}) ids = [] if options[:generations] raise ArgumentError, ":generations option must be an Integer" unless options[:generations].is_a? Integer generation_count = 0 generation_ids = parents.compact.map(&:id) while (generation_count < options[:generations]) && (generation_ids.length > 0) next_gen_ids = [] ids += generation_ids until generation_ids.empty? ids.unshift(generation_ids.shift) next_gen_ids += gclass.find(ids.first).parents.compact.map(&:id) end generation_ids = next_gen_ids generation_count += 1 end else remaining_ids = parents.compact.map(&:id) until remaining_ids.empty? ids << remaining_ids.shift remaining_ids += gclass.find(ids.last).parents.compact.map(&:id) end end gclass.where(id: ids) end
ruby
def ancestors(options = {}) ids = [] if options[:generations] raise ArgumentError, ":generations option must be an Integer" unless options[:generations].is_a? Integer generation_count = 0 generation_ids = parents.compact.map(&:id) while (generation_count < options[:generations]) && (generation_ids.length > 0) next_gen_ids = [] ids += generation_ids until generation_ids.empty? ids.unshift(generation_ids.shift) next_gen_ids += gclass.find(ids.first).parents.compact.map(&:id) end generation_ids = next_gen_ids generation_count += 1 end else remaining_ids = parents.compact.map(&:id) until remaining_ids.empty? ids << remaining_ids.shift remaining_ids += gclass.find(ids.last).parents.compact.map(&:id) end end gclass.where(id: ids) end
[ "def", "ancestors", "(", "options", "=", "{", "}", ")", "ids", "=", "[", "]", "if", "options", "[", ":generations", "]", "raise", "ArgumentError", ",", "\":generations option must be an Integer\"", "unless", "options", "[", ":generations", "]", ".", "is_a?", "Integer", "generation_count", "=", "0", "generation_ids", "=", "parents", ".", "compact", ".", "map", "(", ":id", ")", "while", "(", "generation_count", "<", "options", "[", ":generations", "]", ")", "&&", "(", "generation_ids", ".", "length", ">", "0", ")", "next_gen_ids", "=", "[", "]", "ids", "+=", "generation_ids", "until", "generation_ids", ".", "empty?", "ids", ".", "unshift", "(", "generation_ids", ".", "shift", ")", "next_gen_ids", "+=", "gclass", ".", "find", "(", "ids", ".", "first", ")", ".", "parents", ".", "compact", ".", "map", "(", ":id", ")", "end", "generation_ids", "=", "next_gen_ids", "generation_count", "+=", "1", "end", "else", "remaining_ids", "=", "parents", ".", "compact", ".", "map", "(", ":id", ")", "until", "remaining_ids", ".", "empty?", "ids", "<<", "remaining_ids", ".", "shift", "remaining_ids", "+=", "gclass", ".", "find", "(", "ids", ".", "last", ")", ".", "parents", ".", "compact", ".", "map", "(", ":id", ")", "end", "end", "gclass", ".", "where", "(", "id", ":", "ids", ")", "end" ]
get list of known ancestrors iterateing over parents @param [Hash] options @option options [Symbol] generations lets you limit how many generations will be included in the output. @return [ActiveRecord::Relation] list of ancestors (limited by a number of generations if so indicated)
[ "get", "list", "of", "known", "ancestrors", "iterateing", "over", "parents" ]
e29eeb1d63cd352d52abf1819ec21659364f90a7
https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/query_methods.rb#L133-L157
1,634
masciugo/genealogy
lib/genealogy/query_methods.rb
Genealogy.QueryMethods.descendants
def descendants(options = {}) ids = [] if options[:generations] generation_count = 0 generation_ids = children.map(&:id) while (generation_count < options[:generations]) && (generation_ids.length > 0) next_gen_ids = [] ids += generation_ids until generation_ids.empty? ids.unshift(generation_ids.shift) next_gen_ids += gclass.find(ids.first).children.map(&:id) end generation_ids = next_gen_ids generation_count += 1 end else remaining_ids = children.map(&:id) until remaining_ids.empty? ids << remaining_ids.shift remaining_ids += gclass.find(ids.last).children.pluck(:id) # break if (remaining_ids - ids).empty? can be necessary in case of loop. Idem for ancestors method end end gclass.where(id: ids) end
ruby
def descendants(options = {}) ids = [] if options[:generations] generation_count = 0 generation_ids = children.map(&:id) while (generation_count < options[:generations]) && (generation_ids.length > 0) next_gen_ids = [] ids += generation_ids until generation_ids.empty? ids.unshift(generation_ids.shift) next_gen_ids += gclass.find(ids.first).children.map(&:id) end generation_ids = next_gen_ids generation_count += 1 end else remaining_ids = children.map(&:id) until remaining_ids.empty? ids << remaining_ids.shift remaining_ids += gclass.find(ids.last).children.pluck(:id) # break if (remaining_ids - ids).empty? can be necessary in case of loop. Idem for ancestors method end end gclass.where(id: ids) end
[ "def", "descendants", "(", "options", "=", "{", "}", ")", "ids", "=", "[", "]", "if", "options", "[", ":generations", "]", "generation_count", "=", "0", "generation_ids", "=", "children", ".", "map", "(", ":id", ")", "while", "(", "generation_count", "<", "options", "[", ":generations", "]", ")", "&&", "(", "generation_ids", ".", "length", ">", "0", ")", "next_gen_ids", "=", "[", "]", "ids", "+=", "generation_ids", "until", "generation_ids", ".", "empty?", "ids", ".", "unshift", "(", "generation_ids", ".", "shift", ")", "next_gen_ids", "+=", "gclass", ".", "find", "(", "ids", ".", "first", ")", ".", "children", ".", "map", "(", ":id", ")", "end", "generation_ids", "=", "next_gen_ids", "generation_count", "+=", "1", "end", "else", "remaining_ids", "=", "children", ".", "map", "(", ":id", ")", "until", "remaining_ids", ".", "empty?", "ids", "<<", "remaining_ids", ".", "shift", "remaining_ids", "+=", "gclass", ".", "find", "(", "ids", ".", "last", ")", ".", "children", ".", "pluck", "(", ":id", ")", "# break if (remaining_ids - ids).empty? can be necessary in case of loop. Idem for ancestors method", "end", "end", "gclass", ".", "where", "(", "id", ":", "ids", ")", "end" ]
get list of known descendants iterateing over children ... @param [Hash] options @option options [Symbol] generations lets you limit how many generations will be included in the output. @return [ActiveRecord::Relation] list of descendants (limited by a number of generations if so indicated)
[ "get", "list", "of", "known", "descendants", "iterateing", "over", "children", "..." ]
e29eeb1d63cd352d52abf1819ec21659364f90a7
https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/query_methods.rb#L164-L188
1,635
masciugo/genealogy
lib/genealogy/query_methods.rb
Genealogy.QueryMethods.uncles_and_aunts
def uncles_and_aunts(options={}) relation = case options[:lineage] when :paternal [father] when :maternal [mother] else parents end ids = relation.compact.inject([]){|memo,parent| memo |= parent.siblings(half: options[:half]).pluck(:id)} gclass.where(id: ids) end
ruby
def uncles_and_aunts(options={}) relation = case options[:lineage] when :paternal [father] when :maternal [mother] else parents end ids = relation.compact.inject([]){|memo,parent| memo |= parent.siblings(half: options[:half]).pluck(:id)} gclass.where(id: ids) end
[ "def", "uncles_and_aunts", "(", "options", "=", "{", "}", ")", "relation", "=", "case", "options", "[", ":lineage", "]", "when", ":paternal", "[", "father", "]", "when", ":maternal", "[", "mother", "]", "else", "parents", "end", "ids", "=", "relation", ".", "compact", ".", "inject", "(", "[", "]", ")", "{", "|", "memo", ",", "parent", "|", "memo", "|=", "parent", ".", "siblings", "(", "half", ":", "options", "[", ":half", "]", ")", ".", "pluck", "(", ":id", ")", "}", "gclass", ".", "where", "(", "id", ":", "ids", ")", "end" ]
list of uncles and aunts iterating through parents' siblings @param [Hash] options @option options [Symbol] lineage to filter by lineage: :paternal or :maternal @option options [Symbol] half to filter by half siblings (see #siblings) @return [ActiveRecord::Relation] list of uncles and aunts
[ "list", "of", "uncles", "and", "aunts", "iterating", "through", "parents", "siblings" ]
e29eeb1d63cd352d52abf1819ec21659364f90a7
https://github.com/masciugo/genealogy/blob/e29eeb1d63cd352d52abf1819ec21659364f90a7/lib/genealogy/query_methods.rb#L205-L216
1,636
paddor/cztop
lib/cztop/poller.rb
CZTop.Poller.modify
def modify(socket, events) ptr = ptr_for_socket(socket) rc = ZMQ.poller_modify(@poller_ptr, ptr, events) HasFFIDelegate.raise_zmq_err if rc == -1 remember_socket(socket, events) end
ruby
def modify(socket, events) ptr = ptr_for_socket(socket) rc = ZMQ.poller_modify(@poller_ptr, ptr, events) HasFFIDelegate.raise_zmq_err if rc == -1 remember_socket(socket, events) end
[ "def", "modify", "(", "socket", ",", "events", ")", "ptr", "=", "ptr_for_socket", "(", "socket", ")", "rc", "=", "ZMQ", ".", "poller_modify", "(", "@poller_ptr", ",", "ptr", ",", "events", ")", "HasFFIDelegate", ".", "raise_zmq_err", "if", "rc", "==", "-", "1", "remember_socket", "(", "socket", ",", "events", ")", "end" ]
Modifies the events of interest for the given socket. @param socket [Socket, Actor] the socket @param events [Integer] events you're interested in (see constants in {ZMQ} @return [void] @raise [ArgumentError] if it's not a socket
[ "Modifies", "the", "events", "of", "interest", "for", "the", "given", "socket", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L62-L67
1,637
paddor/cztop
lib/cztop/poller.rb
CZTop.Poller.remove
def remove(socket) ptr = ptr_for_socket(socket) rc = ZMQ.poller_remove(@poller_ptr, ptr) HasFFIDelegate.raise_zmq_err if rc == -1 forget_socket(socket) end
ruby
def remove(socket) ptr = ptr_for_socket(socket) rc = ZMQ.poller_remove(@poller_ptr, ptr) HasFFIDelegate.raise_zmq_err if rc == -1 forget_socket(socket) end
[ "def", "remove", "(", "socket", ")", "ptr", "=", "ptr_for_socket", "(", "socket", ")", "rc", "=", "ZMQ", ".", "poller_remove", "(", "@poller_ptr", ",", "ptr", ")", "HasFFIDelegate", ".", "raise_zmq_err", "if", "rc", "==", "-", "1", "forget_socket", "(", "socket", ")", "end" ]
Removes a previously registered socket. Won't raise if you're trying to remove a socket that's not registered. @param socket [Socket, Actor] the socket @return [void] @raise [ArgumentError] if it's not a socket
[ "Removes", "a", "previously", "registered", "socket", ".", "Won", "t", "raise", "if", "you", "re", "trying", "to", "remove", "a", "socket", "that", "s", "not", "registered", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L74-L79
1,638
paddor/cztop
lib/cztop/poller.rb
CZTop.Poller.remove_reader
def remove_reader(socket) if event_mask_for_socket(socket) == ZMQ::POLLIN remove(socket) return end raise ArgumentError, "not registered for readability only: %p" % socket end
ruby
def remove_reader(socket) if event_mask_for_socket(socket) == ZMQ::POLLIN remove(socket) return end raise ArgumentError, "not registered for readability only: %p" % socket end
[ "def", "remove_reader", "(", "socket", ")", "if", "event_mask_for_socket", "(", "socket", ")", "==", "ZMQ", "::", "POLLIN", "remove", "(", "socket", ")", "return", "end", "raise", "ArgumentError", ",", "\"not registered for readability only: %p\"", "%", "socket", "end" ]
Removes a reader socket that was registered for readability only. @param socket [Socket, Actor] the socket @raise [ArgumentError] if it's not registered, not registered for readability, or registered for more than just readability
[ "Removes", "a", "reader", "socket", "that", "was", "registered", "for", "readability", "only", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L86-L92
1,639
paddor/cztop
lib/cztop/poller.rb
CZTop.Poller.remove_writer
def remove_writer(socket) if event_mask_for_socket(socket) == ZMQ::POLLOUT remove(socket) return end raise ArgumentError, "not registered for writability only: %p" % socket end
ruby
def remove_writer(socket) if event_mask_for_socket(socket) == ZMQ::POLLOUT remove(socket) return end raise ArgumentError, "not registered for writability only: %p" % socket end
[ "def", "remove_writer", "(", "socket", ")", "if", "event_mask_for_socket", "(", "socket", ")", "==", "ZMQ", "::", "POLLOUT", "remove", "(", "socket", ")", "return", "end", "raise", "ArgumentError", ",", "\"not registered for writability only: %p\"", "%", "socket", "end" ]
Removes a reader socket that was registered for writability only. @param socket [Socket, Actor] the socket @raise [ArgumentError] if it's not registered, not registered for writability, or registered for more than just writability
[ "Removes", "a", "reader", "socket", "that", "was", "registered", "for", "writability", "only", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L99-L105
1,640
paddor/cztop
lib/cztop/poller.rb
CZTop.Poller.wait
def wait(timeout = -1) rc = ZMQ.poller_wait(@poller_ptr, @event_ptr, timeout) if rc == -1 case CZMQ::FFI::Errors.errno # NOTE: ETIMEDOUT for backwards compatibility, although this API is # still DRAFT. when Errno::EAGAIN::Errno, Errno::ETIMEDOUT::Errno return nil else HasFFIDelegate.raise_zmq_err end end return Event.new(self, @event_ptr) end
ruby
def wait(timeout = -1) rc = ZMQ.poller_wait(@poller_ptr, @event_ptr, timeout) if rc == -1 case CZMQ::FFI::Errors.errno # NOTE: ETIMEDOUT for backwards compatibility, although this API is # still DRAFT. when Errno::EAGAIN::Errno, Errno::ETIMEDOUT::Errno return nil else HasFFIDelegate.raise_zmq_err end end return Event.new(self, @event_ptr) end
[ "def", "wait", "(", "timeout", "=", "-", "1", ")", "rc", "=", "ZMQ", ".", "poller_wait", "(", "@poller_ptr", ",", "@event_ptr", ",", "timeout", ")", "if", "rc", "==", "-", "1", "case", "CZMQ", "::", "FFI", "::", "Errors", ".", "errno", "# NOTE: ETIMEDOUT for backwards compatibility, although this API is", "# still DRAFT.", "when", "Errno", "::", "EAGAIN", "::", "Errno", ",", "Errno", "::", "ETIMEDOUT", "::", "Errno", "return", "nil", "else", "HasFFIDelegate", ".", "raise_zmq_err", "end", "end", "return", "Event", ".", "new", "(", "self", ",", "@event_ptr", ")", "end" ]
Waits for registered sockets to become readable or writable, depending on what you're interested in. @param timeout [Integer] how long to wait in ms, or 0 to avoid blocking, or -1 to wait indefinitely @return [Event] the first event of interest @return [nil] if the timeout expired or @raise [SystemCallError] if this failed
[ "Waits", "for", "registered", "sockets", "to", "become", "readable", "or", "writable", "depending", "on", "what", "you", "re", "interested", "in", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/poller.rb#L115-L128
1,641
hawkular/hawkular-client-ruby
lib/hawkular/operations/operations_api.rb
Hawkular::Operations.Client.invoke_specific_operation
def invoke_specific_operation(operation_payload, operation_name, &callback) fail Hawkular::ArgumentError, 'Operation must be specified' if operation_name.nil? required = %i[resourceId feedId] check_pre_conditions operation_payload, required, &callback invoke_operation_helper(operation_payload, operation_name, &callback) end
ruby
def invoke_specific_operation(operation_payload, operation_name, &callback) fail Hawkular::ArgumentError, 'Operation must be specified' if operation_name.nil? required = %i[resourceId feedId] check_pre_conditions operation_payload, required, &callback invoke_operation_helper(operation_payload, operation_name, &callback) end
[ "def", "invoke_specific_operation", "(", "operation_payload", ",", "operation_name", ",", "&", "callback", ")", "fail", "Hawkular", "::", "ArgumentError", ",", "'Operation must be specified'", "if", "operation_name", ".", "nil?", "required", "=", "%i[", "resourceId", "feedId", "]", "check_pre_conditions", "operation_payload", ",", "required", ",", "callback", "invoke_operation_helper", "(", "operation_payload", ",", "operation_name", ",", "callback", ")", "end" ]
Invokes operation on the WildFly agent that has it's own message type @param operation_payload [Hash{String=>Object}] a hash containing: resourceId [String] denoting the resource on which the operation is about to run, feedId [String] @param operation_name [String] the name of the operation. This must correspond with the message type, they can be found here https://git.io/v2h1a (Use only the first part of the name without the Request/Response suffix), e.g. RemoveDatasource (and not RemoveDatasourceRequest) @param callback [Block] callback that is run after the operation is done
[ "Invokes", "operation", "on", "the", "WildFly", "agent", "that", "has", "it", "s", "own", "message", "type" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L169-L175
1,642
hawkular/hawkular-client-ruby
lib/hawkular/operations/operations_api.rb
Hawkular::Operations.Client.add_deployment
def add_deployment(hash, &callback) hash[:enabled] = hash.key?(:enabled) ? hash[:enabled] : true hash[:force_deploy] = hash.key?(:force_deploy) ? hash[:force_deploy] : false required = %i[resource_id feed_id destination_file_name binary_content] check_pre_conditions hash, required, &callback operation_payload = prepare_payload_hash([:binary_content], hash) invoke_operation_helper(operation_payload, 'DeployApplication', hash[:binary_content], &callback) end
ruby
def add_deployment(hash, &callback) hash[:enabled] = hash.key?(:enabled) ? hash[:enabled] : true hash[:force_deploy] = hash.key?(:force_deploy) ? hash[:force_deploy] : false required = %i[resource_id feed_id destination_file_name binary_content] check_pre_conditions hash, required, &callback operation_payload = prepare_payload_hash([:binary_content], hash) invoke_operation_helper(operation_payload, 'DeployApplication', hash[:binary_content], &callback) end
[ "def", "add_deployment", "(", "hash", ",", "&", "callback", ")", "hash", "[", ":enabled", "]", "=", "hash", ".", "key?", "(", ":enabled", ")", "?", "hash", "[", ":enabled", "]", ":", "true", "hash", "[", ":force_deploy", "]", "=", "hash", ".", "key?", "(", ":force_deploy", ")", "?", "hash", "[", ":force_deploy", "]", ":", "false", "required", "=", "%i[", "resource_id", "feed_id", "destination_file_name", "binary_content", "]", "check_pre_conditions", "hash", ",", "required", ",", "callback", "operation_payload", "=", "prepare_payload_hash", "(", "[", ":binary_content", "]", ",", "hash", ")", "invoke_operation_helper", "(", "operation_payload", ",", "'DeployApplication'", ",", "hash", "[", ":binary_content", "]", ",", "callback", ")", "end" ]
Deploys an archive file into WildFly @param [Hash] hash Arguments for deployment @option hash [String] :resource_id ID of the WildFly server into which we deploy or of the domain controller if we deploy into a server group (in case of domain mode) @option hash [String] :feed_id feed containing this resource @option hash [String] :destination_file_name resulting file name @option hash [String] :binary_content binary content representing the war file @option hash [String] :enabled whether the deployment should be enabled immediately, or not (default = true) @option hash [String] :force_deploy whether to replace existing content or not (default = false) @option hash [String] :server_groups comma-separated list of server groups for the operation (default = ignored) @param callback [Block] callback that is run after the operation is done
[ "Deploys", "an", "archive", "file", "into", "WildFly" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L190-L198
1,643
hawkular/hawkular-client-ruby
lib/hawkular/operations/operations_api.rb
Hawkular::Operations.Client.undeploy
def undeploy(hash, &callback) hash[:remove_content] = hash.key?(:remove_content) ? hash[:remove_content] : true required = %i[resource_id feed_id deployment_name] check_pre_conditions hash, required, &callback hash[:destination_file_name] = hash[:deployment_name] operation_payload = prepare_payload_hash([:deployment_name], hash) invoke_operation_helper(operation_payload, 'UndeployApplication', &callback) end
ruby
def undeploy(hash, &callback) hash[:remove_content] = hash.key?(:remove_content) ? hash[:remove_content] : true required = %i[resource_id feed_id deployment_name] check_pre_conditions hash, required, &callback hash[:destination_file_name] = hash[:deployment_name] operation_payload = prepare_payload_hash([:deployment_name], hash) invoke_operation_helper(operation_payload, 'UndeployApplication', &callback) end
[ "def", "undeploy", "(", "hash", ",", "&", "callback", ")", "hash", "[", ":remove_content", "]", "=", "hash", ".", "key?", "(", ":remove_content", ")", "?", "hash", "[", ":remove_content", "]", ":", "true", "required", "=", "%i[", "resource_id", "feed_id", "deployment_name", "]", "check_pre_conditions", "hash", ",", "required", ",", "callback", "hash", "[", ":destination_file_name", "]", "=", "hash", "[", ":deployment_name", "]", "operation_payload", "=", "prepare_payload_hash", "(", "[", ":deployment_name", "]", ",", "hash", ")", "invoke_operation_helper", "(", "operation_payload", ",", "'UndeployApplication'", ",", "callback", ")", "end" ]
Undeploy a WildFly deployment @param [Hash] hash Arguments for deployment removal @option hash [String] :resource_id ID of the WildFly server from which to undeploy the deployment @option hash [String] :feed_id feed containing this resource @option hash [String] :deployment_name name of deployment to undeploy @option hash [String] :remove_content whether to remove the deployment content or not (default = true) @option hash [String] :server_groups comma-separated list of server groups for the operation (default = ignored) @param callback [Block] callback that is run after the operation is done
[ "Undeploy", "a", "WildFly", "deployment" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L210-L219
1,644
hawkular/hawkular-client-ruby
lib/hawkular/operations/operations_api.rb
Hawkular::Operations.Client.enable_deployment
def enable_deployment(hash, &callback) required = %i[resource_id feed_id deployment_name] check_pre_conditions hash, required, &callback hash[:destination_file_name] = hash[:deployment_name] operation_payload = prepare_payload_hash([:deployment_name], hash) invoke_operation_helper(operation_payload, 'EnableApplication', &callback) end
ruby
def enable_deployment(hash, &callback) required = %i[resource_id feed_id deployment_name] check_pre_conditions hash, required, &callback hash[:destination_file_name] = hash[:deployment_name] operation_payload = prepare_payload_hash([:deployment_name], hash) invoke_operation_helper(operation_payload, 'EnableApplication', &callback) end
[ "def", "enable_deployment", "(", "hash", ",", "&", "callback", ")", "required", "=", "%i[", "resource_id", "feed_id", "deployment_name", "]", "check_pre_conditions", "hash", ",", "required", ",", "callback", "hash", "[", ":destination_file_name", "]", "=", "hash", "[", ":deployment_name", "]", "operation_payload", "=", "prepare_payload_hash", "(", "[", ":deployment_name", "]", ",", "hash", ")", "invoke_operation_helper", "(", "operation_payload", ",", "'EnableApplication'", ",", "callback", ")", "end" ]
Enable a WildFly deployment @param [Hash] hash Arguments for enable deployment @option hash [String] :resource_id ID of the WildFly server from which to enable the deployment @option hash [String] :feed_id feed containing this resource @option hash [String] :deployment_name name of deployment to enable @option hash [String] :server_groups comma-separated list of server groups for the operation (default = ignored) @param callback [Block] callback that is run after the operation is done
[ "Enable", "a", "WildFly", "deployment" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L230-L238
1,645
hawkular/hawkular-client-ruby
lib/hawkular/operations/operations_api.rb
Hawkular::Operations.Client.export_jdr
def export_jdr(resource_id, feed_id, delete_immediately = false, sender_request_id = nil, &callback) fail Hawkular::ArgumentError, 'resource_id must be specified' if resource_id.nil? fail Hawkular::ArgumentError, 'feed_id must be specified' if feed_id.nil? check_pre_conditions(&callback) invoke_specific_operation({ resourceId: resource_id, feedId: feed_id, deleteImmediately: delete_immediately, senderRequestId: sender_request_id }, 'ExportJdr', &callback) end
ruby
def export_jdr(resource_id, feed_id, delete_immediately = false, sender_request_id = nil, &callback) fail Hawkular::ArgumentError, 'resource_id must be specified' if resource_id.nil? fail Hawkular::ArgumentError, 'feed_id must be specified' if feed_id.nil? check_pre_conditions(&callback) invoke_specific_operation({ resourceId: resource_id, feedId: feed_id, deleteImmediately: delete_immediately, senderRequestId: sender_request_id }, 'ExportJdr', &callback) end
[ "def", "export_jdr", "(", "resource_id", ",", "feed_id", ",", "delete_immediately", "=", "false", ",", "sender_request_id", "=", "nil", ",", "&", "callback", ")", "fail", "Hawkular", "::", "ArgumentError", ",", "'resource_id must be specified'", "if", "resource_id", ".", "nil?", "fail", "Hawkular", "::", "ArgumentError", ",", "'feed_id must be specified'", "if", "feed_id", ".", "nil?", "check_pre_conditions", "(", "callback", ")", "invoke_specific_operation", "(", "{", "resourceId", ":", "resource_id", ",", "feedId", ":", "feed_id", ",", "deleteImmediately", ":", "delete_immediately", ",", "senderRequestId", ":", "sender_request_id", "}", ",", "'ExportJdr'", ",", "callback", ")", "end" ]
Exports the JDR report @param [String] resource_id ID of the WildFly server @param [String] feed_id ID of the feed containing the WildFly server @param [Boolean] delete_immediately specifies whether the temporary file at the remote server should be deleted. False, by default. @param callback [Block] callback that is run after the operation is done
[ "Exports", "the", "JDR", "report" ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L330-L340
1,646
hawkular/hawkular-client-ruby
lib/hawkular/operations/operations_api.rb
Hawkular::Operations.Client.update_collection_intervals
def update_collection_intervals(hash, &callback) required = %i[resourceId feedId metricTypes availTypes] check_pre_conditions hash, required, &callback invoke_specific_operation(hash, 'UpdateCollectionIntervals', &callback) end
ruby
def update_collection_intervals(hash, &callback) required = %i[resourceId feedId metricTypes availTypes] check_pre_conditions hash, required, &callback invoke_specific_operation(hash, 'UpdateCollectionIntervals', &callback) end
[ "def", "update_collection_intervals", "(", "hash", ",", "&", "callback", ")", "required", "=", "%i[", "resourceId", "feedId", "metricTypes", "availTypes", "]", "check_pre_conditions", "hash", ",", "required", ",", "callback", "invoke_specific_operation", "(", "hash", ",", "'UpdateCollectionIntervals'", ",", "callback", ")", "end" ]
Updates the collection intervals. @param [Hash] hash Arguments for update collection intervals @option hash {resourceId} a resource managed by the target agent @option hash {feedId} the related feed ID @option hash {metricTypes} A map with key=MetricTypeId, value=interval (seconds). MetricTypeId must be of form MetricTypeSet~MetricTypeName @option hash {availTypes} A map with key=AvailTypeId, value=interval (seconds). AvailTypeId must be of form AvailTypeSet~AvailTypeName @param callback [Block] callback that is run after the operation is done
[ "Updates", "the", "collection", "intervals", "." ]
3b07729c2ab359e3199c282e199a3f1699ddc49c
https://github.com/hawkular/hawkular-client-ruby/blob/3b07729c2ab359e3199c282e199a3f1699ddc49c/lib/hawkular/operations/operations_api.rb#L353-L357
1,647
bfoz/geometry
lib/geometry/polyline.rb
Geometry.Polyline.close!
def close! unless @edges.empty? # NOTE: parallel? is use here instead of collinear? because the # edges are connected, and will therefore be collinear if # they're parallel if closed? if @edges.first.parallel?(@edges.last) unshift_edge Edge.new(@edges.last.first, shift_edge.last) end elsif closing_edge = Edge.new(@edges.last.last, @edges.first.first) # If the closing edge is collinear with the last edge, then # simply extened the last edge to fill the gap if @edges.last.parallel?(closing_edge) closing_edge = Edge.new(pop_edge.first, @edges.first.first) end # Check that the new closing_edge isn't zero-length if closing_edge.first != closing_edge.last # If the closing edge is collinear with the first edge, then # extend the first edge "backwards" to fill the gap if @edges.first.parallel?(closing_edge) unshift_edge Edge.new(closing_edge.first, shift_edge.last) else push_edge closing_edge end end end end self end
ruby
def close! unless @edges.empty? # NOTE: parallel? is use here instead of collinear? because the # edges are connected, and will therefore be collinear if # they're parallel if closed? if @edges.first.parallel?(@edges.last) unshift_edge Edge.new(@edges.last.first, shift_edge.last) end elsif closing_edge = Edge.new(@edges.last.last, @edges.first.first) # If the closing edge is collinear with the last edge, then # simply extened the last edge to fill the gap if @edges.last.parallel?(closing_edge) closing_edge = Edge.new(pop_edge.first, @edges.first.first) end # Check that the new closing_edge isn't zero-length if closing_edge.first != closing_edge.last # If the closing edge is collinear with the first edge, then # extend the first edge "backwards" to fill the gap if @edges.first.parallel?(closing_edge) unshift_edge Edge.new(closing_edge.first, shift_edge.last) else push_edge closing_edge end end end end self end
[ "def", "close!", "unless", "@edges", ".", "empty?", "# NOTE: parallel? is use here instead of collinear? because the", "#\tedges are connected, and will therefore be collinear if", "#\tthey're parallel", "if", "closed?", "if", "@edges", ".", "first", ".", "parallel?", "(", "@edges", ".", "last", ")", "unshift_edge", "Edge", ".", "new", "(", "@edges", ".", "last", ".", "first", ",", "shift_edge", ".", "last", ")", "end", "elsif", "closing_edge", "=", "Edge", ".", "new", "(", "@edges", ".", "last", ".", "last", ",", "@edges", ".", "first", ".", "first", ")", "# If the closing edge is collinear with the last edge, then", "# simply extened the last edge to fill the gap", "if", "@edges", ".", "last", ".", "parallel?", "(", "closing_edge", ")", "closing_edge", "=", "Edge", ".", "new", "(", "pop_edge", ".", "first", ",", "@edges", ".", "first", ".", "first", ")", "end", "# Check that the new closing_edge isn't zero-length", "if", "closing_edge", ".", "first", "!=", "closing_edge", ".", "last", "# If the closing edge is collinear with the first edge, then", "# extend the first edge \"backwards\" to fill the gap", "if", "@edges", ".", "first", ".", "parallel?", "(", "closing_edge", ")", "unshift_edge", "Edge", ".", "new", "(", "closing_edge", ".", "first", ",", "shift_edge", ".", "last", ")", "else", "push_edge", "closing_edge", "end", "end", "end", "end", "self", "end" ]
Close the receiver and return it @return [Polyline] the receiver after closing
[ "Close", "the", "receiver", "and", "return", "it" ]
3054ccba59f184c172be52a6f0b7cf4a33f617a5
https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L127-L159
1,648
bfoz/geometry
lib/geometry/polyline.rb
Geometry.Polyline.bisector_map
def bisector_map winding = 0 tangent_loop.each_cons(2).map do |v1,v2| k = v1[0]*v2[1] - v1[1]*v2[0] # z-component of v1 x v2 winding += k if v1 == v2 # collinear, same direction? bisector = Vector[-v1[1], v1[0]] block_given? ? (bisector * yield(bisector, 1)) : bisector elsif 0 == k # collinear, reverse direction nil else bisector_y = (v2[1] - v1[1])/k # If v1 or v2 happens to be horizontal, then the other one must be used when calculating # the x-component of the bisector (to avoid a divide by zero). But, comparing floats # with zero is problematic, so use the one with the largest y-component instead checking # for a y-component equal to zero. v = (v2[1].abs > v1[1].abs) ? v2 : v1 bisector = Vector[(v[0]*bisector_y - 1)/v[1], bisector_y] block_given? ? (bisector * yield(bisector, k)) : bisector end end end
ruby
def bisector_map winding = 0 tangent_loop.each_cons(2).map do |v1,v2| k = v1[0]*v2[1] - v1[1]*v2[0] # z-component of v1 x v2 winding += k if v1 == v2 # collinear, same direction? bisector = Vector[-v1[1], v1[0]] block_given? ? (bisector * yield(bisector, 1)) : bisector elsif 0 == k # collinear, reverse direction nil else bisector_y = (v2[1] - v1[1])/k # If v1 or v2 happens to be horizontal, then the other one must be used when calculating # the x-component of the bisector (to avoid a divide by zero). But, comparing floats # with zero is problematic, so use the one with the largest y-component instead checking # for a y-component equal to zero. v = (v2[1].abs > v1[1].abs) ? v2 : v1 bisector = Vector[(v[0]*bisector_y - 1)/v[1], bisector_y] block_given? ? (bisector * yield(bisector, k)) : bisector end end end
[ "def", "bisector_map", "winding", "=", "0", "tangent_loop", ".", "each_cons", "(", "2", ")", ".", "map", "do", "|", "v1", ",", "v2", "|", "k", "=", "v1", "[", "0", "]", "*", "v2", "[", "1", "]", "-", "v1", "[", "1", "]", "*", "v2", "[", "0", "]", "# z-component of v1 x v2", "winding", "+=", "k", "if", "v1", "==", "v2", "# collinear, same direction?", "bisector", "=", "Vector", "[", "-", "v1", "[", "1", "]", ",", "v1", "[", "0", "]", "]", "block_given?", "?", "(", "bisector", "*", "yield", "(", "bisector", ",", "1", ")", ")", ":", "bisector", "elsif", "0", "==", "k", "# collinear, reverse direction", "nil", "else", "bisector_y", "=", "(", "v2", "[", "1", "]", "-", "v1", "[", "1", "]", ")", "/", "k", "# If v1 or v2 happens to be horizontal, then the other one must be used when calculating", "# the x-component of the bisector (to avoid a divide by zero). But, comparing floats", "# with zero is problematic, so use the one with the largest y-component instead checking", "# for a y-component equal to zero.", "v", "=", "(", "v2", "[", "1", "]", ".", "abs", ">", "v1", "[", "1", "]", ".", "abs", ")", "?", "v2", ":", "v1", "bisector", "=", "Vector", "[", "(", "v", "[", "0", "]", "*", "bisector_y", "-", "1", ")", "/", "v", "[", "1", "]", ",", "bisector_y", "]", "block_given?", "?", "(", "bisector", "*", "yield", "(", "bisector", ",", "k", ")", ")", ":", "bisector", "end", "end", "end" ]
Generate bisectors and k values with an optional mapping block @note If the {Polyline} isn't closed (the normal case), then the first and last vertices will be given bisectors that are perpendicular to themselves. @return [Array<Vector>] the unit {Vector}s representing the angle bisector of each vertex
[ "Generate", "bisectors", "and", "k", "values", "with", "an", "optional", "mapping", "block" ]
3054ccba59f184c172be52a6f0b7cf4a33f617a5
https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L281-L304
1,649
bfoz/geometry
lib/geometry/polyline.rb
Geometry.Polyline.tangent_loop
def tangent_loop edges.map {|e| e.direction }.tap do |tangents| # Generating a bisector for each vertex requires an edge on both sides of each vertex. # Obviously, the first and last vertices each have only a single adjacent edge, unless the # Polyline happens to be closed (like a Polygon). When not closed, duplicate the # first and last direction vectors to fake the adjacent edges. This causes the first and last # edges to have bisectors that are perpendicular to themselves. if closed? # Prepend the last direction vector so that the last edge can be used to find the bisector for the first vertex tangents.unshift tangents.last else # Duplicate the first and last direction vectors to compensate for not having edges adjacent to the first and last vertices tangents.unshift(tangents.first) tangents.push(tangents.last) end end end
ruby
def tangent_loop edges.map {|e| e.direction }.tap do |tangents| # Generating a bisector for each vertex requires an edge on both sides of each vertex. # Obviously, the first and last vertices each have only a single adjacent edge, unless the # Polyline happens to be closed (like a Polygon). When not closed, duplicate the # first and last direction vectors to fake the adjacent edges. This causes the first and last # edges to have bisectors that are perpendicular to themselves. if closed? # Prepend the last direction vector so that the last edge can be used to find the bisector for the first vertex tangents.unshift tangents.last else # Duplicate the first and last direction vectors to compensate for not having edges adjacent to the first and last vertices tangents.unshift(tangents.first) tangents.push(tangents.last) end end end
[ "def", "tangent_loop", "edges", ".", "map", "{", "|", "e", "|", "e", ".", "direction", "}", ".", "tap", "do", "|", "tangents", "|", "# Generating a bisector for each vertex requires an edge on both sides of each vertex.", "# Obviously, the first and last vertices each have only a single adjacent edge, unless the", "# Polyline happens to be closed (like a Polygon). When not closed, duplicate the", "# first and last direction vectors to fake the adjacent edges. This causes the first and last", "# edges to have bisectors that are perpendicular to themselves.", "if", "closed?", "# Prepend the last direction vector so that the last edge can be used to find the bisector for the first vertex", "tangents", ".", "unshift", "tangents", ".", "last", "else", "# Duplicate the first and last direction vectors to compensate for not having edges adjacent to the first and last vertices", "tangents", ".", "unshift", "(", "tangents", ".", "first", ")", "tangents", ".", "push", "(", "tangents", ".", "last", ")", "end", "end", "end" ]
Generate the tangents and fake a circular buffer while accounting for closedness @return [Array<Vector>] the tangents
[ "Generate", "the", "tangents", "and", "fake", "a", "circular", "buffer", "while", "accounting", "for", "closedness" ]
3054ccba59f184c172be52a6f0b7cf4a33f617a5
https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L317-L333
1,650
bfoz/geometry
lib/geometry/polyline.rb
Geometry.Polyline.find_next_intersection
def find_next_intersection(edges, i, e) for j in i..(edges.count-1) e2 = edges[j][:edge] next if !e2 || e.connected?(e2) intersection = e.intersection(e2) return [intersection, j] if intersection end nil end
ruby
def find_next_intersection(edges, i, e) for j in i..(edges.count-1) e2 = edges[j][:edge] next if !e2 || e.connected?(e2) intersection = e.intersection(e2) return [intersection, j] if intersection end nil end
[ "def", "find_next_intersection", "(", "edges", ",", "i", ",", "e", ")", "for", "j", "in", "i", "..", "(", "edges", ".", "count", "-", "1", ")", "e2", "=", "edges", "[", "j", "]", "[", ":edge", "]", "next", "if", "!", "e2", "||", "e", ".", "connected?", "(", "e2", ")", "intersection", "=", "e", ".", "intersection", "(", "e2", ")", "return", "[", "intersection", ",", "j", "]", "if", "intersection", "end", "nil", "end" ]
Find the next edge that intersects with e, starting at index i
[ "Find", "the", "next", "edge", "that", "intersects", "with", "e", "starting", "at", "index", "i" ]
3054ccba59f184c172be52a6f0b7cf4a33f617a5
https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L336-L344
1,651
bfoz/geometry
lib/geometry/polyline.rb
Geometry.Polyline.find_last_intersection
def find_last_intersection(edges, i, e) intersection, intersection_at = nil, nil for j in i..(edges.count-1) e2 = edges[j][:edge] next if !e2 || e.connected?(e2) _intersection = e.intersection(e2) intersection, intersection_at = _intersection, j if _intersection end [intersection, intersection_at] end
ruby
def find_last_intersection(edges, i, e) intersection, intersection_at = nil, nil for j in i..(edges.count-1) e2 = edges[j][:edge] next if !e2 || e.connected?(e2) _intersection = e.intersection(e2) intersection, intersection_at = _intersection, j if _intersection end [intersection, intersection_at] end
[ "def", "find_last_intersection", "(", "edges", ",", "i", ",", "e", ")", "intersection", ",", "intersection_at", "=", "nil", ",", "nil", "for", "j", "in", "i", "..", "(", "edges", ".", "count", "-", "1", ")", "e2", "=", "edges", "[", "j", "]", "[", ":edge", "]", "next", "if", "!", "e2", "||", "e", ".", "connected?", "(", "e2", ")", "_intersection", "=", "e", ".", "intersection", "(", "e2", ")", "intersection", ",", "intersection_at", "=", "_intersection", ",", "j", "if", "_intersection", "end", "[", "intersection", ",", "intersection_at", "]", "end" ]
Find the last edge that intersects with e, starting at index i
[ "Find", "the", "last", "edge", "that", "intersects", "with", "e", "starting", "at", "index", "i" ]
3054ccba59f184c172be52a6f0b7cf4a33f617a5
https://github.com/bfoz/geometry/blob/3054ccba59f184c172be52a6f0b7cf4a33f617a5/lib/geometry/polyline.rb#L347-L356
1,652
paddor/cztop
lib/cztop/config.rb
CZTop.Config.[]
def [](path, default = "") ptr = ffi_delegate.get(path, default) return nil if ptr.null? ptr.read_string end
ruby
def [](path, default = "") ptr = ffi_delegate.get(path, default) return nil if ptr.null? ptr.read_string end
[ "def", "[]", "(", "path", ",", "default", "=", "\"\"", ")", "ptr", "=", "ffi_delegate", ".", "get", "(", "path", ",", "default", ")", "return", "nil", "if", "ptr", ".", "null?", "ptr", ".", "read_string", "end" ]
Get the value of the current config item. @param path [String, #to_s] path to config item @param default [String, #to_s] default value to return if config item doesn't exist @return [String] @return [default] if config item doesn't exist @note The default value is not returned when the config item exists but just doesn't have a value. In that case, it'll return the empty string.
[ "Get", "the", "value", "of", "the", "current", "config", "item", "." ]
d20ee44775d05b60f40fffd1287a9b01270ab853
https://github.com/paddor/cztop/blob/d20ee44775d05b60f40fffd1287a9b01270ab853/lib/cztop/config.rb#L95-L99
1,653
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.9/xmlrpc/create.rb
XMLRPC.Create.methodResponse
def methodResponse(is_ret, *params) if is_ret resp = params.collect do |param| @writer.ele("param", conv2value(param)) end resp = [@writer.ele("params", *resp)] else if params.size != 1 or params[0] === XMLRPC::FaultException raise ArgumentError, "no valid fault-structure given" end resp = @writer.ele("fault", conv2value(params[0].to_h)) end tree = @writer.document( @writer.pi("xml", 'version="1.0"'), @writer.ele("methodResponse", resp) ) @writer.document_to_str(tree) + "\n" end
ruby
def methodResponse(is_ret, *params) if is_ret resp = params.collect do |param| @writer.ele("param", conv2value(param)) end resp = [@writer.ele("params", *resp)] else if params.size != 1 or params[0] === XMLRPC::FaultException raise ArgumentError, "no valid fault-structure given" end resp = @writer.ele("fault", conv2value(params[0].to_h)) end tree = @writer.document( @writer.pi("xml", 'version="1.0"'), @writer.ele("methodResponse", resp) ) @writer.document_to_str(tree) + "\n" end
[ "def", "methodResponse", "(", "is_ret", ",", "*", "params", ")", "if", "is_ret", "resp", "=", "params", ".", "collect", "do", "|", "param", "|", "@writer", ".", "ele", "(", "\"param\"", ",", "conv2value", "(", "param", ")", ")", "end", "resp", "=", "[", "@writer", ".", "ele", "(", "\"params\"", ",", "resp", ")", "]", "else", "if", "params", ".", "size", "!=", "1", "or", "params", "[", "0", "]", "===", "XMLRPC", "::", "FaultException", "raise", "ArgumentError", ",", "\"no valid fault-structure given\"", "end", "resp", "=", "@writer", ".", "ele", "(", "\"fault\"", ",", "conv2value", "(", "params", "[", "0", "]", ".", "to_h", ")", ")", "end", "tree", "=", "@writer", ".", "document", "(", "@writer", ".", "pi", "(", "\"xml\"", ",", "'version=\"1.0\"'", ")", ",", "@writer", ".", "ele", "(", "\"methodResponse\"", ",", "resp", ")", ")", "@writer", ".", "document_to_str", "(", "tree", ")", "+", "\"\\n\"", "end" ]
generates a XML-RPC methodResponse document if is_ret == false then the params array must contain only one element, which is a structure of a fault return-value. if is_ret == true then a normal return-value of all the given params is created.
[ "generates", "a", "XML", "-", "RPC", "methodResponse", "document" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.9/xmlrpc/create.rb#L144-L166
1,654
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/fragments.rb
SM.LineCollection.add_list_start_and_ends
def add_list_start_and_ends level = 0 res = [] type_stack = [] @fragments.each do |fragment| # $stderr.puts "#{level} : #{fragment.class.name} : #{fragment.level}" new_level = fragment.level while (level < new_level) level += 1 type = fragment.type res << ListStart.new(level, fragment.param, type) if type type_stack.push type # $stderr.puts "Start: #{level}" end while level > new_level type = type_stack.pop res << ListEnd.new(level, type) if type level -= 1 # $stderr.puts "End: #{level}, #{type}" end res << fragment level = fragment.level end level.downto(1) do |i| type = type_stack.pop res << ListEnd.new(i, type) if type end @fragments = res end
ruby
def add_list_start_and_ends level = 0 res = [] type_stack = [] @fragments.each do |fragment| # $stderr.puts "#{level} : #{fragment.class.name} : #{fragment.level}" new_level = fragment.level while (level < new_level) level += 1 type = fragment.type res << ListStart.new(level, fragment.param, type) if type type_stack.push type # $stderr.puts "Start: #{level}" end while level > new_level type = type_stack.pop res << ListEnd.new(level, type) if type level -= 1 # $stderr.puts "End: #{level}, #{type}" end res << fragment level = fragment.level end level.downto(1) do |i| type = type_stack.pop res << ListEnd.new(i, type) if type end @fragments = res end
[ "def", "add_list_start_and_ends", "level", "=", "0", "res", "=", "[", "]", "type_stack", "=", "[", "]", "@fragments", ".", "each", "do", "|", "fragment", "|", "# $stderr.puts \"#{level} : #{fragment.class.name} : #{fragment.level}\"", "new_level", "=", "fragment", ".", "level", "while", "(", "level", "<", "new_level", ")", "level", "+=", "1", "type", "=", "fragment", ".", "type", "res", "<<", "ListStart", ".", "new", "(", "level", ",", "fragment", ".", "param", ",", "type", ")", "if", "type", "type_stack", ".", "push", "type", "# $stderr.puts \"Start: #{level}\"", "end", "while", "level", ">", "new_level", "type", "=", "type_stack", ".", "pop", "res", "<<", "ListEnd", ".", "new", "(", "level", ",", "type", ")", "if", "type", "level", "-=", "1", "# $stderr.puts \"End: #{level}, #{type}\"", "end", "res", "<<", "fragment", "level", "=", "fragment", ".", "level", "end", "level", ".", "downto", "(", "1", ")", "do", "|", "i", "|", "type", "=", "type_stack", ".", "pop", "res", "<<", "ListEnd", ".", "new", "(", "i", ",", "type", ")", "if", "type", "end", "@fragments", "=", "res", "end" ]
List nesting is implicit given the level of Make it explicit, just to make life a tad easier for the output processors
[ "List", "nesting", "is", "implicit", "given", "the", "level", "of", "Make", "it", "explicit", "just", "to", "make", "life", "a", "tad", "easier", "for", "the", "output", "processors" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/fragments.rb#L239-L271
1,655
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/packagetask.rb
Rake.PackageTask.init
def init(name, version) @name = name @version = version @package_files = Rake::FileList.new @package_dir = 'pkg' @need_tar = false @need_tar_gz = false @need_tar_bz2 = false @need_zip = false @tar_command = 'tar' @zip_command = 'zip' end
ruby
def init(name, version) @name = name @version = version @package_files = Rake::FileList.new @package_dir = 'pkg' @need_tar = false @need_tar_gz = false @need_tar_bz2 = false @need_zip = false @tar_command = 'tar' @zip_command = 'zip' end
[ "def", "init", "(", "name", ",", "version", ")", "@name", "=", "name", "@version", "=", "version", "@package_files", "=", "Rake", "::", "FileList", ".", "new", "@package_dir", "=", "'pkg'", "@need_tar", "=", "false", "@need_tar_gz", "=", "false", "@need_tar_bz2", "=", "false", "@need_zip", "=", "false", "@tar_command", "=", "'tar'", "@zip_command", "=", "'zip'", "end" ]
Create a Package Task with the given name and version. Initialization that bypasses the "yield self" and "define" step.
[ "Create", "a", "Package", "Task", "with", "the", "given", "name", "and", "version", ".", "Initialization", "that", "bypasses", "the", "yield", "self", "and", "define", "step", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/packagetask.rb#L85-L96
1,656
maintux/esx
lib/esx.rb
ESX.Host.create_vm
def create_vm(specification) spec = specification spec[:cpus] = (specification[:cpus] || 1).to_i spec[:cpu_cores] = (specification[:cpu_cores] || 1).to_i spec[:guest_id] = specification[:guest_id] || 'otherGuest' spec[:hw_version] = (specification[:hw_version] || 8).to_i if specification[:disk_size] spec[:disk_size] = (specification[:disk_size].to_i * 1024) else spec[:disk_size] = 4194304 end spec[:memory] = (specification[:memory] || 128).to_i if specification[:datastore] spec[:datastore] = "[#{specification[:datastore]}]" else spec[:datastore] = '[datastore1]' end vm_cfg = { :name => spec[:vm_name], :guestId => spec[:guest_id], :files => { :vmPathName => spec[:datastore] }, :numCPUs => spec[:cpus], :numCoresPerSocket => spec[:cpu_cores], :memoryMB => spec[:memory], :deviceChange => [ { :operation => :add, :device => RbVmomi::VIM.VirtualLsiLogicController( :key => 1000, :busNumber => 0, :sharedBus => :noSharing) } ], :version => 'vmx-'+spec[:hw_version].to_s.rjust(2,'0'), :extraConfig => [ { :key => 'bios.bootOrder', :value => 'ethernet0' } ] } #Add multiple nics nics_count = 0 if spec[:nics] spec[:nics].each do |nic_spec| vm_cfg[:deviceChange].push( { :operation => :add, :device => RbVmomi::VIM.VirtualE1000(create_net_dev(nics_count, nic_spec)) } ) nics_count += 1 end end # VMDK provided, replace the empty vmdk vm_cfg[:deviceChange].push(create_disk_spec(:disk_file => spec[:disk_file], :disk_type => spec[:disk_type], :disk_size => spec[:disk_size], :datastore => spec[:datastore])) unless @free_license VM.wrap(@_datacenter.vmFolder.CreateVM_Task(:config => vm_cfg, :pool => @_datacenter.hostFolder.children.first.resourcePool).wait_for_completion,self) else gem_root = Gem::Specification.find_by_name("esx").gem_dir template_path = File.join(gem_root, 'templates', 'vmx_template.erb') spec[:guest_id] = convert_guest_id_for_vmdk(spec[:guest_id]) erb = ERB.new File.read(template_path) vmx = erb.result binding tmp_vmx = Tempfile.new 'vmx' tmp_vmx.write vmx tmp_vmx.close ds = spec[:datastore]||'datastore1' ds = ds.gsub('[','').gsub(']','') vmx_path = "/vmfs/volumes/#{ds}/#{spec[:vm_name]}/#{spec[:vm_name]}.vmx" remote_command "mkdir -p #{File.dirname(vmx_path)}" upload_file tmp_vmx.path, vmx_path remote_command "vim-cmd solo/registervm #{vmx_path}" VM.wrap(@_datacenter.find_vm(spec[:vm_name]),self) end end
ruby
def create_vm(specification) spec = specification spec[:cpus] = (specification[:cpus] || 1).to_i spec[:cpu_cores] = (specification[:cpu_cores] || 1).to_i spec[:guest_id] = specification[:guest_id] || 'otherGuest' spec[:hw_version] = (specification[:hw_version] || 8).to_i if specification[:disk_size] spec[:disk_size] = (specification[:disk_size].to_i * 1024) else spec[:disk_size] = 4194304 end spec[:memory] = (specification[:memory] || 128).to_i if specification[:datastore] spec[:datastore] = "[#{specification[:datastore]}]" else spec[:datastore] = '[datastore1]' end vm_cfg = { :name => spec[:vm_name], :guestId => spec[:guest_id], :files => { :vmPathName => spec[:datastore] }, :numCPUs => spec[:cpus], :numCoresPerSocket => spec[:cpu_cores], :memoryMB => spec[:memory], :deviceChange => [ { :operation => :add, :device => RbVmomi::VIM.VirtualLsiLogicController( :key => 1000, :busNumber => 0, :sharedBus => :noSharing) } ], :version => 'vmx-'+spec[:hw_version].to_s.rjust(2,'0'), :extraConfig => [ { :key => 'bios.bootOrder', :value => 'ethernet0' } ] } #Add multiple nics nics_count = 0 if spec[:nics] spec[:nics].each do |nic_spec| vm_cfg[:deviceChange].push( { :operation => :add, :device => RbVmomi::VIM.VirtualE1000(create_net_dev(nics_count, nic_spec)) } ) nics_count += 1 end end # VMDK provided, replace the empty vmdk vm_cfg[:deviceChange].push(create_disk_spec(:disk_file => spec[:disk_file], :disk_type => spec[:disk_type], :disk_size => spec[:disk_size], :datastore => spec[:datastore])) unless @free_license VM.wrap(@_datacenter.vmFolder.CreateVM_Task(:config => vm_cfg, :pool => @_datacenter.hostFolder.children.first.resourcePool).wait_for_completion,self) else gem_root = Gem::Specification.find_by_name("esx").gem_dir template_path = File.join(gem_root, 'templates', 'vmx_template.erb') spec[:guest_id] = convert_guest_id_for_vmdk(spec[:guest_id]) erb = ERB.new File.read(template_path) vmx = erb.result binding tmp_vmx = Tempfile.new 'vmx' tmp_vmx.write vmx tmp_vmx.close ds = spec[:datastore]||'datastore1' ds = ds.gsub('[','').gsub(']','') vmx_path = "/vmfs/volumes/#{ds}/#{spec[:vm_name]}/#{spec[:vm_name]}.vmx" remote_command "mkdir -p #{File.dirname(vmx_path)}" upload_file tmp_vmx.path, vmx_path remote_command "vim-cmd solo/registervm #{vmx_path}" VM.wrap(@_datacenter.find_vm(spec[:vm_name]),self) end end
[ "def", "create_vm", "(", "specification", ")", "spec", "=", "specification", "spec", "[", ":cpus", "]", "=", "(", "specification", "[", ":cpus", "]", "||", "1", ")", ".", "to_i", "spec", "[", ":cpu_cores", "]", "=", "(", "specification", "[", ":cpu_cores", "]", "||", "1", ")", ".", "to_i", "spec", "[", ":guest_id", "]", "=", "specification", "[", ":guest_id", "]", "||", "'otherGuest'", "spec", "[", ":hw_version", "]", "=", "(", "specification", "[", ":hw_version", "]", "||", "8", ")", ".", "to_i", "if", "specification", "[", ":disk_size", "]", "spec", "[", ":disk_size", "]", "=", "(", "specification", "[", ":disk_size", "]", ".", "to_i", "*", "1024", ")", "else", "spec", "[", ":disk_size", "]", "=", "4194304", "end", "spec", "[", ":memory", "]", "=", "(", "specification", "[", ":memory", "]", "||", "128", ")", ".", "to_i", "if", "specification", "[", ":datastore", "]", "spec", "[", ":datastore", "]", "=", "\"[#{specification[:datastore]}]\"", "else", "spec", "[", ":datastore", "]", "=", "'[datastore1]'", "end", "vm_cfg", "=", "{", ":name", "=>", "spec", "[", ":vm_name", "]", ",", ":guestId", "=>", "spec", "[", ":guest_id", "]", ",", ":files", "=>", "{", ":vmPathName", "=>", "spec", "[", ":datastore", "]", "}", ",", ":numCPUs", "=>", "spec", "[", ":cpus", "]", ",", ":numCoresPerSocket", "=>", "spec", "[", ":cpu_cores", "]", ",", ":memoryMB", "=>", "spec", "[", ":memory", "]", ",", ":deviceChange", "=>", "[", "{", ":operation", "=>", ":add", ",", ":device", "=>", "RbVmomi", "::", "VIM", ".", "VirtualLsiLogicController", "(", ":key", "=>", "1000", ",", ":busNumber", "=>", "0", ",", ":sharedBus", "=>", ":noSharing", ")", "}", "]", ",", ":version", "=>", "'vmx-'", "+", "spec", "[", ":hw_version", "]", ".", "to_s", ".", "rjust", "(", "2", ",", "'0'", ")", ",", ":extraConfig", "=>", "[", "{", ":key", "=>", "'bios.bootOrder'", ",", ":value", "=>", "'ethernet0'", "}", "]", "}", "#Add multiple nics", "nics_count", "=", "0", "if", "spec", "[", ":nics", "]", "spec", "[", ":nics", "]", ".", "each", "do", "|", "nic_spec", "|", "vm_cfg", "[", ":deviceChange", "]", ".", "push", "(", "{", ":operation", "=>", ":add", ",", ":device", "=>", "RbVmomi", "::", "VIM", ".", "VirtualE1000", "(", "create_net_dev", "(", "nics_count", ",", "nic_spec", ")", ")", "}", ")", "nics_count", "+=", "1", "end", "end", "# VMDK provided, replace the empty vmdk", "vm_cfg", "[", ":deviceChange", "]", ".", "push", "(", "create_disk_spec", "(", ":disk_file", "=>", "spec", "[", ":disk_file", "]", ",", ":disk_type", "=>", "spec", "[", ":disk_type", "]", ",", ":disk_size", "=>", "spec", "[", ":disk_size", "]", ",", ":datastore", "=>", "spec", "[", ":datastore", "]", ")", ")", "unless", "@free_license", "VM", ".", "wrap", "(", "@_datacenter", ".", "vmFolder", ".", "CreateVM_Task", "(", ":config", "=>", "vm_cfg", ",", ":pool", "=>", "@_datacenter", ".", "hostFolder", ".", "children", ".", "first", ".", "resourcePool", ")", ".", "wait_for_completion", ",", "self", ")", "else", "gem_root", "=", "Gem", "::", "Specification", ".", "find_by_name", "(", "\"esx\"", ")", ".", "gem_dir", "template_path", "=", "File", ".", "join", "(", "gem_root", ",", "'templates'", ",", "'vmx_template.erb'", ")", "spec", "[", ":guest_id", "]", "=", "convert_guest_id_for_vmdk", "(", "spec", "[", ":guest_id", "]", ")", "erb", "=", "ERB", ".", "new", "File", ".", "read", "(", "template_path", ")", "vmx", "=", "erb", ".", "result", "binding", "tmp_vmx", "=", "Tempfile", ".", "new", "'vmx'", "tmp_vmx", ".", "write", "vmx", "tmp_vmx", ".", "close", "ds", "=", "spec", "[", ":datastore", "]", "||", "'datastore1'", "ds", "=", "ds", ".", "gsub", "(", "'['", ",", "''", ")", ".", "gsub", "(", "']'", ",", "''", ")", "vmx_path", "=", "\"/vmfs/volumes/#{ds}/#{spec[:vm_name]}/#{spec[:vm_name]}.vmx\"", "remote_command", "\"mkdir -p #{File.dirname(vmx_path)}\"", "upload_file", "tmp_vmx", ".", "path", ",", "vmx_path", "remote_command", "\"vim-cmd solo/registervm #{vmx_path}\"", "VM", ".", "wrap", "(", "@_datacenter", ".", "find_vm", "(", "spec", "[", ":vm_name", "]", ")", ",", "self", ")", "end", "end" ]
Create a Virtual Machine Requires a Hash with the following keys: { :vm_name => name, (string, required) :cpus => 1, #(int, optional) :guest_id => 'otherGuest', #(string, optional) :disk_size => 4096, #(in MB, optional) :memory => 128, #(in MB, optional) :datastore => datastore1 #(string, optional) :disk_file => path to vmdk inside datastore (optional) :disk_type => flat, sparse (default flat) :hw_version => 8 #(int, optional) } supported guest_id list: http://pubs.vmware.com/vsphere-50/index.jsp?topic=/com.vmware.wssdk.apiref.doc_50/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html Default values above.
[ "Create", "a", "Virtual", "Machine" ]
ac02f2ef1b6294dfaa811fe638250cb3c000eeb6
https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L126-L207
1,657
maintux/esx
lib/esx.rb
ESX.Host.host_info
def host_info [ @_host.summary.config.product.fullName, @_host.summary.config.product.apiType, @_host.summary.config.product.apiVersion, @_host.summary.config.product.osType, @_host.summary.config.product.productLineId, @_host.summary.config.product.vendor, @_host.summary.config.product.version ] end
ruby
def host_info [ @_host.summary.config.product.fullName, @_host.summary.config.product.apiType, @_host.summary.config.product.apiVersion, @_host.summary.config.product.osType, @_host.summary.config.product.productLineId, @_host.summary.config.product.vendor, @_host.summary.config.product.version ] end
[ "def", "host_info", "[", "@_host", ".", "summary", ".", "config", ".", "product", ".", "fullName", ",", "@_host", ".", "summary", ".", "config", ".", "product", ".", "apiType", ",", "@_host", ".", "summary", ".", "config", ".", "product", ".", "apiVersion", ",", "@_host", ".", "summary", ".", "config", ".", "product", ".", "osType", ",", "@_host", ".", "summary", ".", "config", ".", "product", ".", "productLineId", ",", "@_host", ".", "summary", ".", "config", ".", "product", ".", "vendor", ",", "@_host", ".", "summary", ".", "config", ".", "product", ".", "version", "]", "end" ]
Return product info as an array of strings containing fullName, apiType, apiVersion, osType, productLineId, vendor, version
[ "Return", "product", "info", "as", "an", "array", "of", "strings", "containing" ]
ac02f2ef1b6294dfaa811fe638250cb3c000eeb6
https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L234-L244
1,658
maintux/esx
lib/esx.rb
ESX.Host.remote_command
def remote_command(cmd) output = "" Net::SSH.start(@address, @user, :password => @password) do |ssh| output = ssh.exec! cmd end output end
ruby
def remote_command(cmd) output = "" Net::SSH.start(@address, @user, :password => @password) do |ssh| output = ssh.exec! cmd end output end
[ "def", "remote_command", "(", "cmd", ")", "output", "=", "\"\"", "Net", "::", "SSH", ".", "start", "(", "@address", ",", "@user", ",", ":password", "=>", "@password", ")", "do", "|", "ssh", "|", "output", "=", "ssh", ".", "exec!", "cmd", "end", "output", "end" ]
Run a command in the ESX host via SSH
[ "Run", "a", "command", "in", "the", "ESX", "host", "via", "SSH" ]
ac02f2ef1b6294dfaa811fe638250cb3c000eeb6
https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L272-L278
1,659
maintux/esx
lib/esx.rb
ESX.Host.copy_from_template
def copy_from_template(template_disk, destination) Log.debug "Copying from template #{template_disk} to #{destination}" raise "Template does not exist" if not template_exist?(template_disk) source = File.join(@templates_dir, File.basename(template_disk)) Net::SSH.start(@address, @user, :password => @password) do |ssh| Log.debug "Clone disk #{source} to #{destination}" Log.debug ssh.exec!("vmkfstools -i #{source} --diskformat thin #{destination} 2>&1") end end
ruby
def copy_from_template(template_disk, destination) Log.debug "Copying from template #{template_disk} to #{destination}" raise "Template does not exist" if not template_exist?(template_disk) source = File.join(@templates_dir, File.basename(template_disk)) Net::SSH.start(@address, @user, :password => @password) do |ssh| Log.debug "Clone disk #{source} to #{destination}" Log.debug ssh.exec!("vmkfstools -i #{source} --diskformat thin #{destination} 2>&1") end end
[ "def", "copy_from_template", "(", "template_disk", ",", "destination", ")", "Log", ".", "debug", "\"Copying from template #{template_disk} to #{destination}\"", "raise", "\"Template does not exist\"", "if", "not", "template_exist?", "(", "template_disk", ")", "source", "=", "File", ".", "join", "(", "@templates_dir", ",", "File", ".", "basename", "(", "template_disk", ")", ")", "Net", "::", "SSH", ".", "start", "(", "@address", ",", "@user", ",", ":password", "=>", "@password", ")", "do", "|", "ssh", "|", "Log", ".", "debug", "\"Clone disk #{source} to #{destination}\"", "Log", ".", "debug", "ssh", ".", "exec!", "(", "\"vmkfstools -i #{source} --diskformat thin #{destination} 2>&1\"", ")", "end", "end" ]
Expects vmdk source file path and destination path copy_from_template "/home/fooser/my.vmdk", "/vmfs/volumes/datastore1/foovm/foovm.vmdk" Destination directory must exist otherwise rises exception
[ "Expects", "vmdk", "source", "file", "path", "and", "destination", "path" ]
ac02f2ef1b6294dfaa811fe638250cb3c000eeb6
https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L356-L364
1,660
maintux/esx
lib/esx.rb
ESX.Host.import_disk
def import_disk(source, destination, print_progress = false, params = {}) use_template = params[:use_template] || false if use_template Log.debug "import_disk :use_template => true" if !template_exist?(source) Log.debug "import_disk, template does not exist, importing." import_template(source, { :print_progress => print_progress }) end copy_from_template(source, destination) else import_disk_convert source, destination, print_progress end end
ruby
def import_disk(source, destination, print_progress = false, params = {}) use_template = params[:use_template] || false if use_template Log.debug "import_disk :use_template => true" if !template_exist?(source) Log.debug "import_disk, template does not exist, importing." import_template(source, { :print_progress => print_progress }) end copy_from_template(source, destination) else import_disk_convert source, destination, print_progress end end
[ "def", "import_disk", "(", "source", ",", "destination", ",", "print_progress", "=", "false", ",", "params", "=", "{", "}", ")", "use_template", "=", "params", "[", ":use_template", "]", "||", "false", "if", "use_template", "Log", ".", "debug", "\"import_disk :use_template => true\"", "if", "!", "template_exist?", "(", "source", ")", "Log", ".", "debug", "\"import_disk, template does not exist, importing.\"", "import_template", "(", "source", ",", "{", ":print_progress", "=>", "print_progress", "}", ")", "end", "copy_from_template", "(", "source", ",", "destination", ")", "else", "import_disk_convert", "source", ",", "destination", ",", "print_progress", "end", "end" ]
Imports a VMDK if params has :use_template => true, the disk is saved as a template in @templates_dir and cloned from there. Destination directory must exist otherwise rises exception
[ "Imports", "a", "VMDK" ]
ac02f2ef1b6294dfaa811fe638250cb3c000eeb6
https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L374-L386
1,661
maintux/esx
lib/esx.rb
ESX.Host.import_disk_convert
def import_disk_convert(source, destination, print_progress = false) tmp_dest = destination + ".tmp" Net::SSH.start(@address, @user, :password => @password) do |ssh| if not (ssh.exec! "ls #{destination} 2>/dev/null").nil? raise Exception.new("Destination file #{destination} already exists") end Log.info "Uploading file... (#{File.basename(source)})" if print_progress ssh.scp.upload!(source, tmp_dest) do |ch, name, sent, total| if print_progress print "\rProgress: #{(sent.to_f * 100 / total.to_f).to_i}%" end end if print_progress Log.info "Converting disk..." ssh.exec "vmkfstools -i #{tmp_dest} --diskformat thin #{destination}; rm -f #{tmp_dest}" else ssh.exec "vmkfstools -i #{tmp_dest} --diskformat thin #{destination} >/dev/null 2>&1; rm -f #{tmp_dest}" end end end
ruby
def import_disk_convert(source, destination, print_progress = false) tmp_dest = destination + ".tmp" Net::SSH.start(@address, @user, :password => @password) do |ssh| if not (ssh.exec! "ls #{destination} 2>/dev/null").nil? raise Exception.new("Destination file #{destination} already exists") end Log.info "Uploading file... (#{File.basename(source)})" if print_progress ssh.scp.upload!(source, tmp_dest) do |ch, name, sent, total| if print_progress print "\rProgress: #{(sent.to_f * 100 / total.to_f).to_i}%" end end if print_progress Log.info "Converting disk..." ssh.exec "vmkfstools -i #{tmp_dest} --diskformat thin #{destination}; rm -f #{tmp_dest}" else ssh.exec "vmkfstools -i #{tmp_dest} --diskformat thin #{destination} >/dev/null 2>&1; rm -f #{tmp_dest}" end end end
[ "def", "import_disk_convert", "(", "source", ",", "destination", ",", "print_progress", "=", "false", ")", "tmp_dest", "=", "destination", "+", "\".tmp\"", "Net", "::", "SSH", ".", "start", "(", "@address", ",", "@user", ",", ":password", "=>", "@password", ")", "do", "|", "ssh", "|", "if", "not", "(", "ssh", ".", "exec!", "\"ls #{destination} 2>/dev/null\"", ")", ".", "nil?", "raise", "Exception", ".", "new", "(", "\"Destination file #{destination} already exists\"", ")", "end", "Log", ".", "info", "\"Uploading file... (#{File.basename(source)})\"", "if", "print_progress", "ssh", ".", "scp", ".", "upload!", "(", "source", ",", "tmp_dest", ")", "do", "|", "ch", ",", "name", ",", "sent", ",", "total", "|", "if", "print_progress", "print", "\"\\rProgress: #{(sent.to_f * 100 / total.to_f).to_i}%\"", "end", "end", "if", "print_progress", "Log", ".", "info", "\"Converting disk...\"", "ssh", ".", "exec", "\"vmkfstools -i #{tmp_dest} --diskformat thin #{destination}; rm -f #{tmp_dest}\"", "else", "ssh", ".", "exec", "\"vmkfstools -i #{tmp_dest} --diskformat thin #{destination} >/dev/null 2>&1; rm -f #{tmp_dest}\"", "end", "end", "end" ]
This method does all the heavy lifting when importing the disk. It also converts the imported VMDK to thin format
[ "This", "method", "does", "all", "the", "heavy", "lifting", "when", "importing", "the", "disk", ".", "It", "also", "converts", "the", "imported", "VMDK", "to", "thin", "format" ]
ac02f2ef1b6294dfaa811fe638250cb3c000eeb6
https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L392-L411
1,662
maintux/esx
lib/esx.rb
ESX.Host.create_disk_spec
def create_disk_spec(params) disk_type = params[:disk_type] || :flat disk_file = params[:disk_file] if disk_type == :sparse and disk_file.nil? raise Exception.new("Creating sparse disks in ESX is not supported. Use an existing image.") end disk_size = params[:disk_size] datastore = params[:datastore] datastore = datastore + " #{disk_file}" if not disk_file.nil? spec = {} if disk_type == :sparse spec = { :operation => :add, :device => RbVmomi::VIM.VirtualDisk( :key => 0, :backing => RbVmomi::VIM.VirtualDiskSparseVer2BackingInfo( :fileName => datastore, :diskMode => :persistent), :controllerKey => 1000, :unitNumber => 0, :capacityInKB => disk_size) } else spec = { :operation => :add, :device => RbVmomi::VIM.VirtualDisk( :key => 0, :backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo( :fileName => datastore, :diskMode => :persistent), :controllerKey => 1000, :unitNumber => 0, :capacityInKB => disk_size) } end spec[:fileOperation] = :create if disk_file.nil? spec end
ruby
def create_disk_spec(params) disk_type = params[:disk_type] || :flat disk_file = params[:disk_file] if disk_type == :sparse and disk_file.nil? raise Exception.new("Creating sparse disks in ESX is not supported. Use an existing image.") end disk_size = params[:disk_size] datastore = params[:datastore] datastore = datastore + " #{disk_file}" if not disk_file.nil? spec = {} if disk_type == :sparse spec = { :operation => :add, :device => RbVmomi::VIM.VirtualDisk( :key => 0, :backing => RbVmomi::VIM.VirtualDiskSparseVer2BackingInfo( :fileName => datastore, :diskMode => :persistent), :controllerKey => 1000, :unitNumber => 0, :capacityInKB => disk_size) } else spec = { :operation => :add, :device => RbVmomi::VIM.VirtualDisk( :key => 0, :backing => RbVmomi::VIM.VirtualDiskFlatVer2BackingInfo( :fileName => datastore, :diskMode => :persistent), :controllerKey => 1000, :unitNumber => 0, :capacityInKB => disk_size) } end spec[:fileOperation] = :create if disk_file.nil? spec end
[ "def", "create_disk_spec", "(", "params", ")", "disk_type", "=", "params", "[", ":disk_type", "]", "||", ":flat", "disk_file", "=", "params", "[", ":disk_file", "]", "if", "disk_type", "==", ":sparse", "and", "disk_file", ".", "nil?", "raise", "Exception", ".", "new", "(", "\"Creating sparse disks in ESX is not supported. Use an existing image.\"", ")", "end", "disk_size", "=", "params", "[", ":disk_size", "]", "datastore", "=", "params", "[", ":datastore", "]", "datastore", "=", "datastore", "+", "\" #{disk_file}\"", "if", "not", "disk_file", ".", "nil?", "spec", "=", "{", "}", "if", "disk_type", "==", ":sparse", "spec", "=", "{", ":operation", "=>", ":add", ",", ":device", "=>", "RbVmomi", "::", "VIM", ".", "VirtualDisk", "(", ":key", "=>", "0", ",", ":backing", "=>", "RbVmomi", "::", "VIM", ".", "VirtualDiskSparseVer2BackingInfo", "(", ":fileName", "=>", "datastore", ",", ":diskMode", "=>", ":persistent", ")", ",", ":controllerKey", "=>", "1000", ",", ":unitNumber", "=>", "0", ",", ":capacityInKB", "=>", "disk_size", ")", "}", "else", "spec", "=", "{", ":operation", "=>", ":add", ",", ":device", "=>", "RbVmomi", "::", "VIM", ".", "VirtualDisk", "(", ":key", "=>", "0", ",", ":backing", "=>", "RbVmomi", "::", "VIM", ".", "VirtualDiskFlatVer2BackingInfo", "(", ":fileName", "=>", "datastore", ",", ":diskMode", "=>", ":persistent", ")", ",", ":controllerKey", "=>", "1000", ",", ":unitNumber", "=>", "0", ",", ":capacityInKB", "=>", "disk_size", ")", "}", "end", "spec", "[", ":fileOperation", "]", "=", ":create", "if", "disk_file", ".", "nil?", "spec", "end" ]
disk_file datastore disk_size disk_type
[ "disk_file", "datastore", "disk_size", "disk_type" ]
ac02f2ef1b6294dfaa811fe638250cb3c000eeb6
https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L424-L461
1,663
maintux/esx
lib/esx.rb
ESX.VM.destroy
def destroy #disks = vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk) unless host.free_license vm_object.Destroy_Task.wait_for_completion else host.remote_command "vim-cmd vmsvc/power.off #{vmid}" host.remote_command "vim-cmd vmsvc/destroy #{vmid}" end end
ruby
def destroy #disks = vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk) unless host.free_license vm_object.Destroy_Task.wait_for_completion else host.remote_command "vim-cmd vmsvc/power.off #{vmid}" host.remote_command "vim-cmd vmsvc/destroy #{vmid}" end end
[ "def", "destroy", "#disks = vm_object.config.hardware.device.grep(RbVmomi::VIM::VirtualDisk)", "unless", "host", ".", "free_license", "vm_object", ".", "Destroy_Task", ".", "wait_for_completion", "else", "host", ".", "remote_command", "\"vim-cmd vmsvc/power.off #{vmid}\"", "host", ".", "remote_command", "\"vim-cmd vmsvc/destroy #{vmid}\"", "end", "end" ]
Destroy the VirtualMaching removing it from the inventory and deleting the disk files
[ "Destroy", "the", "VirtualMaching", "removing", "it", "from", "the", "inventory", "and", "deleting", "the", "disk", "files" ]
ac02f2ef1b6294dfaa811fe638250cb3c000eeb6
https://github.com/maintux/esx/blob/ac02f2ef1b6294dfaa811fe638250cb3c000eeb6/lib/esx.rb#L524-L532
1,664
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb
RI.AttributeFormatter.write_attribute_text
def write_attribute_text(prefix, line) print prefix line.each do |achar| print achar.char end puts end
ruby
def write_attribute_text(prefix, line) print prefix line.each do |achar| print achar.char end puts end
[ "def", "write_attribute_text", "(", "prefix", ",", "line", ")", "print", "prefix", "line", ".", "each", "do", "|", "achar", "|", "print", "achar", ".", "char", "end", "puts", "end" ]
overridden in specific formatters
[ "overridden", "in", "specific", "formatters" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb#L331-L337
1,665
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb
RI.OverstrikeFormatter.bold_print
def bold_print(text) text.split(//).each do |ch| print ch, BS, ch end end
ruby
def bold_print(text) text.split(//).each do |ch| print ch, BS, ch end end
[ "def", "bold_print", "(", "text", ")", "text", ".", "split", "(", "/", "/", ")", ".", "each", "do", "|", "ch", "|", "print", "ch", ",", "BS", ",", "ch", "end", "end" ]
draw a string in bold
[ "draw", "a", "string", "in", "bold" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb#L390-L394
1,666
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb
RI.SimpleFormatter.display_heading
def display_heading(text, level, indent) text = strip_attributes(text) case level when 1 puts "= " + text.upcase when 2 puts "-- " + text else print indent, text, "\n" end end
ruby
def display_heading(text, level, indent) text = strip_attributes(text) case level when 1 puts "= " + text.upcase when 2 puts "-- " + text else print indent, text, "\n" end end
[ "def", "display_heading", "(", "text", ",", "level", ",", "indent", ")", "text", "=", "strip_attributes", "(", "text", ")", "case", "level", "when", "1", "puts", "\"= \"", "+", "text", ".", "upcase", "when", "2", "puts", "\"-- \"", "+", "text", "else", "print", "indent", ",", "text", ",", "\"\\n\"", "end", "end" ]
Place heading level indicators inline with heading.
[ "Place", "heading", "level", "indicators", "inline", "with", "heading", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/ri/ri_formatter.rb#L633-L643
1,667
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb
Rack.Request.POST
def POST if @env["rack.request.form_input"].eql? @env["rack.input"] @env["rack.request.form_hash"] elsif form_data? || parseable_data? @env["rack.request.form_input"] = @env["rack.input"] unless @env["rack.request.form_hash"] = Utils::Multipart.parse_multipart(env) form_vars = @env["rack.input"].read # Fix for Safari Ajax postings that always append \0 form_vars.sub!(/\0\z/, '') @env["rack.request.form_vars"] = form_vars @env["rack.request.form_hash"] = Utils.parse_nested_query(form_vars) @env["rack.input"].rewind end @env["rack.request.form_hash"] else {} end end
ruby
def POST if @env["rack.request.form_input"].eql? @env["rack.input"] @env["rack.request.form_hash"] elsif form_data? || parseable_data? @env["rack.request.form_input"] = @env["rack.input"] unless @env["rack.request.form_hash"] = Utils::Multipart.parse_multipart(env) form_vars = @env["rack.input"].read # Fix for Safari Ajax postings that always append \0 form_vars.sub!(/\0\z/, '') @env["rack.request.form_vars"] = form_vars @env["rack.request.form_hash"] = Utils.parse_nested_query(form_vars) @env["rack.input"].rewind end @env["rack.request.form_hash"] else {} end end
[ "def", "POST", "if", "@env", "[", "\"rack.request.form_input\"", "]", ".", "eql?", "@env", "[", "\"rack.input\"", "]", "@env", "[", "\"rack.request.form_hash\"", "]", "elsif", "form_data?", "||", "parseable_data?", "@env", "[", "\"rack.request.form_input\"", "]", "=", "@env", "[", "\"rack.input\"", "]", "unless", "@env", "[", "\"rack.request.form_hash\"", "]", "=", "Utils", "::", "Multipart", ".", "parse_multipart", "(", "env", ")", "form_vars", "=", "@env", "[", "\"rack.input\"", "]", ".", "read", "# Fix for Safari Ajax postings that always append \\0", "form_vars", ".", "sub!", "(", "/", "\\0", "\\z", "/", ",", "''", ")", "@env", "[", "\"rack.request.form_vars\"", "]", "=", "form_vars", "@env", "[", "\"rack.request.form_hash\"", "]", "=", "Utils", ".", "parse_nested_query", "(", "form_vars", ")", "@env", "[", "\"rack.input\"", "]", ".", "rewind", "end", "@env", "[", "\"rack.request.form_hash\"", "]", "else", "{", "}", "end", "end" ]
Returns the data recieved in the request body. This method support both application/x-www-form-urlencoded and multipart/form-data.
[ "Returns", "the", "data", "recieved", "in", "the", "request", "body", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb#L127-L148
1,668
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb
Rack.Request.url
def url url = scheme + "://" url << host if scheme == "https" && port != 443 || scheme == "http" && port != 80 url << ":#{port}" end url << fullpath url end
ruby
def url url = scheme + "://" url << host if scheme == "https" && port != 443 || scheme == "http" && port != 80 url << ":#{port}" end url << fullpath url end
[ "def", "url", "url", "=", "scheme", "+", "\"://\"", "url", "<<", "host", "if", "scheme", "==", "\"https\"", "&&", "port", "!=", "443", "||", "scheme", "==", "\"http\"", "&&", "port", "!=", "80", "url", "<<", "\":#{port}\"", "end", "url", "<<", "fullpath", "url", "end" ]
Tries to return a remake of the original request URL as a string.
[ "Tries", "to", "return", "a", "remake", "of", "the", "original", "request", "URL", "as", "a", "string", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb#L204-L216
1,669
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb
DRb.DRbProtocol.open
def open(uri, config, first=true) @protocol.each do |prot| begin return prot.open(uri, config) rescue DRbBadScheme rescue DRbConnError raise($!) rescue raise(DRbConnError, "#{uri} - #{$!.inspect}") end end if first && (config[:auto_load] != false) auto_load(uri, config) return open(uri, config, false) end raise DRbBadURI, 'can\'t parse uri:' + uri end
ruby
def open(uri, config, first=true) @protocol.each do |prot| begin return prot.open(uri, config) rescue DRbBadScheme rescue DRbConnError raise($!) rescue raise(DRbConnError, "#{uri} - #{$!.inspect}") end end if first && (config[:auto_load] != false) auto_load(uri, config) return open(uri, config, false) end raise DRbBadURI, 'can\'t parse uri:' + uri end
[ "def", "open", "(", "uri", ",", "config", ",", "first", "=", "true", ")", "@protocol", ".", "each", "do", "|", "prot", "|", "begin", "return", "prot", ".", "open", "(", "uri", ",", "config", ")", "rescue", "DRbBadScheme", "rescue", "DRbConnError", "raise", "(", "$!", ")", "rescue", "raise", "(", "DRbConnError", ",", "\"#{uri} - #{$!.inspect}\"", ")", "end", "end", "if", "first", "&&", "(", "config", "[", ":auto_load", "]", "!=", "false", ")", "auto_load", "(", "uri", ",", "config", ")", "return", "open", "(", "uri", ",", "config", ",", "false", ")", "end", "raise", "DRbBadURI", ",", "'can\\'t parse uri:'", "+", "uri", "end" ]
Open a client connection to +uri+ with the configuration +config+. The DRbProtocol module asks each registered protocol in turn to try to open the URI. Each protocol signals that it does not handle that URI by raising a DRbBadScheme error. If no protocol recognises the URI, then a DRbBadURI error is raised. If a protocol accepts the URI, but an error occurs in opening it, a DRbConnError is raised.
[ "Open", "a", "client", "connection", "to", "+", "uri", "+", "with", "the", "configuration", "+", "config", "+", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L758-L774
1,670
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb
DRb.DRbProtocol.open_server
def open_server(uri, config, first=true) @protocol.each do |prot| begin return prot.open_server(uri, config) rescue DRbBadScheme end end if first && (config[:auto_load] != false) auto_load(uri, config) return open_server(uri, config, false) end raise DRbBadURI, 'can\'t parse uri:' + uri end
ruby
def open_server(uri, config, first=true) @protocol.each do |prot| begin return prot.open_server(uri, config) rescue DRbBadScheme end end if first && (config[:auto_load] != false) auto_load(uri, config) return open_server(uri, config, false) end raise DRbBadURI, 'can\'t parse uri:' + uri end
[ "def", "open_server", "(", "uri", ",", "config", ",", "first", "=", "true", ")", "@protocol", ".", "each", "do", "|", "prot", "|", "begin", "return", "prot", ".", "open_server", "(", "uri", ",", "config", ")", "rescue", "DRbBadScheme", "end", "end", "if", "first", "&&", "(", "config", "[", ":auto_load", "]", "!=", "false", ")", "auto_load", "(", "uri", ",", "config", ")", "return", "open_server", "(", "uri", ",", "config", ",", "false", ")", "end", "raise", "DRbBadURI", ",", "'can\\'t parse uri:'", "+", "uri", "end" ]
Open a server listening for connections at +uri+ with configuration +config+. The DRbProtocol module asks each registered protocol in turn to try to open a server at the URI. Each protocol signals that it does not handle that URI by raising a DRbBadScheme error. If no protocol recognises the URI, then a DRbBadURI error is raised. If a protocol accepts the URI, but an error occurs in opening it, the underlying error is passed on to the caller.
[ "Open", "a", "server", "listening", "for", "connections", "at", "+", "uri", "+", "with", "configuration", "+", "config", "+", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L786-L798
1,671
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb
DRb.DRbTCPSocket.send_request
def send_request(ref, msg_id, arg, b) @msg.send_request(stream, ref, msg_id, arg, b) end
ruby
def send_request(ref, msg_id, arg, b) @msg.send_request(stream, ref, msg_id, arg, b) end
[ "def", "send_request", "(", "ref", ",", "msg_id", ",", "arg", ",", "b", ")", "@msg", ".", "send_request", "(", "stream", ",", "ref", ",", "msg_id", ",", "arg", ",", "b", ")", "end" ]
On the client side, send a request to the server.
[ "On", "the", "client", "side", "send", "a", "request", "to", "the", "server", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L937-L939
1,672
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb
DRb.DRbObject.method_missing
def method_missing(msg_id, *a, &b) if DRb.here?(@uri) obj = DRb.to_obj(@ref) DRb.current_server.check_insecure_method(obj, msg_id) return obj.__send__(msg_id, *a, &b) end succ, result = self.class.with_friend(@uri) do DRbConn.open(@uri) do |conn| conn.send_message(self, msg_id, a, b) end end if succ return result elsif DRbUnknown === result raise result else bt = self.class.prepare_backtrace(@uri, result) result.set_backtrace(bt + caller) raise result end end
ruby
def method_missing(msg_id, *a, &b) if DRb.here?(@uri) obj = DRb.to_obj(@ref) DRb.current_server.check_insecure_method(obj, msg_id) return obj.__send__(msg_id, *a, &b) end succ, result = self.class.with_friend(@uri) do DRbConn.open(@uri) do |conn| conn.send_message(self, msg_id, a, b) end end if succ return result elsif DRbUnknown === result raise result else bt = self.class.prepare_backtrace(@uri, result) result.set_backtrace(bt + caller) raise result end end
[ "def", "method_missing", "(", "msg_id", ",", "*", "a", ",", "&", "b", ")", "if", "DRb", ".", "here?", "(", "@uri", ")", "obj", "=", "DRb", ".", "to_obj", "(", "@ref", ")", "DRb", ".", "current_server", ".", "check_insecure_method", "(", "obj", ",", "msg_id", ")", "return", "obj", ".", "__send__", "(", "msg_id", ",", "a", ",", "b", ")", "end", "succ", ",", "result", "=", "self", ".", "class", ".", "with_friend", "(", "@uri", ")", "do", "DRbConn", ".", "open", "(", "@uri", ")", "do", "|", "conn", "|", "conn", ".", "send_message", "(", "self", ",", "msg_id", ",", "a", ",", "b", ")", "end", "end", "if", "succ", "return", "result", "elsif", "DRbUnknown", "===", "result", "raise", "result", "else", "bt", "=", "self", ".", "class", ".", "prepare_backtrace", "(", "@uri", ",", "result", ")", "result", ".", "set_backtrace", "(", "bt", "+", "caller", ")", "raise", "result", "end", "end" ]
Routes method calls to the referenced object.
[ "Routes", "method", "calls", "to", "the", "referenced", "object", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1114-L1136
1,673
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb
DRb.DRbServer.stop_service
def stop_service DRb.remove_server(self) if Thread.current['DRb'] && Thread.current['DRb']['server'] == self Thread.current['DRb']['stop_service'] = true else @thread.kill end end
ruby
def stop_service DRb.remove_server(self) if Thread.current['DRb'] && Thread.current['DRb']['server'] == self Thread.current['DRb']['stop_service'] = true else @thread.kill end end
[ "def", "stop_service", "DRb", ".", "remove_server", "(", "self", ")", "if", "Thread", ".", "current", "[", "'DRb'", "]", "&&", "Thread", ".", "current", "[", "'DRb'", "]", "[", "'server'", "]", "==", "self", "Thread", ".", "current", "[", "'DRb'", "]", "[", "'stop_service'", "]", "=", "true", "else", "@thread", ".", "kill", "end", "end" ]
Stop this server.
[ "Stop", "this", "server", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1427-L1434
1,674
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb
DRb.DRbServer.to_obj
def to_obj(ref) return front if ref.nil? return front[ref.to_s] if DRbURIOption === ref @idconv.to_obj(ref) end
ruby
def to_obj(ref) return front if ref.nil? return front[ref.to_s] if DRbURIOption === ref @idconv.to_obj(ref) end
[ "def", "to_obj", "(", "ref", ")", "return", "front", "if", "ref", ".", "nil?", "return", "front", "[", "ref", ".", "to_s", "]", "if", "DRbURIOption", "===", "ref", "@idconv", ".", "to_obj", "(", "ref", ")", "end" ]
Convert a dRuby reference to the local object it refers to.
[ "Convert", "a", "dRuby", "reference", "to", "the", "local", "object", "it", "refers", "to", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1437-L1441
1,675
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb
DRb.DRbServer.check_insecure_method
def check_insecure_method(obj, msg_id) return true if Proc === obj && msg_id == :__drb_yield raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id) if obj.private_methods.include?(msg_id.to_s) desc = any_to_s(obj) raise NoMethodError, "private method `#{msg_id}' called for #{desc}" elsif obj.protected_methods.include?(msg_id.to_s) desc = any_to_s(obj) raise NoMethodError, "protected method `#{msg_id}' called for #{desc}" else true end end
ruby
def check_insecure_method(obj, msg_id) return true if Proc === obj && msg_id == :__drb_yield raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id) if obj.private_methods.include?(msg_id.to_s) desc = any_to_s(obj) raise NoMethodError, "private method `#{msg_id}' called for #{desc}" elsif obj.protected_methods.include?(msg_id.to_s) desc = any_to_s(obj) raise NoMethodError, "protected method `#{msg_id}' called for #{desc}" else true end end
[ "def", "check_insecure_method", "(", "obj", ",", "msg_id", ")", "return", "true", "if", "Proc", "===", "obj", "&&", "msg_id", "==", ":__drb_yield", "raise", "(", "ArgumentError", ",", "\"#{any_to_s(msg_id)} is not a symbol\"", ")", "unless", "Symbol", "==", "msg_id", ".", "class", "raise", "(", "SecurityError", ",", "\"insecure method `#{msg_id}'\"", ")", "if", "insecure_method?", "(", "msg_id", ")", "if", "obj", ".", "private_methods", ".", "include?", "(", "msg_id", ".", "to_s", ")", "desc", "=", "any_to_s", "(", "obj", ")", "raise", "NoMethodError", ",", "\"private method `#{msg_id}' called for #{desc}\"", "elsif", "obj", ".", "protected_methods", ".", "include?", "(", "msg_id", ".", "to_s", ")", "desc", "=", "any_to_s", "(", "obj", ")", "raise", "NoMethodError", ",", "\"protected method `#{msg_id}' called for #{desc}\"", "else", "true", "end", "end" ]
Check that a method is callable via dRuby. +obj+ is the object we want to invoke the method on. +msg_id+ is the method name, as a Symbol. If the method is an insecure method (see #insecure_method?) a SecurityError is thrown. If the method is private or undefined, a NameError is thrown.
[ "Check", "that", "a", "method", "is", "callable", "via", "dRuby", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1505-L1519
1,676
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb
DRb.DRbServer.main_loop
def main_loop Thread.start(@protocol.accept) do |client| @grp.add Thread.current Thread.current['DRb'] = { 'client' => client , 'server' => self } loop do begin succ = false invoke_method = InvokeMethod.new(self, client) succ, result = invoke_method.perform if !succ && verbose p result result.backtrace.each do |x| puts x end end client.send_reply(succ, result) rescue nil ensure client.close unless succ if Thread.current['DRb']['stop_service'] Thread.new { stop_service } end break unless succ end end end end
ruby
def main_loop Thread.start(@protocol.accept) do |client| @grp.add Thread.current Thread.current['DRb'] = { 'client' => client , 'server' => self } loop do begin succ = false invoke_method = InvokeMethod.new(self, client) succ, result = invoke_method.perform if !succ && verbose p result result.backtrace.each do |x| puts x end end client.send_reply(succ, result) rescue nil ensure client.close unless succ if Thread.current['DRb']['stop_service'] Thread.new { stop_service } end break unless succ end end end end
[ "def", "main_loop", "Thread", ".", "start", "(", "@protocol", ".", "accept", ")", "do", "|", "client", "|", "@grp", ".", "add", "Thread", ".", "current", "Thread", ".", "current", "[", "'DRb'", "]", "=", "{", "'client'", "=>", "client", ",", "'server'", "=>", "self", "}", "loop", "do", "begin", "succ", "=", "false", "invoke_method", "=", "InvokeMethod", ".", "new", "(", "self", ",", "client", ")", "succ", ",", "result", "=", "invoke_method", ".", "perform", "if", "!", "succ", "&&", "verbose", "p", "result", "result", ".", "backtrace", ".", "each", "do", "|", "x", "|", "puts", "x", "end", "end", "client", ".", "send_reply", "(", "succ", ",", "result", ")", "rescue", "nil", "ensure", "client", ".", "close", "unless", "succ", "if", "Thread", ".", "current", "[", "'DRb'", "]", "[", "'stop_service'", "]", "Thread", ".", "new", "{", "stop_service", "}", "end", "break", "unless", "succ", "end", "end", "end", "end" ]
The main loop performed by a DRbServer's internal thread. Accepts a connection from a client, and starts up its own thread to handle it. This thread loops, receiving requests from the client, invoking them on a local object, and returning responses, until the client closes the connection or a local method call fails.
[ "The", "main", "loop", "performed", "by", "a", "DRbServer", "s", "internal", "thread", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/drb/drb.rb#L1618-L1644
1,677
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/jdbc_adapter/jdbc_postgre.rb
::JdbcSpec.PostgreSQL.supports_standard_conforming_strings?
def supports_standard_conforming_strings? # Temporarily set the client message level above error to prevent unintentional # error messages in the logs when working on a PostgreSQL database server that # does not support standard conforming strings. client_min_messages_old = client_min_messages self.client_min_messages = 'panic' # postgres-pr does not raise an exception when client_min_messages is set higher # than error and "SHOW standard_conforming_strings" fails, but returns an empty # PGresult instead. has_support = select('SHOW standard_conforming_strings').to_a[0][0] rescue false self.client_min_messages = client_min_messages_old has_support end
ruby
def supports_standard_conforming_strings? # Temporarily set the client message level above error to prevent unintentional # error messages in the logs when working on a PostgreSQL database server that # does not support standard conforming strings. client_min_messages_old = client_min_messages self.client_min_messages = 'panic' # postgres-pr does not raise an exception when client_min_messages is set higher # than error and "SHOW standard_conforming_strings" fails, but returns an empty # PGresult instead. has_support = select('SHOW standard_conforming_strings').to_a[0][0] rescue false self.client_min_messages = client_min_messages_old has_support end
[ "def", "supports_standard_conforming_strings?", "# Temporarily set the client message level above error to prevent unintentional", "# error messages in the logs when working on a PostgreSQL database server that", "# does not support standard conforming strings.", "client_min_messages_old", "=", "client_min_messages", "self", ".", "client_min_messages", "=", "'panic'", "# postgres-pr does not raise an exception when client_min_messages is set higher", "# than error and \"SHOW standard_conforming_strings\" fails, but returns an empty", "# PGresult instead.", "has_support", "=", "select", "(", "'SHOW standard_conforming_strings'", ")", ".", "to_a", "[", "0", "]", "[", "0", "]", "rescue", "false", "self", ".", "client_min_messages", "=", "client_min_messages_old", "has_support", "end" ]
Does PostgreSQL support standard conforming strings?
[ "Does", "PostgreSQL", "support", "standard", "conforming", "strings?" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activerecord-jdbc-adapter-0.9.7-java/lib/jdbc_adapter/jdbc_postgre.rb#L120-L133
1,678
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rdoctask.rb
Rake.RDocTask.define
def define if rdoc_task_name != "rdoc" desc "Build the RDOC HTML Files" else desc "Build the #{rdoc_task_name} HTML Files" end task rdoc_task_name desc "Force a rebuild of the RDOC files" task rerdoc_task_name => [clobber_task_name, rdoc_task_name] desc "Remove rdoc products" task clobber_task_name do rm_r rdoc_dir rescue nil end task :clobber => [clobber_task_name] directory @rdoc_dir task rdoc_task_name => [rdoc_target] file rdoc_target => @rdoc_files + [Rake.application.rakefile] do rm_r @rdoc_dir rescue nil @before_running_rdoc.call if @before_running_rdoc args = option_list + @rdoc_files if @external argstring = args.join(' ') sh %{ruby -Ivendor vendor/rd #{argstring}} else require 'rdoc/rdoc' RDoc::RDoc.new.document(args) end end self end
ruby
def define if rdoc_task_name != "rdoc" desc "Build the RDOC HTML Files" else desc "Build the #{rdoc_task_name} HTML Files" end task rdoc_task_name desc "Force a rebuild of the RDOC files" task rerdoc_task_name => [clobber_task_name, rdoc_task_name] desc "Remove rdoc products" task clobber_task_name do rm_r rdoc_dir rescue nil end task :clobber => [clobber_task_name] directory @rdoc_dir task rdoc_task_name => [rdoc_target] file rdoc_target => @rdoc_files + [Rake.application.rakefile] do rm_r @rdoc_dir rescue nil @before_running_rdoc.call if @before_running_rdoc args = option_list + @rdoc_files if @external argstring = args.join(' ') sh %{ruby -Ivendor vendor/rd #{argstring}} else require 'rdoc/rdoc' RDoc::RDoc.new.document(args) end end self end
[ "def", "define", "if", "rdoc_task_name", "!=", "\"rdoc\"", "desc", "\"Build the RDOC HTML Files\"", "else", "desc", "\"Build the #{rdoc_task_name} HTML Files\"", "end", "task", "rdoc_task_name", "desc", "\"Force a rebuild of the RDOC files\"", "task", "rerdoc_task_name", "=>", "[", "clobber_task_name", ",", "rdoc_task_name", "]", "desc", "\"Remove rdoc products\"", "task", "clobber_task_name", "do", "rm_r", "rdoc_dir", "rescue", "nil", "end", "task", ":clobber", "=>", "[", "clobber_task_name", "]", "directory", "@rdoc_dir", "task", "rdoc_task_name", "=>", "[", "rdoc_target", "]", "file", "rdoc_target", "=>", "@rdoc_files", "+", "[", "Rake", ".", "application", ".", "rakefile", "]", "do", "rm_r", "@rdoc_dir", "rescue", "nil", "@before_running_rdoc", ".", "call", "if", "@before_running_rdoc", "args", "=", "option_list", "+", "@rdoc_files", "if", "@external", "argstring", "=", "args", ".", "join", "(", "' '", ")", "sh", "%{ruby -Ivendor vendor/rd #{argstring}}", "else", "require", "'rdoc/rdoc'", "RDoc", "::", "RDoc", ".", "new", ".", "document", "(", "args", ")", "end", "end", "self", "end" ]
Create an RDoc task with the given name. See the RDocTask class overview for documentation. Create the tasks defined by this task lib.
[ "Create", "an", "RDoc", "task", "with", "the", "given", "name", ".", "See", "the", "RDocTask", "class", "overview", "for", "documentation", ".", "Create", "the", "tasks", "defined", "by", "this", "task", "lib", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rdoctask.rb#L111-L144
1,679
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/runit/assert.rb
RUNIT.Assert.assert_match
def assert_match(actual_string, expected_re, message="") _wrap_assertion { full_message = build_message(message, "Expected <?> to match <?>", actual_string, expected_re) assert_block(full_message) { expected_re =~ actual_string } Regexp.last_match } end
ruby
def assert_match(actual_string, expected_re, message="") _wrap_assertion { full_message = build_message(message, "Expected <?> to match <?>", actual_string, expected_re) assert_block(full_message) { expected_re =~ actual_string } Regexp.last_match } end
[ "def", "assert_match", "(", "actual_string", ",", "expected_re", ",", "message", "=", "\"\"", ")", "_wrap_assertion", "{", "full_message", "=", "build_message", "(", "message", ",", "\"Expected <?> to match <?>\"", ",", "actual_string", ",", "expected_re", ")", "assert_block", "(", "full_message", ")", "{", "expected_re", "=~", "actual_string", "}", "Regexp", ".", "last_match", "}", "end" ]
To deal with the fact that RubyUnit does not check that the regular expression is, indeed, a regular expression, if it is not, we do our own assertion using the same semantics as RubyUnit
[ "To", "deal", "with", "the", "fact", "that", "RubyUnit", "does", "not", "check", "that", "the", "regular", "expression", "is", "indeed", "a", "regular", "expression", "if", "it", "is", "not", "we", "do", "our", "own", "assertion", "using", "the", "same", "semantics", "as", "RubyUnit" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/runit/assert.rb#L23-L31
1,680
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/gempackagetask.rb
Rake.GemPackageTask.init
def init(gem) super(gem.name, gem.version) @gem_spec = gem @package_files += gem_spec.files if gem_spec.files end
ruby
def init(gem) super(gem.name, gem.version) @gem_spec = gem @package_files += gem_spec.files if gem_spec.files end
[ "def", "init", "(", "gem", ")", "super", "(", "gem", ".", "name", ",", "gem", ".", "version", ")", "@gem_spec", "=", "gem", "@package_files", "+=", "gem_spec", ".", "files", "if", "gem_spec", ".", "files", "end" ]
Create a GEM Package task library. Automatically define the gem if a block is given. If no block is supplied, then +define+ needs to be called to define the task. Initialization tasks without the "yield self" or define operations.
[ "Create", "a", "GEM", "Package", "task", "library", ".", "Automatically", "define", "the", "gem", "if", "a", "block", "is", "given", ".", "If", "no", "block", "is", "supplied", "then", "+", "define", "+", "needs", "to", "be", "called", "to", "define", "the", "task", ".", "Initialization", "tasks", "without", "the", "yield", "self", "or", "define", "operations", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/gempackagetask.rb#L64-L68
1,681
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/xml_mini/rexml.rb
ActiveSupport.XmlMini_REXML.parse
def parse(string) require 'rexml/document' unless defined?(REXML::Document) doc = REXML::Document.new(string) merge_element!({}, doc.root) end
ruby
def parse(string) require 'rexml/document' unless defined?(REXML::Document) doc = REXML::Document.new(string) merge_element!({}, doc.root) end
[ "def", "parse", "(", "string", ")", "require", "'rexml/document'", "unless", "defined?", "(", "REXML", "::", "Document", ")", "doc", "=", "REXML", "::", "Document", ".", "new", "(", "string", ")", "merge_element!", "(", "{", "}", ",", "doc", ".", "root", ")", "end" ]
Parse an XML Document string into a simple hash Same as XmlSimple::xml_in but doesn't shoot itself in the foot, and uses the defaults from ActiveSupport string:: XML Document string to parse
[ "Parse", "an", "XML", "Document", "string", "into", "a", "simple", "hash" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/xml_mini/rexml.rb#L15-L19
1,682
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_html.rb
SM.ToHtml.init_tags
def init_tags @attr_tags = [ InlineTag.new(SM::Attribute.bitmap_for(:BOLD), "<b>", "</b>"), InlineTag.new(SM::Attribute.bitmap_for(:TT), "<tt>", "</tt>"), InlineTag.new(SM::Attribute.bitmap_for(:EM), "<em>", "</em>"), ] end
ruby
def init_tags @attr_tags = [ InlineTag.new(SM::Attribute.bitmap_for(:BOLD), "<b>", "</b>"), InlineTag.new(SM::Attribute.bitmap_for(:TT), "<tt>", "</tt>"), InlineTag.new(SM::Attribute.bitmap_for(:EM), "<em>", "</em>"), ] end
[ "def", "init_tags", "@attr_tags", "=", "[", "InlineTag", ".", "new", "(", "SM", "::", "Attribute", ".", "bitmap_for", "(", ":BOLD", ")", ",", "\"<b>\"", ",", "\"</b>\"", ")", ",", "InlineTag", ".", "new", "(", "SM", "::", "Attribute", ".", "bitmap_for", "(", ":TT", ")", ",", "\"<tt>\"", ",", "\"</tt>\"", ")", ",", "InlineTag", ".", "new", "(", "SM", "::", "Attribute", ".", "bitmap_for", "(", ":EM", ")", ",", "\"<em>\"", ",", "\"</em>\"", ")", ",", "]", "end" ]
Set up the standard mapping of attributes to HTML tags
[ "Set", "up", "the", "standard", "mapping", "of", "attributes", "to", "HTML", "tags" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_html.rb#L28-L34
1,683
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_html.rb
SM.ToHtml.add_tag
def add_tag(name, start, stop) @attr_tags << InlineTag.new(SM::Attribute.bitmap_for(name), start, stop) end
ruby
def add_tag(name, start, stop) @attr_tags << InlineTag.new(SM::Attribute.bitmap_for(name), start, stop) end
[ "def", "add_tag", "(", "name", ",", "start", ",", "stop", ")", "@attr_tags", "<<", "InlineTag", ".", "new", "(", "SM", "::", "Attribute", ".", "bitmap_for", "(", "name", ")", ",", "start", ",", "stop", ")", "end" ]
Add a new set of HTML tags for an attribute. We allow separate start and end tags for flexibility
[ "Add", "a", "new", "set", "of", "HTML", "tags", "for", "an", "attribute", ".", "We", "allow", "separate", "start", "and", "end", "tags", "for", "flexibility" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/to_html.rb#L40-L42
1,684
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/net/http.rb
Net.HTTPHeader.set_form_data
def set_form_data(params, sep = '&') self.body = params.map {|k,v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" }.join(sep) self.content_type = 'application/x-www-form-urlencoded' end
ruby
def set_form_data(params, sep = '&') self.body = params.map {|k,v| "#{urlencode(k.to_s)}=#{urlencode(v.to_s)}" }.join(sep) self.content_type = 'application/x-www-form-urlencoded' end
[ "def", "set_form_data", "(", "params", ",", "sep", "=", "'&'", ")", "self", ".", "body", "=", "params", ".", "map", "{", "|", "k", ",", "v", "|", "\"#{urlencode(k.to_s)}=#{urlencode(v.to_s)}\"", "}", ".", "join", "(", "sep", ")", "self", ".", "content_type", "=", "'application/x-www-form-urlencoded'", "end" ]
Set header fields and a body from HTML form data. +params+ should be a Hash containing HTML form data. Optional argument +sep+ means data record separator. This method also set Content-Type: header field to application/x-www-form-urlencoded.
[ "Set", "header", "fields", "and", "a", "body", "from", "HTML", "form", "data", ".", "+", "params", "+", "should", "be", "a", "Hash", "containing", "HTML", "form", "data", ".", "Optional", "argument", "+", "sep", "+", "means", "data", "record", "separator", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/net/http.rb#L1432-L1435
1,685
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb
Rinda.Tuple.each
def each # FIXME if Hash === @tuple @tuple.each { |k, v| yield(k, v) } else @tuple.each_with_index { |v, k| yield(k, v) } end end
ruby
def each # FIXME if Hash === @tuple @tuple.each { |k, v| yield(k, v) } else @tuple.each_with_index { |v, k| yield(k, v) } end end
[ "def", "each", "# FIXME", "if", "Hash", "===", "@tuple", "@tuple", ".", "each", "{", "|", "k", ",", "v", "|", "yield", "(", "k", ",", "v", ")", "}", "else", "@tuple", ".", "each_with_index", "{", "|", "v", ",", "k", "|", "yield", "(", "k", ",", "v", ")", "}", "end", "end" ]
Iterate through the tuple, yielding the index or key, and the value, thus ensuring arrays are iterated similarly to hashes.
[ "Iterate", "through", "the", "tuple", "yielding", "the", "index", "or", "key", "and", "the", "value", "thus", "ensuring", "arrays", "are", "iterated", "similarly", "to", "hashes", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb#L84-L90
1,686
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb
Rinda.Tuple.init_with_ary
def init_with_ary(ary) @tuple = Array.new(ary.size) @tuple.size.times do |i| @tuple[i] = ary[i] end end
ruby
def init_with_ary(ary) @tuple = Array.new(ary.size) @tuple.size.times do |i| @tuple[i] = ary[i] end end
[ "def", "init_with_ary", "(", "ary", ")", "@tuple", "=", "Array", ".", "new", "(", "ary", ".", "size", ")", "@tuple", ".", "size", ".", "times", "do", "|", "i", "|", "@tuple", "[", "i", "]", "=", "ary", "[", "i", "]", "end", "end" ]
Munges +ary+ into a valid Tuple.
[ "Munges", "+", "ary", "+", "into", "a", "valid", "Tuple", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb#L107-L112
1,687
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb
Rinda.Tuple.init_with_hash
def init_with_hash(hash) @tuple = Hash.new hash.each do |k, v| raise InvalidHashTupleKey unless String === k @tuple[k] = v end end
ruby
def init_with_hash(hash) @tuple = Hash.new hash.each do |k, v| raise InvalidHashTupleKey unless String === k @tuple[k] = v end end
[ "def", "init_with_hash", "(", "hash", ")", "@tuple", "=", "Hash", ".", "new", "hash", ".", "each", "do", "|", "k", ",", "v", "|", "raise", "InvalidHashTupleKey", "unless", "String", "===", "k", "@tuple", "[", "k", "]", "=", "v", "end", "end" ]
Ensures +hash+ is a valid Tuple.
[ "Ensures", "+", "hash", "+", "is", "a", "valid", "Tuple", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rinda/rinda.rb#L117-L123
1,688
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/xsd/datatypes.rb
XSD.XSDFloat.narrow32bit
def narrow32bit(f) if f.nan? || f.infinite? f elsif f.abs < MIN_POSITIVE_SINGLE XSDFloat.positive?(f) ? POSITIVE_ZERO : NEGATIVE_ZERO else f end end
ruby
def narrow32bit(f) if f.nan? || f.infinite? f elsif f.abs < MIN_POSITIVE_SINGLE XSDFloat.positive?(f) ? POSITIVE_ZERO : NEGATIVE_ZERO else f end end
[ "def", "narrow32bit", "(", "f", ")", "if", "f", ".", "nan?", "||", "f", ".", "infinite?", "f", "elsif", "f", ".", "abs", "<", "MIN_POSITIVE_SINGLE", "XSDFloat", ".", "positive?", "(", "f", ")", "?", "POSITIVE_ZERO", ":", "NEGATIVE_ZERO", "else", "f", "end", "end" ]
Convert to single-precision 32-bit floating point value.
[ "Convert", "to", "single", "-", "precision", "32", "-", "bit", "floating", "point", "value", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/xsd/datatypes.rb#L352-L360
1,689
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/xsd/datatypes.rb
XSD.XSDHexBinary.set_encoded
def set_encoded(value) if /^[0-9a-fA-F]*$/ !~ value raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.") end @data = String.new(value).strip @is_nil = false end
ruby
def set_encoded(value) if /^[0-9a-fA-F]*$/ !~ value raise ValueSpaceError.new("#{ type }: cannot accept '#{ value }'.") end @data = String.new(value).strip @is_nil = false end
[ "def", "set_encoded", "(", "value", ")", "if", "/", "/", "!~", "value", "raise", "ValueSpaceError", ".", "new", "(", "\"#{ type }: cannot accept '#{ value }'.\"", ")", "end", "@data", "=", "String", ".", "new", "(", "value", ")", ".", "strip", "@is_nil", "=", "false", "end" ]
String in Ruby could be a binary.
[ "String", "in", "Ruby", "could", "be", "a", "binary", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/xsd/datatypes.rb#L880-L886
1,690
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/rescuable.rb
ActiveSupport.Rescuable.rescue_with_handler
def rescue_with_handler(exception) if handler = handler_for_rescue(exception) handler.arity != 0 ? handler.call(exception) : handler.call true # don't rely on the return value of the handler end end
ruby
def rescue_with_handler(exception) if handler = handler_for_rescue(exception) handler.arity != 0 ? handler.call(exception) : handler.call true # don't rely on the return value of the handler end end
[ "def", "rescue_with_handler", "(", "exception", ")", "if", "handler", "=", "handler_for_rescue", "(", "exception", ")", "handler", ".", "arity", "!=", "0", "?", "handler", ".", "call", "(", "exception", ")", ":", "handler", ".", "call", "true", "# don't rely on the return value of the handler", "end", "end" ]
Tries to rescue the exception by looking up and calling a registered handler.
[ "Tries", "to", "rescue", "the", "exception", "by", "looking", "up", "and", "calling", "a", "registered", "handler", "." ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/rescuable.rb#L71-L76
1,691
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb
SM.PreProcess.handle
def handle(text) text.gsub!(/^([ \t#]*):(\w+):\s*(.+)?\n/) do prefix = $1 directive = $2.downcase param = $3 case directive when "include" filename = param.split[0] include_file(filename, prefix) else yield(directive, param) end end end
ruby
def handle(text) text.gsub!(/^([ \t#]*):(\w+):\s*(.+)?\n/) do prefix = $1 directive = $2.downcase param = $3 case directive when "include" filename = param.split[0] include_file(filename, prefix) else yield(directive, param) end end end
[ "def", "handle", "(", "text", ")", "text", ".", "gsub!", "(", "/", "\\t", "\\w", "\\s", "\\n", "/", ")", "do", "prefix", "=", "$1", "directive", "=", "$2", ".", "downcase", "param", "=", "$3", "case", "directive", "when", "\"include\"", "filename", "=", "param", ".", "split", "[", "0", "]", "include_file", "(", "filename", ",", "prefix", ")", "else", "yield", "(", "directive", ",", "param", ")", "end", "end", "end" ]
Look for common options in a chunk of text. Options that we don't handle are passed back to our caller as |directive, param|
[ "Look", "for", "common", "options", "in", "a", "chunk", "of", "text", ".", "Options", "that", "we", "don", "t", "handle", "are", "passed", "back", "to", "our", "caller", "as", "|directive", "param|" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb#L20-L35
1,692
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb
SM.PreProcess.include_file
def include_file(name, indent) if (full_name = find_include_file(name)) content = File.open(full_name) {|f| f.read} # strip leading '#'s, but only if all lines start with them if content =~ /^[^#]/ content.gsub(/^/, indent) else content.gsub(/^#?/, indent) end else $stderr.puts "Couldn't find file to include: '#{name}'" '' end end
ruby
def include_file(name, indent) if (full_name = find_include_file(name)) content = File.open(full_name) {|f| f.read} # strip leading '#'s, but only if all lines start with them if content =~ /^[^#]/ content.gsub(/^/, indent) else content.gsub(/^#?/, indent) end else $stderr.puts "Couldn't find file to include: '#{name}'" '' end end
[ "def", "include_file", "(", "name", ",", "indent", ")", "if", "(", "full_name", "=", "find_include_file", "(", "name", ")", ")", "content", "=", "File", ".", "open", "(", "full_name", ")", "{", "|", "f", "|", "f", ".", "read", "}", "# strip leading '#'s, but only if all lines start with them", "if", "content", "=~", "/", "/", "content", ".", "gsub", "(", "/", "/", ",", "indent", ")", "else", "content", ".", "gsub", "(", "/", "/", ",", "indent", ")", "end", "else", "$stderr", ".", "puts", "\"Couldn't find file to include: '#{name}'\"", "''", "end", "end" ]
Include a file, indenting it correctly
[ "Include", "a", "file", "indenting", "it", "correctly" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb#L43-L56
1,693
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb
SM.PreProcess.find_include_file
def find_include_file(name) to_search = [ File.dirname(@input_file_name) ].concat @include_path to_search.each do |dir| full_name = File.join(dir, name) stat = File.stat(full_name) rescue next return full_name if stat.readable? end nil end
ruby
def find_include_file(name) to_search = [ File.dirname(@input_file_name) ].concat @include_path to_search.each do |dir| full_name = File.join(dir, name) stat = File.stat(full_name) rescue next return full_name if stat.readable? end nil end
[ "def", "find_include_file", "(", "name", ")", "to_search", "=", "[", "File", ".", "dirname", "(", "@input_file_name", ")", "]", ".", "concat", "@include_path", "to_search", ".", "each", "do", "|", "dir", "|", "full_name", "=", "File", ".", "join", "(", "dir", ",", "name", ")", "stat", "=", "File", ".", "stat", "(", "full_name", ")", "rescue", "next", "return", "full_name", "if", "stat", ".", "readable?", "end", "nil", "end" ]
Look for the given file in the directory containing the current file, and then in each of the directories specified in the RDOC_INCLUDE path
[ "Look", "for", "the", "given", "file", "in", "the", "directory", "containing", "the", "current", "file", "and", "then", "in", "each", "of", "the", "directories", "specified", "in", "the", "RDOC_INCLUDE", "path" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/markup/simple_markup/preprocess.rb#L62-L70
1,694
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb
RDoc.Fortran95parser.parse_subprogram
def parse_subprogram(subprogram, params, comment, code, before_contains=nil, function=nil, prefix=nil) subprogram.singleton = false prefix = "" if !prefix arguments = params.sub(/\(/, "").sub(/\)/, "").split(",") if params args_comment, params_opt = find_arguments(arguments, code.sub(/^s*?contains\s*?(!.*?)?$.*/im, ""), nil, nil, true) params_opt = "( " + params_opt + " ) " if params_opt subprogram.params = params_opt || "" namelist_comment = find_namelists(code, before_contains) block_comment = find_comments comment if function subprogram.comment = "<b><em> Function </em></b> :: <em>#{prefix}</em>\n" else subprogram.comment = "<b><em> Subroutine </em></b> :: <em>#{prefix}</em>\n" end subprogram.comment << args_comment if args_comment subprogram.comment << block_comment if block_comment subprogram.comment << namelist_comment if namelist_comment # For output source code subprogram.start_collecting_tokens subprogram.add_token Token.new(1,1).set_text(code) subprogram end
ruby
def parse_subprogram(subprogram, params, comment, code, before_contains=nil, function=nil, prefix=nil) subprogram.singleton = false prefix = "" if !prefix arguments = params.sub(/\(/, "").sub(/\)/, "").split(",") if params args_comment, params_opt = find_arguments(arguments, code.sub(/^s*?contains\s*?(!.*?)?$.*/im, ""), nil, nil, true) params_opt = "( " + params_opt + " ) " if params_opt subprogram.params = params_opt || "" namelist_comment = find_namelists(code, before_contains) block_comment = find_comments comment if function subprogram.comment = "<b><em> Function </em></b> :: <em>#{prefix}</em>\n" else subprogram.comment = "<b><em> Subroutine </em></b> :: <em>#{prefix}</em>\n" end subprogram.comment << args_comment if args_comment subprogram.comment << block_comment if block_comment subprogram.comment << namelist_comment if namelist_comment # For output source code subprogram.start_collecting_tokens subprogram.add_token Token.new(1,1).set_text(code) subprogram end
[ "def", "parse_subprogram", "(", "subprogram", ",", "params", ",", "comment", ",", "code", ",", "before_contains", "=", "nil", ",", "function", "=", "nil", ",", "prefix", "=", "nil", ")", "subprogram", ".", "singleton", "=", "false", "prefix", "=", "\"\"", "if", "!", "prefix", "arguments", "=", "params", ".", "sub", "(", "/", "\\(", "/", ",", "\"\"", ")", ".", "sub", "(", "/", "\\)", "/", ",", "\"\"", ")", ".", "split", "(", "\",\"", ")", "if", "params", "args_comment", ",", "params_opt", "=", "find_arguments", "(", "arguments", ",", "code", ".", "sub", "(", "/", "\\s", "/im", ",", "\"\"", ")", ",", "nil", ",", "nil", ",", "true", ")", "params_opt", "=", "\"( \"", "+", "params_opt", "+", "\" ) \"", "if", "params_opt", "subprogram", ".", "params", "=", "params_opt", "||", "\"\"", "namelist_comment", "=", "find_namelists", "(", "code", ",", "before_contains", ")", "block_comment", "=", "find_comments", "comment", "if", "function", "subprogram", ".", "comment", "=", "\"<b><em> Function </em></b> :: <em>#{prefix}</em>\\n\"", "else", "subprogram", ".", "comment", "=", "\"<b><em> Subroutine </em></b> :: <em>#{prefix}</em>\\n\"", "end", "subprogram", ".", "comment", "<<", "args_comment", "if", "args_comment", "subprogram", ".", "comment", "<<", "block_comment", "if", "block_comment", "subprogram", ".", "comment", "<<", "namelist_comment", "if", "namelist_comment", "# For output source code", "subprogram", ".", "start_collecting_tokens", "subprogram", ".", "add_token", "Token", ".", "new", "(", "1", ",", "1", ")", ".", "set_text", "(", "code", ")", "subprogram", "end" ]
End of parse_program_or_module Parse arguments, comment, code of subroutine and function. Return AnyMethod object.
[ "End", "of", "parse_program_or_module" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1007-L1034
1,695
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb
RDoc.Fortran95parser.collect_first_comment
def collect_first_comment(body) comment = "" not_comment = "" comment_start = false comment_end = false body.split("\n").each{ |line| if comment_end not_comment << line not_comment << "\n" elsif /^\s*?!\s?(.*)$/i =~ line comment_start = true comment << $1 comment << "\n" elsif /^\s*?$/i =~ line comment_end = true if comment_start && COMMENTS_ARE_UPPER else comment_end = true not_comment << line not_comment << "\n" end } return comment, not_comment end
ruby
def collect_first_comment(body) comment = "" not_comment = "" comment_start = false comment_end = false body.split("\n").each{ |line| if comment_end not_comment << line not_comment << "\n" elsif /^\s*?!\s?(.*)$/i =~ line comment_start = true comment << $1 comment << "\n" elsif /^\s*?$/i =~ line comment_end = true if comment_start && COMMENTS_ARE_UPPER else comment_end = true not_comment << line not_comment << "\n" end } return comment, not_comment end
[ "def", "collect_first_comment", "(", "body", ")", "comment", "=", "\"\"", "not_comment", "=", "\"\"", "comment_start", "=", "false", "comment_end", "=", "false", "body", ".", "split", "(", "\"\\n\"", ")", ".", "each", "{", "|", "line", "|", "if", "comment_end", "not_comment", "<<", "line", "not_comment", "<<", "\"\\n\"", "elsif", "/", "\\s", "\\s", "/i", "=~", "line", "comment_start", "=", "true", "comment", "<<", "$1", "comment", "<<", "\"\\n\"", "elsif", "/", "\\s", "/i", "=~", "line", "comment_end", "=", "true", "if", "comment_start", "&&", "COMMENTS_ARE_UPPER", "else", "comment_end", "=", "true", "not_comment", "<<", "line", "not_comment", "<<", "\"\\n\"", "end", "}", "return", "comment", ",", "not_comment", "end" ]
Collect comment for file entity
[ "Collect", "comment", "for", "file", "entity" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1039-L1061
1,696
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb
RDoc.Fortran95parser.find_namelists
def find_namelists(text, before_contains=nil) return nil if !text result = "" lines = "#{text}" before_contains = "" if !before_contains while lines =~ /^\s*?namelist\s+\/\s*?(\w+)\s*?\/([\s\w\,]+)$/i lines = $~.post_match nml_comment = COMMENTS_ARE_UPPER ? find_comments($~.pre_match) : find_comments($~.post_match) nml_name = $1 nml_args = $2.split(",") result << "\n\n=== NAMELIST <tt><b>" + nml_name + "</tt></b>\n\n" result << nml_comment + "\n" if nml_comment if lines.split("\n")[0] =~ /^\//i lines = "namelist " + lines end result << find_arguments(nml_args, "#{text}" + "\n" + before_contains) end return result end
ruby
def find_namelists(text, before_contains=nil) return nil if !text result = "" lines = "#{text}" before_contains = "" if !before_contains while lines =~ /^\s*?namelist\s+\/\s*?(\w+)\s*?\/([\s\w\,]+)$/i lines = $~.post_match nml_comment = COMMENTS_ARE_UPPER ? find_comments($~.pre_match) : find_comments($~.post_match) nml_name = $1 nml_args = $2.split(",") result << "\n\n=== NAMELIST <tt><b>" + nml_name + "</tt></b>\n\n" result << nml_comment + "\n" if nml_comment if lines.split("\n")[0] =~ /^\//i lines = "namelist " + lines end result << find_arguments(nml_args, "#{text}" + "\n" + before_contains) end return result end
[ "def", "find_namelists", "(", "text", ",", "before_contains", "=", "nil", ")", "return", "nil", "if", "!", "text", "result", "=", "\"\"", "lines", "=", "\"#{text}\"", "before_contains", "=", "\"\"", "if", "!", "before_contains", "while", "lines", "=~", "/", "\\s", "\\s", "\\/", "\\s", "\\w", "\\s", "\\/", "\\s", "\\w", "\\,", "/i", "lines", "=", "$~", ".", "post_match", "nml_comment", "=", "COMMENTS_ARE_UPPER", "?", "find_comments", "(", "$~", ".", "pre_match", ")", ":", "find_comments", "(", "$~", ".", "post_match", ")", "nml_name", "=", "$1", "nml_args", "=", "$2", ".", "split", "(", "\",\"", ")", "result", "<<", "\"\\n\\n=== NAMELIST <tt><b>\"", "+", "nml_name", "+", "\"</tt></b>\\n\\n\"", "result", "<<", "nml_comment", "+", "\"\\n\"", "if", "nml_comment", "if", "lines", ".", "split", "(", "\"\\n\"", ")", "[", "0", "]", "=~", "/", "\\/", "/i", "lines", "=", "\"namelist \"", "+", "lines", "end", "result", "<<", "find_arguments", "(", "nml_args", ",", "\"#{text}\"", "+", "\"\\n\"", "+", "before_contains", ")", "end", "return", "result", "end" ]
Return comments of definitions of namelists
[ "Return", "comments", "of", "definitions", "of", "namelists" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1123-L1142
1,697
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb
RDoc.Fortran95parser.find_comments
def find_comments text return "" unless text lines = text.split("\n") lines.reverse! if COMMENTS_ARE_UPPER comment_block = Array.new lines.each do |line| break if line =~ /^\s*?\w/ || line =~ /^\s*?$/ if COMMENTS_ARE_UPPER comment_block.unshift line.sub(/^\s*?!\s?/,"") else comment_block.push line.sub(/^\s*?!\s?/,"") end end nice_lines = comment_block.join("\n").split "\n\s*?\n" nice_lines[0] ||= "" nice_lines.shift end
ruby
def find_comments text return "" unless text lines = text.split("\n") lines.reverse! if COMMENTS_ARE_UPPER comment_block = Array.new lines.each do |line| break if line =~ /^\s*?\w/ || line =~ /^\s*?$/ if COMMENTS_ARE_UPPER comment_block.unshift line.sub(/^\s*?!\s?/,"") else comment_block.push line.sub(/^\s*?!\s?/,"") end end nice_lines = comment_block.join("\n").split "\n\s*?\n" nice_lines[0] ||= "" nice_lines.shift end
[ "def", "find_comments", "text", "return", "\"\"", "unless", "text", "lines", "=", "text", ".", "split", "(", "\"\\n\"", ")", "lines", ".", "reverse!", "if", "COMMENTS_ARE_UPPER", "comment_block", "=", "Array", ".", "new", "lines", ".", "each", "do", "|", "line", "|", "break", "if", "line", "=~", "/", "\\s", "\\w", "/", "||", "line", "=~", "/", "\\s", "/", "if", "COMMENTS_ARE_UPPER", "comment_block", ".", "unshift", "line", ".", "sub", "(", "/", "\\s", "\\s", "/", ",", "\"\"", ")", "else", "comment_block", ".", "push", "line", ".", "sub", "(", "/", "\\s", "\\s", "/", ",", "\"\"", ")", "end", "end", "nice_lines", "=", "comment_block", ".", "join", "(", "\"\\n\"", ")", ".", "split", "\"\\n\\s*?\\n\"", "nice_lines", "[", "0", "]", "||=", "\"\"", "nice_lines", ".", "shift", "end" ]
Comments just after module or subprogram, or arguments are returned. If "COMMENTS_ARE_UPPER" is true, comments just before modules or subprograms are returned
[ "Comments", "just", "after", "module", "or", "subprogram", "or", "arguments", "are", "returned", ".", "If", "COMMENTS_ARE_UPPER", "is", "true", "comments", "just", "before", "modules", "or", "subprograms", "are", "returned" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1149-L1165
1,698
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb
RDoc.Fortran95parser.initialize_public_method
def initialize_public_method(method, parent) return if !method || !parent new_meth = AnyMethod.new("External Alias for module", method.name) new_meth.singleton = method.singleton new_meth.params = method.params.clone new_meth.comment = remove_trailing_alias(method.comment.clone) new_meth.comment << "\n\n#{EXTERNAL_ALIAS_MES} #{parent.strip.chomp}\##{method.name}" return new_meth end
ruby
def initialize_public_method(method, parent) return if !method || !parent new_meth = AnyMethod.new("External Alias for module", method.name) new_meth.singleton = method.singleton new_meth.params = method.params.clone new_meth.comment = remove_trailing_alias(method.comment.clone) new_meth.comment << "\n\n#{EXTERNAL_ALIAS_MES} #{parent.strip.chomp}\##{method.name}" return new_meth end
[ "def", "initialize_public_method", "(", "method", ",", "parent", ")", "return", "if", "!", "method", "||", "!", "parent", "new_meth", "=", "AnyMethod", ".", "new", "(", "\"External Alias for module\"", ",", "method", ".", "name", ")", "new_meth", ".", "singleton", "=", "method", ".", "singleton", "new_meth", ".", "params", "=", "method", ".", "params", ".", "clone", "new_meth", ".", "comment", "=", "remove_trailing_alias", "(", "method", ".", "comment", ".", "clone", ")", "new_meth", ".", "comment", "<<", "\"\\n\\n#{EXTERNAL_ALIAS_MES} #{parent.strip.chomp}\\##{method.name}\"", "return", "new_meth", "end" ]
Create method for internal alias
[ "Create", "method", "for", "internal", "alias" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1177-L1187
1,699
ThoughtWorksStudios/oauth2_provider
tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb
RDoc.Fortran95parser.initialize_external_method
def initialize_external_method(new, old, params, file, comment, token=nil, internal=nil, nolink=nil) return nil unless new || old if internal external_alias_header = "#{INTERNAL_ALIAS_MES} " external_alias_text = external_alias_header + old elsif file external_alias_header = "#{EXTERNAL_ALIAS_MES} " external_alias_text = external_alias_header + file + "#" + old else return nil end external_meth = AnyMethod.new(external_alias_text, new) external_meth.singleton = false external_meth.params = params external_comment = remove_trailing_alias(comment) + "\n\n" if comment external_meth.comment = external_comment || "" if nolink && token external_meth.start_collecting_tokens external_meth.add_token Token.new(1,1).set_text(token) else external_meth.comment << external_alias_text end return external_meth end
ruby
def initialize_external_method(new, old, params, file, comment, token=nil, internal=nil, nolink=nil) return nil unless new || old if internal external_alias_header = "#{INTERNAL_ALIAS_MES} " external_alias_text = external_alias_header + old elsif file external_alias_header = "#{EXTERNAL_ALIAS_MES} " external_alias_text = external_alias_header + file + "#" + old else return nil end external_meth = AnyMethod.new(external_alias_text, new) external_meth.singleton = false external_meth.params = params external_comment = remove_trailing_alias(comment) + "\n\n" if comment external_meth.comment = external_comment || "" if nolink && token external_meth.start_collecting_tokens external_meth.add_token Token.new(1,1).set_text(token) else external_meth.comment << external_alias_text end return external_meth end
[ "def", "initialize_external_method", "(", "new", ",", "old", ",", "params", ",", "file", ",", "comment", ",", "token", "=", "nil", ",", "internal", "=", "nil", ",", "nolink", "=", "nil", ")", "return", "nil", "unless", "new", "||", "old", "if", "internal", "external_alias_header", "=", "\"#{INTERNAL_ALIAS_MES} \"", "external_alias_text", "=", "external_alias_header", "+", "old", "elsif", "file", "external_alias_header", "=", "\"#{EXTERNAL_ALIAS_MES} \"", "external_alias_text", "=", "external_alias_header", "+", "file", "+", "\"#\"", "+", "old", "else", "return", "nil", "end", "external_meth", "=", "AnyMethod", ".", "new", "(", "external_alias_text", ",", "new", ")", "external_meth", ".", "singleton", "=", "false", "external_meth", ".", "params", "=", "params", "external_comment", "=", "remove_trailing_alias", "(", "comment", ")", "+", "\"\\n\\n\"", "if", "comment", "external_meth", ".", "comment", "=", "external_comment", "||", "\"\"", "if", "nolink", "&&", "token", "external_meth", ".", "start_collecting_tokens", "external_meth", ".", "add_token", "Token", ".", "new", "(", "1", ",", "1", ")", ".", "set_text", "(", "token", ")", "else", "external_meth", ".", "comment", "<<", "external_alias_text", "end", "return", "external_meth", "end" ]
Create method for external alias If argument "internal" is true, file is ignored.
[ "Create", "method", "for", "external", "alias" ]
d54702f194edd05389968cf8947465860abccc5d
https://github.com/ThoughtWorksStudios/oauth2_provider/blob/d54702f194edd05389968cf8947465860abccc5d/tools/jruby-1.5.1/lib/ruby/1.8/rdoc/parsers/parse_f95.rb#L1194-L1220