lib/redmine-cli/resources.rb in redmine-cli-0.1.5 vs lib/redmine-cli/resources.rb in redmine-cli-0.1.6

- old
+ new

@@ -5,41 +5,45 @@ require 'pp' module Redmine module Cli class BaseResource < ActiveResource::Base - self.site = Redmine::Cli::config.url - self.user = Redmine::Cli::config.username - self.password = Redmine::Cli::config.password - - class << self - # HACK: Redmine API isn't ActiveResource-friendly out of the box, so - # we need to pass nometa=1 to all requests since we don't care about - # the metadata that gets passed back in the top level attributes. - def find(*arguments) - arguments[1] = arguments[1] || {} - arguments[1][:params] = arguments[1][:params] || {} - arguments[1][:params][:nometa] = 1 - - super - end - - def fetch_all(params = {}) - limit = 100 - offset = 0 - - resources = [] - - while((fetched_resources = self.all(:params => params.merge({:limit => limit, :offset => offset}))).any?) - resources += fetched_resources - offset += limit - if fetched_resources.length < limit then - break + begin + self.site = Redmine::Cli::config.url + self.user = Redmine::Cli::config.username + self.password = Redmine::Cli::config.password + + class << self + # HACK: Redmine API isn't ActiveResource-friendly out of the box, so + # we need to pass nometa=1 to all requests since we don't care about + # the metadata that gets passed back in the top level attributes. + def find(*arguments) + arguments[1] = arguments[1] || {} + arguments[1][:params] = arguments[1][:params] || {} + arguments[1][:params][:nometa] = 1 + + super + end + + def fetch_all(params = {}) + limit = 100 + offset = 0 + + resources = [] + + while((fetched_resources = self.all(:params => params.merge({:limit => limit, :offset => offset}))).any?) + resources += fetched_resources + offset += limit + if fetched_resources.length < limit then + break + end end + + resources end - - resources end + rescue NoConfigFileError + puts "Warning: No .redmine file was found in your home directory. Use \"redmine install\" to create one." end end class Issue < BaseResource; end class User < BaseResource; end