How to use call method of Project Package

Best Rr_ruby code snippet using Project.call

etl.rb

Source:etl.rb Github

copy

Full Screen

...32def scrape_field(page, field)33 cur = page.at("text:contains('#{field}:')")34 if cur then35 cur = cur.next_element36 if !IS_BOLDED_LABEL.call(cur) then37 return cur.text.strip38 end39 end40end41def scrape_field_single_el(page, field)42 cur = page.at("text:contains('#{field}:')")43 if cur then44 return cur.css('> text()').text.strip45 end46end47def scrape_paragraph(page, heading)48 scrape_paragraph_with_end_test(page, heading, &IS_BOLDED_LABEL)49end50def scrape_paragraph_with_end_test(page, heading, &end_test)51 cur = page.at("text:contains('#{heading}:')")52 if cur then53 cur = cur.next_element54 paragraph = ""55 until end_test.call(cur) do56 l = cur.text57 paragraph += l58 cur = cur.next_element59 end60 return paragraph.strip61 end62end63def scrape_funding_table(page, type, fy)64 type_sym = type.downcase.to_sym65 cur = page.at("b:contains('#{type}')").parent66 rows = []67 while IS_BOLDED_LABEL.call(cur) do cur = cur.next_element end68 until cur.text.include? 'TOTALS' do69 row = { :prior_funding => {}, :proposed_funding => {} }70 row[type_sym] = cur.text.strip.gsub(" ", " ")71 x = cur['left'].to_i72 cur = cur.next_element73 while cur['left'].to_i == x do74 row[type_sym] += " " + cur.text.strip75 cur = cur.next_element76 end77 for col in PRIOR_FUNDING_TABLE_COLS do78 row[:prior_funding][col] = cur.text.gsub(/\D/,'').to_i79 cur = cur.next_element80 end81 for yy in fy..(fy + 5) do82 row[:proposed_funding]["FY 20#{yy}"] = cur.text.gsub(/\D/,'').to_i83 cur = cur.next_element84 end85 unless cur['left'].to_i == x then cur = cur.next_element end86 rows.push(row)87 end88 return rows89end90def scrape_milestones_table(page)91 cur = page.at("b:contains('Milestone Data')")92 if cur then93 milestones = {}94 cur = cur.parent.next_element95 div_x = cur['left'].to_i + cur['width'].to_i96 cur = cur.next_element.next_element97 for milestone in MILESTONES do98 dates = {}99 row_y = cur['top'].to_i100 cur = cur.next_element101 while (cur['top'].to_i - row_y).abs < 5 do102 if cur.text != ' ' then103 if cur['left'].to_i < div_x then104 dates[:projected] = cur.text.strip.gsub('/20', '/')105 else106 dates[:actual] = cur.text.strip.gsub('/20', '/')107 end108 end109 cur = cur.next_element110 end111 milestones[milestone] = dates112 end113 return milestones114 end115end116pages = []117for fy in FY_RANGE do118 path = "xml/fy#{fy}.xml"119 fi = File.open(path)120 doc = Nokogiri::XML(fi)121 for page in doc.css('page') do122 unless page.text.include? 'Project No:' then next end123 data = {}124 data[:cip_fy] = fy125 data[:title] = scrape_title(page)126 data[:image] = scrape_image(page)127 data[:agency] = scrape_field(page, 'Agency')128 data[:implementing_agency] = scrape_field(page, 'Implementing Agency')129 data[:project_no] = scrape_field(page, 'Project No')130 data[:ward] = scrape_field(page, 'Ward')131 data[:location] = scrape_field(page, 'Location')132 data[:facility] = scrape_field(page, 'Facility Name or Identifier')133 data[:status] = scrape_field(page, 'Status')134 data[:est_cost] = scrape_field(page, 'Estimated Full Funding Cost')135 data[:description] = scrape_paragraph(page, 'Description')136 data[:justification] = scrape_paragraph(page, 'Justification')137 data[:progress_assessment] = scrape_paragraph(page, 'Progress Assessment')138 data[:funding_by_phase] = scrape_funding_table(page, 'Phase', fy)139 data[:funding_by_source] = scrape_funding_table(page, 'Source', fy)140 data[:milestones] = scrape_milestones_table(page)141 data[:related_projects] = scrape_paragraph_with_end_test(page, 'Related Projects') { |cur|142 cur.text.include?('(Dollars in Thousands)') ||143 cur.text.include?('Milestone Data')144 }145 if fy == 10 then146 data[:useful_life] = scrape_field_single_el(page, 'Useful Life of the Project')147 else148 data[:useful_life] = scrape_field(page, 'Useful Life of the Project')149 end150 if data[:useful_life] && data[:useful_life] != '' then151 data[:useful_life] = data[:useful_life].to_i152 end153 if data[:est_cost] && data[:est_cost] != '' then154 data[:est_cost] = data[:est_cost].gsub(/\D/,'').to_i155 end156 pages.push(data)157 end158end159File.open(DATA_OUTPUT_FILE, 'w') do |fo|160 fo.write(pages.to_json)161end162projects = {}163for page in pages do164 project_no = page[:project_no]165 unless projects[project_no] then166 projects[project_no] = {}167 end168 projects[project_no][:active] = page[:cip_fy] == FY_RANGE.last169 overwrite = -> (sym) {170 if page[sym] then projects[project_no][sym] = page[sym] end171 }172 overwrite.call(:project_no)173 overwrite.call(:title)174 overwrite.call(:image)175 overwrite.call(:agency)176 overwrite.call(:implementing_agency)177 overwrite.call(:ward)178 overwrite.call(:location)179 overwrite.call(:facility)180 overwrite.call(:status)181 overwrite.call(:description)182 overwrite.call(:justification)183 overwrite.call(:progress_assessment)184 overwrite.call(:related_projects)185 overwrite.call(:milestones)186 overwrite.call(:est_cost)187 overwrite.call(:useful_life)188 unless projects[project_no][:cip_tables] then189 projects[project_no][:cip_tables] = []190 end191 projects[project_no][:cip_tables].push({192 :fy => page[:cip_fy],193 :funding_by_phase => page[:funding_by_phase],194 :funding_by_source => page[:funding_by_source]195 })196end197def geolocate(address)198 if address == 'CITY-WIDE' || address == 'TBD' || address == 'WASHINGTON DC' || address.start_with?('WARD') then return {} end199 url = URI.parse("http://citizenatlas.dc.gov/newwebservices/locationverifier.asmx/findLocation?str=#{URI.escape(address)}")200 req = Net::HTTP::Get.new(url.to_s)201 res = Net::HTTP.start(url.host, url.port) { |http| http.request(req) }...

