idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
10,200
def proxy_java_fields fields = %w( key frameRate mousePressed keyPressed ) methods = fields . map { | field | java_class . declared_field ( field ) } @declared_fields = Hash [ fields . zip ( methods ) ] end
Proxy over a list of Java declared fields that have the same name as some methods . Add to this list as needed .
10,201
def execute! show_help if options . empty? show_version if options [ :version ] run_sketch if options [ :run ] watch_sketch if options [ :watch ] live if options [ :live ] create if options [ :create ] check if options [ :check ] install if options [ :install ] end
Dispatch central .
10,202
def parse_options ( args ) opt_parser = OptionParser . new do | opts | opts . banner = 'Usage: k9 [options] [<filename.rb>]' options [ :version ] = false opts . on ( '-v' , '--version' , 'JRubyArt Version' ) do options [ :version ] = true end options [ :install ] = false opts . on ( '-i' , '--install' , 'Installs jruby...
Parse the command - line options .
10,203
def model_class if WillFilter :: Config . require_filter_extensions? raise WillFilter :: FilterException . new ( "model_class method must be overloaded in the extending class." ) end if model_class_name . blank? raise WillFilter :: FilterException . new ( "model_class_name was not specified." ) end @model_class ||= mod...
For extra security this method must be overloaded by the extending class .
10,204
def condition_title_for ( key ) title_parts = key . to_s . split ( '.' ) title = key . to_s . gsub ( "." , ": " ) . gsub ( "_" , " " ) title = title . split ( " " ) . collect { | part | part . split ( "/" ) . last . capitalize } . join ( " " ) if title_parts . size > 1 "#{JOIN_NAME_INDICATOR} #{title}" else title end e...
Can be overloaded for custom titles
10,205
def export_formats formats = [ ] formats << [ "-- Generic Formats --" , - 1 ] WillFilter :: Config . default_export_formats . each do | frmt | formats << [ frmt , frmt ] end if custom_formats . size > 0 formats << [ "-- Custom Formats --" , - 2 ] custom_formats . each do | frmt | formats << frmt end end formats end
Export Filter Data
10,206
def joins return nil if inner_joins . empty? inner_joins . collect do | inner_join | join_table_name = association_class ( inner_join ) . table_name join_on_field = inner_join . last . to_s "INNER JOIN #{join_table_name} ON #{join_table_name}.id = #{table_name}.#{join_on_field}" end end
deprecated for Rails 3 . 0 and up
10,207
def make_request ( method , path , data = { } , api_version = 'v1' , api_endpoint = '' ) d = camelcase ( data ) build_path = lambda { | path | "/#{api_version}" + ( if path [ 0 ] == "/" then path else "/#{path}" end ) } if api_endpoint . length == 0 create_connection = @create_connection else if not @created_connection...
Make HTTP request to Catapult API
10,208
def check_response ( response ) if response . status >= 400 parsed_body = JSON . parse ( response . body ) raise Errors :: GenericError . new ( parsed_body [ 'code' ] , parsed_body [ 'message' ] ) end end
Check response object and raise error if status code > = 400
10,209
def camelcase v case when v . is_a? ( Array ) v . map { | i | camelcase ( i ) } when v . is_a? ( Hash ) result = { } v . each do | k , val | result [ k . to_s ( ) . camelcase ( :lower ) ] = camelcase ( val ) end result else v end end
Convert all keys of a hash to camel cased strings
10,210
def symbolize v case when v . is_a? ( Array ) v . map { | i | symbolize ( i ) } when v . is_a? ( Hash ) result = { } v . each do | k , val | result [ k . underscore ( ) . to_sym ( ) ] = symbolize ( val ) end result else v end end
Convert all keys of hash to underscored symbols
10,211
def to_fileupload { id : id , name : filename , content_type : content_type , size : size , url : url , thumb_url : thumb_url } end
Serialize asset to fileupload JSON format
10,212
def create_transcription ( ) headers = @client . make_request ( :post , @client . concat_user_path ( "#{RECORDING_PATH}/#{id}/transcriptions" ) , { } ) [ 1 ] id = Client . get_id_from_location_header ( headers [ :location ] ) get_transcription ( id ) end
Request the transcription process to be started for the given recording id .
10,213
def uploader_authorization_adapter adapter = Uploader . authorization_adapter if adapter . is_a? String ActiveSupport :: Dependencies . constantize ( adapter ) else adapter end end
Returns the class to be used as the authorization adapter
10,214
def multiple? ( method_name ) return false if association ( method_name ) . nil? name = association ( method_name ) . respond_to? ( :many? ) ? :many? : :collection? association ( method_name ) . send ( name ) end
many? for Mongoid and collection? for AR
10,215
def create_member ( data ) headers = @client . make_request ( :post , @client . concat_user_path ( "#{CONFERENCE_PATH}/#{id}/members" ) , data ) [ 1 ] id = Client . get_id_from_location_header ( headers [ :location ] ) get_member ( id ) end
Add a member to a conference .
10,216
def get_member ( member_id ) member = ConferenceMember . new ( @client . make_request ( :get , @client . concat_user_path ( "#{CONFERENCE_PATH}/#{id}/members/#{member_id}" ) ) [ 0 ] , @client ) member . conference_id = id member end
Retrieve information about a particular conference member
10,217
def get_members ( ) @client . make_request ( :get , @client . concat_user_path ( "#{CONFERENCE_PATH}/#{id}/members" ) ) [ 0 ] . map do | i | member = ConferenceMember . new ( i , @client ) member . conference_id = id member end end
List all members from a conference
10,218
def print_qr_code ( content , level : :m , dot : DEFAULT_DOTSIZE , pos : [ 0 , cursor ] , stroke : true , margin : 4 , ** options ) qr_version = 0 dot_size = dot begin qr_version += 1 qr_code = RQRCode :: QRCode . new ( content , size : qr_version , level : level ) dot = options [ :extent ] / ( 2 * margin + qr_code . m...
Prints a QR Code to the PDF document . The QR Code creation happens on the fly .
10,219
def create_endpoint ( data ) headers = @client . make_request ( :post , @client . concat_user_path ( "#{DOMAIN_PATH}/#{id}/endpoints" ) , data ) [ 1 ] id = Client . get_id_from_location_header ( headers [ :location ] ) get_endpoint ( id ) end
Add a endpoint to a domain .
10,220
def get_endpoint ( endpoint_id ) endpoint = EndPoint . new ( @client . make_request ( :get , @client . concat_user_path ( "#{DOMAIN_PATH}/#{id}/endpoints/#{endpoint_id}" ) ) [ 0 ] , @client ) endpoint . domain_id = id endpoint end
Retrieve information about an endpoint
10,221
def get_endpoints ( query = nil ) @client . make_request ( :get , @client . concat_user_path ( "#{DOMAIN_PATH}/#{id}/endpoints" ) , query ) [ 0 ] . map do | i | endpoint = EndPoint . new ( i , @client ) endpoint . domain_id = id endpoint end end
List all endpoints from a domain
10,222
def delete_endpoint ( endpoint_id ) endpoint = EndPoint . new ( { :id => endpoint_id } , @client ) endpoint . domain_id = id endpoint . delete ( ) end
Delete an endpoint
10,223
def create_gather ( data ) d = if data . is_a? ( String ) { :tag => id , :max_digits => 1 , :prompt => { :locale => 'en_US' , :gender => 'female' , :sentence => data , :voice => 'kate' , :bargeable => true } } else data end headers = @client . make_request ( :post , @client . concat_user_path ( "#{CALL_PATH}/#{id}/gath...
Gather the DTMF digits pressed
10,224
def speak_sentence ( sentence , tag = nil , gender = "female" , voice = "kate" ) play_audio ( { :gender => gender || "female" , :locale => "en_US" , :voice => voice || "kate" , :sentence => sentence , :tag => tag } ) end
Speak a sentence
10,225
def extract_criteria extracted_data_criteria = [ ] @doc . xpath ( 'cda:QualityMeasureDocument/cda:component/cda:dataCriteriaSection/cda:entry' , NAMESPACES ) . each do | entry | extracted_data_criteria << entry dc = HQMF2CQL :: DataCriteria . new ( entry ) sdc = dc . clone sdc . id += '_source' @data_criteria << dc @so...
Extracts data criteria from the HQMF document .
10,226
def make_positive_entry negated_criteria = [ ] data_criteria_index_lookup = [ ] @data_criteria . each_with_index do | criterion , source_index | negated_criteria << criterion if criterion . negation data_criteria_index_lookup << [ criterion . code_list_id , criterion . definition , criterion . status , criterion . nega...
This method is needed for situations when there is a only a negated version of a data criteria . Bonnie will only show the affirmative version of data criteria . This method will create an affirmative version of a data criteria when there is only the negative one in the HQMF .
10,227
def extract_measures measure_files = MATMeasureFiles . create_from_zip_file ( @measure_zip ) measures = [ ] if measure_files . components . present? measure , component_measures = create_measure_and_components ( measure_files ) measures . push ( * component_measures ) else measure = create_measure ( measure_files ) end...
Returns an array of measures will contain a single measure if it is a non - composite measure
10,228
def create_measure ( measure_files ) hqmf_xml = measure_files . hqmf_xml measure_files . cql_libraries . each { | cql_lib_files | modify_elm_valueset_information ( cql_lib_files . elm ) } measure = CQM :: Measure . new ( HQMFMeasureLoader . extract_fields ( hqmf_xml ) ) measure . cql_libraries = create_cql_libraries ( ...
Creates and returns a measure
10,229
def retrieve_code_system_for_model code_system = attr_val ( "#{@code_list_xpath}/@codeSystem" ) if code_system code_system_name = HQMF :: Util :: CodeSystemHelper . code_system_for ( code_system ) else code_system_name = attr_val ( "#{@code_list_xpath}/@codeSystemName" ) end code_value = attr_val ( "#{@code_list_xpath}...
Extract the code system from the xml taht the document should use
10,230
def read_attribute ( attribute ) id = attribute . at_xpath ( './cda:id/@root' , NAMESPACES ) . try ( :value ) code = attribute . at_xpath ( './cda:code/@code' , NAMESPACES ) . try ( :value ) name = attribute . at_xpath ( './cda:code/cda:displayName/@value' , NAMESPACES ) . try ( :value ) value = attribute . at_xpath ( ...
Handles parsing the attributes of the document
10,231
def extract_populations_cql_map populations_cql_map = { } @doc . xpath ( "//cda:populationCriteriaSection/cda:component[@typeCode='COMP']" , HQMF2 :: Document :: NAMESPACES ) . each do | population_def | { HQMF :: PopulationCriteria :: IPP => 'initialPopulationCriteria' , HQMF :: PopulationCriteria :: DENOM => 'denomin...
Extracts the mappings between actual HQMF populations and their corresponding CQL define statements .
10,232
def extract_main_library population_criteria_sections = @doc . xpath ( "//cda:populationCriteriaSection/cda:component[@typeCode='COMP']" , HQMF2 :: Document :: NAMESPACES ) criteria_section = population_criteria_sections . at_xpath ( "cda:initialPopulationCriteria" , HQMF2 :: Document :: NAMESPACES ) if criteria_sectio...
Extracts the name of the main cql library from the Population Criteria Section .
10,233
def title disp_value = attr_val ( "#{@code_list_xpath}/cda:displayName/@value" ) unless disp_value . present? disp_value = attr_val ( './cda:localVariableName/@value' ) disp_value = disp_value . partition ( '_' ) . first unless disp_value . nil? end @title || disp_value || @description || id end
Get the title of the criteria provides a human readable description
10,234
def render_authorize_result ( status = 401 , text = nil , valid = false ) text = text || error_msg Rails . logger . error ( text ) if status != 200 { plain : text , status : status , valid : valid } end
render weixin server authorize results
10,235
def reply_music_message ( from = nil , to = nil , music ) message = MusicReplyMessage . new message . FromUserName = from || @weixin_message . ToUserName message . ToUserName = to || @weixin_message . FromUserName message . Music = music encrypt_message message . to_xml end
music = generate_music
10,236
def save ( root_node , filename ) stringify_tree_from root_node File . open ( filename , 'w' ) { | f | f << @sgf } end
Takes a node and a filename as arguments
10,237
def add_children ( * nodes ) new_children = nodes . flatten new_children . each do | node | node . set_parent self node . add_observer ( self ) end changed notify_observers :new_children , new_children end
Takes an arbitrary number of child nodes adds them to the list of children and make this node their parent .
10,238
def render ( node ) node = Marshal . load ( Marshal . dump ( node ) ) node . fetch ( 'marks' , [ ] ) . each do | mark | renderer = mappings [ mark [ 'type' ] ] return mappings [ nil ] . new ( mappings ) . render ( mark ) if renderer . nil? && mappings . key? ( nil ) node [ 'value' ] = renderer . new ( mappings ) . rend...
Renders text nodes with all markings .
10,239
def render ( document ) renderer = find_renderer ( document ) renderer . render ( document ) unless renderer . nil? end
Returns a rendered RichText document
10,240
def render ( node ) asset = nil begin asset = node [ 'data' ] [ 'target' ] rescue fail "Node target is not an asset - Node: #{node}" end return render_asset ( asset , node ) if asset . class . ancestors . map ( & :to_s ) . any? { | name | name . include? ( 'Asset' ) } if asset . is_a? ( :: Hash ) unless asset . key? ( ...
Renders asset nodes
10,241
def render ( document ) document [ 'content' ] . each_with_object ( [ ] ) do | node , result | result << find_renderer ( node ) . render ( node ) end . join ( "\n" ) end
Renders all nodes in the document .
10,242
def parse_xibs Dir [ "#{options.source_dir}/**/*.{storyboard,xib}" ] . each_with_index do | xib , xib_index | filename = File . basename ( xib , '.*' ) next if options . ignored . include? filename xibs << filename group_name = "#{xib.split(".").last}Names" constants [ filename ] << Location . new ( group_name , nil , ...
Parse all found storyboards and build a dictionary of constant = > locations
10,243
def textilize ( input ) site = @context . registers [ :site ] converter = if site . respond_to? ( :find_converter_instance ) site . find_converter_instance ( Jekyll :: Converters :: Textile ) else site . getConverterImpl ( Jekyll :: Converters :: Textile ) end converter . convert ( input ) end
Convert a Textile string into HTML output .
10,244
def parse_bibs_data ( bibs ) bibs . reduce ( Hash . new ) { | acc , bib | acc . merge ( { "#{bib.id}" => { holdings : build_holdings_for ( bib ) } } ) } end
Data structure for holdings information of bib records . A hash with mms ids as keys with values of an array of one or more hashes of holdings info
10,245
def method_missing ( name ) return response [ name . to_s ] if has_key? ( name . to_s ) super . method_missing name end
Access the top level JSON attributes as object methods
10,246
def save! response = HTTParty . put ( "#{users_base_path}/#{id}" , timeout : timeout , headers : headers , body : to_json ) get_body_from ( response ) end
Persist the user in it s current state back to Alma
10,247
def ensure_hash ( ambiguous_param ) case ambiguous_param when String if ambiguous_param . present? ensure_hash ( JSON . parse ( ambiguous_param ) ) else { } end when Hash , ActionController :: Parameters ambiguous_param when nil { } else raise ArgumentError , "Unexpected parameter: #{ambiguous_param}" end end
Handle form data JSON body or a blank value
10,248
def call ( action , params = { } , headers = { } , options = { } ) @api . call ( @name , action , params , headers , options ) end
Execute an action on a resource
10,249
def request ( method , path , * arguments ) response = http . send ( method , path , * arguments ) response . uri = URI . join ( endpoint , path ) handle_response ( response ) rescue Timeout :: Error , Net :: OpenTimeout => e raise TimeoutError . new ( @request , e . message ) rescue OpenSSL :: SSL :: SSLError => e rai...
Makes a request to the remote service .
10,250
def extract_and_merge_controller_data ( data ) if @controller data [ :request ] = { params : @controller . request . parameters . to_hash , rails_root : defined? ( Rails ) && defined? ( Rails . root ) ? Rails . root : "Rails.root not defined. Is this a test environment?" , url : @controller . complete_request_uri } dat...
Pull certain fields out of the controller and add to the data hash .
10,251
def summary if update_type == :message message elsif update_type == :recv and @data [ 2 , 9 ] == "+++++++++" "creating local" elsif update_type == :recv "updating local" elsif update_type == :sent and @data [ 2 , 9 ] == "+++++++++" "creating remote" elsif update_type == :sent "updating remote" else changes = [ ] [ :che...
Simple description of the change .
10,252
def with ( & block ) raise ArgumentError . new ( "Must pass a block" ) unless block_given? case block . arity when 1 yield self when 0 instance_methods_eval ( & block ) else raise "block arity must be 0 or 1" end end
Evaluate a block just like it was a constructor block .
10,253
def merge_constants! ( constants_hash ) constants_hash . each_pair do | name , value | @constants [ name ] = case value when Array case value . size when 3 then Gosu :: Color . rgb ( * value ) when 4 then Gosu :: Color . rgba ( * value ) else raise "Colors must be in 0..255, RGB or RGBA array format" end else value end...
Merge in a hash containing constant values . Arrays will be resolved as colors in RGBA or RGB format .
10,254
def merge_elements! ( elements_hash ) elements_hash . each_pair do | klass_names , data | klass = Fidgit klass_names . to_s . split ( '::' ) . each do | klass_name | klass = klass . const_get klass_name end raise "elements must be names of classes derived from #{Element}" unless klass . ancestors . include? Fidgit :: E...
Merge in a hash containing default values for each element .
10,255
def selection_range from = [ @text_input . selection_start , caret_position ] . min to = [ @text_input . selection_start , caret_position ] . max ( from ... to ) end
Returns the range of the selection .
10,256
def selection_text = ( str ) from = [ @text_input . selection_start , @text_input . caret_pos ] . min to = [ @text_input . selection_start , @text_input . caret_pos ] . max new_length = str . length full_text = text tags_length_before = ( 0 ... from ) . inject ( 0 ) { | m , i | m + @tags [ i ] . length } tags_length_in...
Sets the text within the selection . The caret will be placed at the end of the inserted text .
10,257
def caret_position = ( position ) raise ArgumentError , "Caret position must be in the range 0 to the length of the text (inclusive)" unless position . between? ( 0 , stripped_text . length ) @text_input . caret_pos = position position end
Position of the caret .
10,258
def draw_foreground if editable? or text == @old_text recalc if focused? @old_caret_position = caret_position @old_selection_start = @text_input . selection_start else roll_back end if caret_position > stripped_text . length self . caret_position = stripped_text . length end if @text_input . selection_start >= stripped...
Draw the text area .
10,259
def text_index_at_position ( x , y ) mouse_x , mouse_y = x - ( self . x + padding_left ) , y - ( self . y + padding_top ) @char_widths . each . with_index do | width , i | char_x , char_y = @caret_positions [ i ] if mouse_x . between? ( char_x , char_x + width ) and mouse_y . between? ( char_y , char_y + font . height ...
Index of character in reference to the displayable text .
10,260
def cut str = selection_text unless str . empty? Clipboard . copy str self . selection_text = '' if editable? end end
Cut the selection and copy it to the clipboard .
10,261
def button ( text , options = { } , & block ) Button . new ( text , { parent : self } . merge! ( options ) , & block ) end
Create a button within the container .
10,262
def image_frame ( image , options = { } , & block ) ImageFrame . new ( image , { parent : self } . merge! ( options ) , & block ) end
Create an icon .
10,263
def hit_element ( x , y ) @children . reverse_each do | child | case child when Container , Composite if element = child . hit_element ( x , y ) return element end else return child if child . hit? ( x , y ) end end self if hit? ( x , y ) end
Returns the element within this container that was hit
10,264
def icon_position = ( position ) raise ArgumentError . new ( "icon_position must be one of #{ICON_POSITIONS}" ) unless ICON_POSITIONS . include? position @icon_position = position case @icon_position when :top , :bottom @contents . instance_variable_set :@type , :fixed_columns @contents . instance_variable_set :@num_co...
Set the position of the icon respective to the text .
10,265
def layout @children . each . with_index do | child , index | child . x = padding_left + x child . y = padding_top + y end rect . width = ( @children . map { | c | c . width } . max || 0 ) + padding_left + padding_right rect . height = ( @children . map { | c | c . height } . max || 0 ) + padding_top + padding_bottom s...
Recalculate the size of the container . Should be overridden by any descendant that manages the positions of its children .
10,266
def draw_rect ( x , y , width , height , z , color , mode = :default ) @@draw_pixel . draw x , y , z , width , height , color , mode nil end
Draw a filled rectangle .
10,267
def draw_frame ( x , y , width , height , thickness , z , color , mode = :default ) draw_rect ( x - thickness , y , thickness , height , z , color , mode ) draw_rect ( x - thickness , y - thickness , width + thickness * 2 , thickness , z , color , mode ) draw_rect ( x + width , y , thickness , height , z , color , mode...
Draw an unfilled rectangle .
10,268
def turn_on ( options = { } ) _check_server! return unless enabled? fail "Already active!" if active? _turn_on_notifiers ( options ) _env . notify_active = true end
Turn notifications on .
10,269
def turn_off _check_server! fail "Not active!" unless active? @detected . available . each do | obj | obj . turn_off if obj . respond_to? ( :turn_off ) end _env . notify_active = false end
Turn notifications off .
10,270
def notify ( message , message_opts = { } ) if _client? return unless enabled? else return unless active? end @detected . available . each do | notifier | notifier . notify ( message , message_opts . dup ) end end
Show a system notification with all configured notifiers .
10,271
def runner @runner ||= ( require 'turn/runners/minirunner' case config . runmode when :marshal Turn :: MiniRunner when :solo require 'turn/runners/solorunner' Turn :: SoloRunner when :cross require 'turn/runners/crossrunner' Turn :: CrossRunner else Turn :: MiniRunner end ) end
Insatance of Runner selected based on format and runmode .
10,272
def pass ( message = nil ) banner PASS if message message = Colorize . magenta ( message ) message = message . to_s . tabto ( TAB_SIZE ) io . puts ( message ) end end
Invoked when a test passes .
10,273
def finish_suite ( suite ) total = colorize_count ( "%d tests" , suite . count_tests , :bold ) passes = colorize_count ( "%d passed" , suite . count_passes , :pass ) assertions = colorize_count ( "%d assertions" , suite . count_assertions , nil ) failures = colorize_count ( "%d failures" , suite . count_failures , :fai...
After all tests are run this is the last observable action .
10,274
def colorize_count ( str , count , colorize_method ) str = str % [ count ] str = Colorize . send ( colorize_method , str ) if colorize_method and count != 0 str end
Creates an optionally - colorized string describing the number of occurances an event occurred .
10,275
def prettify ( raised , message = nil ) message ||= raised . message backtrace = raised . respond_to? ( :backtrace ) ? raised . backtrace : raised . location backtrace = clean_backtrace ( backtrace ) backtrace . first . insert ( 0 , TRACE_MARK ) io . puts Colorize . bold ( message . tabto ( TAB_SIZE ) ) io . puts backt...
Cleanups and prints test payload
10,276
def main ( * argv ) option_parser . parse! ( argv ) @loadpath = [ 'lib' ] if loadpath . empty? tests = ARGV . empty? ? nil : argv . dup config = Turn . config do | c | c . live = live c . log = log c . loadpath = loadpath c . requires = requires c . tests = tests c . runmode = runmode c . format = outmode c . mode = de...
Run command .
10,277
def files @files ||= ( fs = tests . map do | t | File . directory? ( t ) ? Dir [ File . join ( t , '**' , '*' ) ] : Dir [ t ] end fs = fs . flatten . reject { | f | File . directory? ( f ) } ex = exclude . map do | x | File . directory? ( x ) ? Dir [ File . join ( x , '**' , '*' ) ] : Dir [ x ] end ex = ex . flatten . ...
Test files .
10,278
def reporter_class rpt_format = format || :pretty class_name = rpt_format . to_s . capitalize + "Reporter" path = "turn/reporters/#{rpt_format}_reporter" [ File . expand_path ( '~' ) , Dir . pwd ] . each do | dir | file = File . join ( dir , ".turn" , "reporters" , "#{rpt_format}_reporter.rb" ) path = file if File . ex...
Load reporter based on output mode and return its class .
10,279
def start ( args = [ ] ) if :: MiniTest :: Unit . respond_to? ( :runner= ) :: MiniTest :: Unit . runner = self end run ( args ) return @turn_suite end
Turn calls this method to start the test run .
10,280
def action_dispatch_params action_dispatch_params = env [ 'action_dispatch.request.path_parameters' ] || { } action_dispatch_params . inject ( { } ) { | hash , ( key , value ) | hash [ key . to_s ] = value ; hash } end
Pass in params from Rails routing
10,281
def changes changes = { 'new' => { } , 'obsolete' => { } , 'updated' => { } } if @environment . nil? new_environments . each do | env | changes [ 'new' ] [ env ] = { } end old_environments . each do | env | changes [ 'obsolete' ] [ env ] = { } end else env = @environment changes [ 'new' ] [ env ] = { } if new_environme...
return changes hash currently exists to keep compatibility with importer html
10,282
def as_json ( options = nil ) return { } if messages . empty? attribute , types = messages . first type = types . first { :error => { :param => attribute , :type => type , :message => nil } } end
Return the first error we get
10,283
def set_additional_attributes ( attributes , name ) if name =~ VIRTUAL_NAMES attributes [ :virtual ] = true if $1 . nil? && name =~ BRIDGES attributes [ :bridge ] = true else attributes [ :attached_to ] = $1 end else attributes [ :virtual ] = false end attributes end
adds attributes like virtual
10,284
def param_for_validation? ( name ) if respond_to? ( name ) ! send ( name ) . nil? else ! param_before_type_cast ( name ) . nil? end end
Validation We want to validate an attribute if its uncoerced value is not nil
10,285
def set_tags_context return unless tag_list_changed? || status_changed? || ! persisted? set_tag_list_on ( tag_context , tag_list ) self . tag_list = [ ] inactive_tag_contexts . each do | context | set_tag_list_on ( context , [ ] ) end end
Set the context of tags so that draft and archived tags are not displayed publicly
10,286
def role? ( role_sym ) role_sym = [ role_sym ] unless role_sym . is_a? ( Array ) roles . map { | r | r . name . underscore . to_sym } . any? { | user_role | role_sym . include? ( user_role ) } end
Checks if the User has a given role
10,287
def render rendered_items = '' list . list_items . each do | list_item | rendered_items += render_item ( list_item ) end content_tag opts [ :wrapper_element ] , rendered_items , html_options , false end
Renders the provided list
10,288
def sign_in ( user = create ( :user ) ) visit new_user_session_path within ( "#new_user" ) do fill_in 'user_email' , with : user . email fill_in 'user_password' , with : user . password end click_button 'Log in' end
Signs a user in
10,289
def find_related_posts @related_posts = @post . find_related_tags . limit ( amount_of_related_posts_to_display ) amount_of_related_posts = @related_posts . length if amount_of_related_posts != amount_of_related_posts_to_display && ( amount_of_related_posts + @popular_posts . length ) >= amount_of_related_posts_to_displ...
Creates array of related posts . If enough related posts do not exist uses popular posts
10,290
def full_filename ( for_file ) parent_name = super ( for_file ) extension = File . extname ( parent_name ) base_name = parent_name . chomp ( extension ) base_name = base_name [ version_name . size . succ .. - 1 ] if version_name [ base_name , version_name ] . compact . join ( '-' ) + extension end
Override full_filename to set version name at the end
10,291
def full_original_filename parent_name = super extension = File . extname ( parent_name ) base_name = parent_name . chomp ( extension ) base_name = base_name [ version_name . size . succ .. - 1 ] if version_name [ base_name , version_name ] . compact . join ( '-' ) + extension end
Override full_original_filename to set version name at the end
10,292
def render_thumb_gallery ( list , opts = { } ) opts . reverse_merge! ( renderer : Integral :: SwiperListRenderer , item_renderer : Integral :: PartialListItemRenderer , item_renderer_opts : { partial_path : 'integral/shared/gallery/thumb_slide' , wrapper_element : 'div' , image_version : :small , html_classes : 'swiper...
Renders a thumbnail gallery
10,293
def process ContactMailer . forward_enquiry ( self ) . deliver_later ContactMailer . auto_reply ( self ) . deliver_later NewsletterSignup . create ( name : name , email : email , context : context ) if newsletter_opt_in? end
Forward the enquiry on and send an auto reply . Create newsletter signup if necessary
10,294
def render_children children = '' list_item . children . each do | child | children += self . class . render ( child , opts ) end children end
Loop over all list item children calling render on each
10,295
def provide_attr ( attr ) list_item_attr_value = list_item . public_send ( attr ) return list_item_attr_value if list_item_attr_value . present? return object_data [ attr ] if object_available? return 'Object Unavailable' if list_item . object? && ! object_available? '' end
Works out what the provided attr evaluates to .
10,296
def header_tags return I18n . t ( 'integral.posts.show.subtitle' ) if object . tags_on ( 'published' ) . empty? header_tags = '' object . tags_on ( 'published' ) . each_with_index do | tag , i | header_tags += tag . name header_tags += ' | ' unless i == object . tags_on ( 'published' ) . size - 1 end header_tags end
Tags to be used within the header of an article to describe the subject
10,297
def preview_image ( size = :small ) preview_image = object &. preview_image &. url ( size ) return preview_image if preview_image . present? image ( size , false ) end
Preview image for the post if present . Otherwise returns featured image
10,298
def image ( size = :small , fallback = true ) image = object &. image &. url ( size ) return image if image . present? h . image_url ( 'integral/defaults/no_image_available.jpg' ) if fallback end
Image for the post if present . Otherwise returns default image
10,299
def anchor_to ( body , location ) current_path = url_for ( only_path : false ) path = "#{current_path}##{location}" link_to body , path end
Creates an anchor link