Class: Fiveruns::Dash::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/fiveruns/dash/configuration.rb

Defined Under Namespace

Classes: ConflictError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



16
17
18
19
# File 'lib/fiveruns/dash/configuration.rb', line 16

def initialize(options = {})
  @options = self.class.default_options.merge(options)
  yield self if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)



122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/fiveruns/dash/configuration.rb', line 122

def method_missing(meth, *args, &block)
  if (klass = Metric.types[meth])
    metric = klass.new(*args, &block)
    metric.recipe = Recipe.current
    if metrics.include?(metric)
      Fiveruns::Dash.logger.info "Skipping previously defined metric `#{metric.name}'"
    else
      metrics << metric
    end
  else
    super
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/fiveruns/dash/configuration.rb', line 15

def options
  @options
end

Class Method Details

.default_optionsObject



11
12
13
# File 'lib/fiveruns/dash/configuration.rb', line 11

def self.default_options
  {:scm_repo => Dir.pwd}
end

Instance Method Details

#add_exceptions_from(*meths, &block) ⇒ Object



57
58
59
60
61
# File 'lib/fiveruns/dash/configuration.rb', line 57

def add_exceptions_from(*meths, &block)
  block = block ? block : lambda { }
  meths.push :exceptions => true
  Instrument.add(*meths, &block)
end

#add_recipe(name, options = {}, &block) ⇒ Object

Merge in an existing recipe call-seq:

add_recipe :ruby


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fiveruns/dash/configuration.rb', line 70

def add_recipe(name, options = {}, &block)
  Fiveruns::Dash.register_recipe(name, options, &block) if block_given?
  if Fiveruns::Dash.recipes[name]
    Fiveruns::Dash.recipes[name].each do |recipe|
      if !recipes.include?(recipe) && recipe.matches?(options)
        recipes << recipe
        with_recipe_settings(options.reject { |k, _| k == :url }) do
          recipe.add_to(self) 
        end
      end
    end
  else
    raise ArgumentError, "No such recipe: #{name}"
  end
end

#added {|current_recipe_settings| ... } ⇒ Object

Optionally fired by recipes when included

Yields:

  • (current_recipe_settings)


96
97
98
# File 'lib/fiveruns/dash/configuration.rb', line 96

def added
  yield current_recipe_settings
end

#annotate_exceptions(&block) ⇒ Object



63
64
65
# File 'lib/fiveruns/dash/configuration.rb', line 63

def annotate_exceptions(&block)
  ::Fiveruns::Dash.session.exception_recorder.add_annotation(&block)
end

#each(&block) ⇒ Object



7
8
9
# File 'lib/fiveruns/dash/configuration.rb', line 7

def each(&block)
  metrics.each(&block)
end

#for_version(source, requirement) ⇒ Object

Optionally add to a recipe if the given version meets a requirement Note: Requires RubyGems-compatible version scheme (ie, MAJOR.MINOR.PATCH)

call-seq:

for_version Rails::Version::CURRENT, ['>=', '2.1.0'] do
  # ... code to execute
end


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fiveruns/dash/configuration.rb', line 33

def for_version(source, requirement)
  unless source
    ::Fiveruns::Dash.logger.warn "No version given (to check against #{requirement.inspect}), skipping block"
    return false
  end
  source_version = ::Gem::Version.new(source.to_s)
  requirement = Array(requirement)
  requirement_version = ::Gem::Version.new(requirement.pop)
  comparator = normalize_version_comparator(requirement.shift || :==)
  yield if source_version.__send__(comparator, requirement_version)
end

#ignore_exceptions(&rule) ⇒ Object



53
54
55
# File 'lib/fiveruns/dash/configuration.rb', line 53

def ignore_exceptions(&rule)
  Fiveruns::Dash::ExceptionRecorder.add_ignore_rule(&rule)
end

#metricsObject

:nodoc:



45
46
47
# File 'lib/fiveruns/dash/configuration.rb', line 45

def metrics #:nodoc:
  @metrics ||= []
end

#modify(criteria = {}) ⇒ Object

Lookup metrics for modification by subsequent recipes



87
88
89
90
91
92
93
# File 'lib/fiveruns/dash/configuration.rb', line 87

def modify(criteria = {})
  metrics.each do |metric|
    if criteria.all? { |k, v| metric.key[k].to_s == v.to_s }
      yield metric
    end
  end        
end

#ready?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/fiveruns/dash/configuration.rb', line 21

def ready?
  options[:app]
end

#recipesObject



49
50
51
# File 'lib/fiveruns/dash/configuration.rb', line 49

def recipes
  @recipes ||= []
end