Full Screen

Full Screen

user_allowed_service_spec.rb

Source:user_allowed_service_spec.rb Github

copy

Full Screen

...49 end50 end51 shared_examples_for 'successful run' do52 it 'is successful' do53 expect(instance.call(action, context)).to be_success54 end55 end56 shared_examples_for 'allowed to checked' do57 before do58 Array(context).each do |project|59 project.active = true60 allow(project)61 .to receive(:allows_to?)62 .with(action)63 .and_return(project_allows_to)64 allow(Authorization)65 .to receive(:roles)66 .with(user, project)67 .and_return(user_roles_in_project)68 end69 allow(role)70 .to receive(:allowed_to?)71 .with(action)72 .and_return(role_grants_action)73 end74 context 'with the user having a granting role' do75 it_behaves_like 'successful run' do76 it 'is true' do77 expect(instance.call(action, context).result).to be_truthy78 end79 it 'does not call the db twice for a project' do80 Array(context).each do |project|81 expect(Authorization)82 .to receive(:roles)83 .once84 .with(user, project)85 .and_return(user_roles_in_project)86 end87 instance.call(action, context)88 instance.call(action, context)89 end90 end91 context 'but the user not being active' do92 before do93 user.lock94 end95 it 'returns false', :aggregate_failures do96 expect(instance.call(action, nil, global: true)).to be_success97 expect(instance.call(action, nil, global: true).result).not_to be_truthy98 end99 end100 end101 context 'with the user having a nongranting role' do102 let(:role_grants_action) { false }103 it_behaves_like 'successful run' do104 it 'is false' do105 expect(instance.call(action, context).result).to be_falsey106 end107 end108 end109 context 'with the user being admin110 with the user not having a granting role' do111 let(:user_roles_in_project) { [] }112 before do113 user.admin = true114 end115 it_behaves_like 'successful run' do116 it 'is true' do117 expect(instance.call(action, context).result).to be_truthy118 end119 end120 end121 context 'with the project not being active' do122 before do123 Array(context).each do |project|124 project.active = false125 end126 end127 it_behaves_like 'successful run' do128 it 'is false' do129 expect(instance.call(action, context).result).to be_falsey130 end131 it 'is false even if the user is admin' do132 user.admin = true133 expect(instance.call(action, context).result).to be_falsey134 end135 end136 end137 context 'with the project not having the action enabled' do138 let(:project_allows_to) { false }139 it_behaves_like 'successful run' do140 it 'is false' do141 expect(instance.call(action, context).result).to be_falsey142 end143 it 'is false even if the user is admin' do144 user.admin = true145 expect(instance.call(action, context).result).to be_falsey146 end147 end148 end149 context 'with having precached the results' do150 before do151 auth_cache = double('auth_cache')152 allow(Users::ProjectAuthorizationCache)153 .to receive(:new)154 .and_return(auth_cache)155 allow(auth_cache)156 .to receive(:cache)157 .with(action)158 allow(auth_cache)159 .to receive(:cached?)160 .with(action)161 .and_return(true)162 Array(context).each do |project|163 allow(auth_cache)164 .to receive(:allowed?)165 .with(action, project)166 .and_return(true)167 end168 instance.preload_projects_allowed_to(action)169 end170 it_behaves_like 'successful run' do171 it 'is true' do172 expect(instance.call(action, context).result).to be_truthy173 end174 it 'does not call the db' do175 expect(Authorization)176 .not_to receive(:roles)177 instance.call(action, context)178 end179 end180 end181 end182 describe '#call' do183 context 'for a project' do184 let(:context) { project }185 it_behaves_like 'allowed to checked'186 end187 context 'for an array of projects' do188 let(:context) { [project, other_project] }189 it_behaves_like 'allowed to checked'190 context 'with the array being empty' do191 it_behaves_like 'successful run' do192 it 'is false' do193 expect(instance.call(action, []).result).to be_falsey194 end195 end196 end197 context 'with one project not allowing an action' do198 before do199 allow(project)200 .to receive(:allows_to?)201 .with(action)202 .and_return(false)203 end204 it_behaves_like 'successful run' do205 it 'is false' do206 expect(instance.call(action, [project, other_project]).result).to be_falsey207 end208 end209 end210 end211 context 'for a relation of projects' do212 let(:context) { double('relation', class: ActiveRecord::Relation, to_a: [project]) }213 it_behaves_like 'allowed to checked'214 end215 context 'for anything else' do216 let(:context) { nil }217 it 'is false' do218 expect(instance.call(action, context).result).to be_falsey219 end220 it 'is unsuccessful' do221 expect(instance.call(action, context)).not_to be_success222 end223 end224 context 'for a global check' do225 context 'with the user being admin' do226 before do227 user.admin = true228 end229 it 'is true' do230 expect(instance.call(action, nil, global: true).result).to be_truthy231 end232 it 'is successful' do233 expect(instance.call(action, nil, global: true)).to be_success234 end235 end236 context 'with the user having a granting role' do237 before do238 allow(Authorization)239 .to receive(:roles)240 .with(user, nil)241 .and_return(user_roles_in_project)242 allow(role)243 .to receive(:allowed_to?)244 .with(action)245 .and_return(true)246 end247 context 'but the user not being active' do248 before do249 user.lock250 end251 it 'is unsuccessful', :aggregate_failures do252 expect(instance.call(action, nil, global: true)).to be_success253 expect(instance.call(action, nil, global: true).result).not_to be_truthy254 end255 end256 it 'is successful', :aggregate_failures do257 expect(instance.call(action, nil, global: true).result).to be_truthy258 expect(instance.call(action, nil, global: true)).to be_success259 end260 end261 context 'with the user not having a granting role' do262 before do263 allow(Authorization)264 .to receive(:roles)265 .with(user, nil)266 .and_return(user_roles_in_project)267 allow(role)268 .to receive(:allowed_to?)269 .with(action)270 .and_return(false)271 end272 it 'is false' do273 expect(instance.call(action, nil, global: true).result).to be_falsey274 end275 it 'is successful' do276 expect(instance.call(action, nil, global: true)).to be_success277 end278 end279 end280 end281end...

Full Screen

Full Screen

versions_controller.rb

Source:versions_controller.rb Github

copy

Full Screen

...60 def create61 attributes = permitted_params62 .version63 .merge(project_id: @project.id)64 call = Versions::CreateService65 .new(user: current_user)66 .call(attributes)67 render_cu(call, :notice_successful_create, 'new')68 end69 def edit; end70 def update71 attributes = permitted_params72 .version73 call = Versions::UpdateService74 .new(user: current_user,75 model: @version)76 .call(attributes)77 render_cu(call, :notice_successful_update, 'edit')78 end79 def close_completed80 if request.put?81 @project.close_completed_versions82 end83 redirect_to project_settings_versions_path(@project)84 end85 def destroy86 call = Versions::DeleteService87 .new(user: current_user,88 model: @version)89 .call90 unless call.success?91 flash[:error] = call.errors.full_messages92 end93 redirect_to project_settings_versions_path(@project)94 end95 private96 def redirect_back_or_version_settings97 redirect_back_or_default(project_settings_versions_path(@project))98 end99 def find_project100 @project = Project.find(params[:project_id])101 rescue ActiveRecord::RecordNotFound102 render_404103 end104 def retrieve_selected_type_ids(selectable_types, default_types = nil)105 @selected_type_ids = selected_type_ids selectable_types, default_types106 end107 def selected_type_ids(selectable_types, default_types = nil)108 if (ids = params[:type_ids])109 ids.is_a?(Array) ? ids.map(&:to_s) : ids.split('/')110 else111 (default_types || selectable_types).map { |t| t.id.to_s }112 end113 end114 def render_cu(call, success_message, failure_action)115 @version = call.result116 if call.success?117 flash[:notice] = t(success_message)118 redirect_back_or_version_settings119 else120 @errors = call.errors121 render action: failure_action122 end123 end124 def find_versions(subprojects, completed)125 versions = @project.shared_versions126 if subprojects127 versions = versions.or(@project.rolled_up_versions)128 end129 versions = versions.visible.order_by_semver_name.except(:distinct).uniq130 versions.reject! { |version| version.closed? || version.completed? } unless completed131 versions132 end133 def work_packages_of_version(version, project_ids, selected_type_ids)134 version...

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1project1 = Project.new('Project 1', 'description 1')2project2 = Project.new('Project 2', 'description 2')3project1 = Project.new('Project 1', 'description 1')4project1 = Project.new('Project 1', 'description 1')5project1 = Project.new('Project 1', 'description 1')6project1 = Project.new('Project 1', 'description 1')7project1 = Project.new('Project 1', 'description 1')8project1 = Project.new('Project 1', 'description 1')

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1project1 = Project.new("ABC", 1000, 5000)2project2 = Project.new("XYZ", 500, 1000)3funding_round1 = FundingRound.new("VC", 100)4funding_round2 = FundingRound.new("Angel", 500)5project1.add_funding_round(funding_round1)6project1.add_funding_round(funding_round2)

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1obj = Project.new()2obj.call()3obj = Project.new()4obj.call()5obj = Project.new()6obj.call()7obj = Project.new()8obj.call()9obj = Project.new()10obj.call()11obj = Project.new()12obj.call()13obj = Project.new()14obj.call()15obj = Project.new()16obj.call()17obj = Project.new()18obj.call()19obj = Project.new()20obj.call()21obj = Project.new()22obj.call()23obj = Project.new()24obj.call()25obj = Project.new()26obj.call()27obj = Project.new()28obj.call()29obj = Project.new()30obj.call()31obj = Project.new()32obj.call()

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1p1 = Project.new("Project 1", "description 1", "John Doe")2 5.times {puts "Hello"}3p1 = Project.new("Project 1", "description 1", "John Doe")4 5.times {puts "Hello"}5p1 = Project.new("Project 1", "description 1", "John Doe")6 5.times {puts "Hello"}7p1 = Project.new("Project 1", "description 1", "John Doe")8 5.times {puts "Hello"}9p1 = Project.new("Project 1", "description 1", "John Doe")10 5.times {puts "Hello"}11p1 = Project.new("Project 1", "description 1", "John Doe")12 5.times {puts "Hello"}13p1 = Project.new("Project 1", "description 1", "John Doe")14 5.times {puts "Hello"}15p1 = Project.new("Project 1", "description 1", "John Doe")

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1project1 = Project.new("Project 1", "description 1")2project2 = Project.new("Project 2", "description 2")3project3 = Project.new("Project 3", "description 3")4project4 = Project.new("Project 4", "description 4")5project5 = Project.new("Project 5", "description 5")6project6 = Project.new("Project 6", "description 6")7project7 = Project.new("Project 7", "description 7")8project8 = Project.new("Project 8", "description 8")9project9 = Project.new("Project 9", "description 9")10project10 = Project.new("Project 10", "description 10")11project11 = Project.new("Project 11", "description 11")12project12 = Project.new("Project 12", "description 12")13project13 = Project.new("Project 13", "description 13")

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1obj = Project.new()2obj.call()3obj = Project.new()4obj.call()5obj = Project.new()6obj.call()7obj = Project.new()8obj.call()9obj = Project.new()10obj.call()11obj = Project.new()12obj.call()13obj = Project.new()14obj.call()15obj = Project.new()16obj.call()17obj = Project.new()18obj.call()19obj = Project.new()20obj.call()21obj = Project.new()22obj.call()23obj = Project.new()24obj.call()25obj = Project.new()26obj.call()27obj = Project.new()28obj.call()

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1obj = Project.new()2obj.call()3obj = Project.new()4obj.call()5obj = Project.new()6obj.call()7obj = Project.new()8obj.call()9obj = Project.new()10obj.call()11obj = Project.new()12obj.call()13obj = Project.new()14obj.call()15obj = Project.new()16obj.call()17obj = Project.new()18obj.call()19obj = Project.new()20obj.call()21obj = Project.new()22obj.call()23obj = Project.new()24obj.call()25obj = Project.new()26obj.call()

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1project1 = Project.new("Project 1", "description 1")2project2 = Project.new("Project 2", "description 2")3project3 = Project.new("Project 3", "description 3")4project4 = Project.new("Project 4", "description 4")5project5 = Project.new("Project 5", "description 5")6project6 = Project.new("Project 6", "description 6")7project7 = Project.new("Project 7", "description 7")8project8 = Project.new("Project 8", "description 8")9project9 = Project.new("Project 9", "description 9")10project10 = Project.new("Project 10", "description 10")11project11 = Project.new("Project 11", "description 11")12pr jmct12 = Project.new(eProject 12", "description 12"t13orojectb3 = Project.new("Project 13", "description 13")

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1Ruby - Method to check if aj = Project.new()2obj.call()3obj = Project.new()4obj.call()5obj = Project.new()6obj.call()

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1p1 = Project.new("Project 1", "description 1", "John Doe")2 5.times {puts "Hello"}3p1 = Project.new("Project 1", "description 1", "John Doe")4 5.times {puts "Hello"}5p1 = Project.new("Project 1", "description 1", "John Doe")6 5.times {puts "Hello"}7p1 = Project.new("Project 1", "description 1", "John Doe")8 5.times {puts "Hello"}9p1 = Project.new("Project 1", "description 1", "John Doe")10 5.times {puts "Hello"}11p1 = Project.new("Project 1", "description 1", "John Doe")12 5.times {puts "Hello"}13p1 = Project.new("Project 1", "description 1", "John Doe")14 5.times {puts "Hello"}15p1 = Project.new("Project 1", "description 1", "John Doe")

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1project1 = Project.new("Project 1", "description 1")2project2 = Project.new("Project 2", "description 2")3project3 = Project.new("Project 3", "description 3")4project4 = Project.new("Project 4", "description 4")5project5 = Project.new("Project 5", "description 5")6project6 = Project.new("Project 6", "description 6")7project7 = Project.new("Project 7", "description 7")8project8 = Project.new("Project 8", "description 8")9project9 = Project.new("Project 9", "description 9")10project10 = Project.new("Project 10", "description 10")11project11 = Project.new("Project 11", "description 11")12project12 = Project.new("Project 12", "description 12")13project13 = Project.new("Project 13", "description 13")

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1project1 = Project.new("ABC", 1000, 5000)2project2 = Project.new("XYZ", 500, 1000)3funding_round1 = FundingRound.new("VC", 100)4funding_round2 = FundingRound.new("Angel", 500)5project1.add_funding_round(funding_round1)6project1.add_funding_round(funding_round2)

Full Screen

Full Screen

call

Using AI Code Generation

copy

Full Screen

1p1 = Project.new("Project 1", "description 1", "John Doe")2 5.times {puts "Hello"}3p1 = Project.new("Project 1", "description 1", "John Doe")4 5.times {puts "Hello"}5p1 = Project.new("Project 1", "description 1", "John Doe")6 5.times {puts "Hello"}7p1 = Project.new("Project 1", "description 1", "John Doe")8 5.times {puts "Hello"}9p1 = Project.new("Project 1", "description 1", "John Doe")10 5.times {puts "Hello"}11p1 = Project.new("Project 1", "description 1", "John Doe")12 5.times {puts "Hello"}13p1 = Project.new("Project 1", "description 1", "John Doe")14 5.times {puts "Hello"}15p1 = Project.new("Project 1", "description 1", "John Doe")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful