techcor 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile CHANGED
@@ -16,7 +16,7 @@ group :development do
16
16
  end
17
17
 
18
18
  gem 'activesupport'
19
- gem 'mongoid', '~> 3.0.0.rc'
19
+ gem 'mongoid', :git => 'https://github.com/mongoid/mongoid.git'
20
20
  gem 'bson_ext'
21
21
  gem 'hirb'
22
22
  gem 'gli', '~> 2.0.0.rc'
data/Gemfile.lock CHANGED
@@ -1,3 +1,13 @@
1
+ GIT
2
+ remote: https://github.com/mongoid/mongoid.git
3
+ revision: 216839d66c7a7017a7e07e4fa8126ca686ca191e
4
+ specs:
5
+ mongoid (3.0.0.rc)
6
+ activemodel (~> 3.1)
7
+ moped (~> 1.0.0.rc)
8
+ origin (~> 1.0.1)
9
+ tzinfo (~> 0.3.22)
10
+
1
11
  GEM
2
12
  remote: http://rubygems.org/
3
13
  specs:
@@ -42,11 +52,6 @@ GEM
42
52
  rdoc
43
53
  json (1.7.3)
44
54
  method_source (0.7.1)
45
- mongoid (3.0.0.rc)
46
- activemodel (~> 3.1)
47
- moped (~> 1.0.0.rc)
48
- origin (~> 1.0.0.rc)
49
- tzinfo (~> 0.3.22)
50
55
  mongoid-rspec (1.4.6)
51
56
  mongoid (>= 3.0.0.rc)
52
57
  rake
@@ -88,7 +93,7 @@ DEPENDENCIES
88
93
  gli (~> 2.0.0.rc)
89
94
  hirb
90
95
  jeweler
91
- mongoid (~> 3.0.0.rc)
96
+ mongoid!
92
97
  mongoid-rspec
93
98
  pry
94
99
  rake
data/config/mongoid.yml CHANGED
@@ -21,11 +21,7 @@ test:
21
21
  production:
22
22
  sessions:
23
23
  default:
24
- hosts:
25
- - <%= ENV['MONGOID_HOST'] || 'localhost' %>:<%= ENV['MONGOID_PORT'] || '27017' %>
26
- database: <%= ENV['MONGOID_DATABASE'] || 'techcor_production' %>
27
- username: <%= ENV['MONGOID_USERNAME'] %>
28
- password: <%= ENV['MONGOID_PASSWORD'] %>
24
+ uri: <%= ENV['MONGOHQ_URL'] %>
29
25
  logger: false
30
26
  options:
31
27
  raise_not_found_error: false
@@ -21,11 +21,7 @@ test:
21
21
  production:
22
22
  sessions:
23
23
  default:
24
- hosts:
25
- - <%= ENV['MONGOID_HOST'] || 'localhost' %>:<%= ENV['MONGOID_PORT'] || '27017' %>
26
- database: <%= ENV['MONGOID_DATABASE'] || 'techcor_production' %>
27
- username: <%= ENV['MONGOID_USERNAME'] %>
28
- password: <%= ENV['MONGOID_PASSWORD'] %>
24
+ uri: mongodb://localhost:27017/techcor_production
29
25
  logger: false
30
26
  options:
31
27
  raise_not_found_error: false
@@ -1,6 +1,6 @@
1
1
  class DescribeProject < Struct.new :project_name, :date_format
2
- def call formatter = formatter, records = records
3
- formatter.present records
2
+ def call formatter_class = ConsoleFormatter, records = records
3
+ formatter(formatter_class).present records
4
4
  end
5
5
 
6
6
  def project project_name = project_name
@@ -11,8 +11,8 @@ class DescribeProject < Struct.new :project_name, :date_format
11
11
  project.metrics
12
12
  end
13
13
 
14
- def formatter format = format
15
- ConsoleFormatter.new format
14
+ def formatter formatter_class, format = format
15
+ formatter_class.new format
16
16
  end
17
17
 
18
18
  def format date_format = date_format
@@ -9,7 +9,7 @@ class TechcorCli
9
9
  command.flag :df, :date_format
10
10
 
11
11
  command.action do |global, options, args|
12
- puts DescribeProject.new(args.first, options[:date_format]).call
12
+ puts DescribeProject.new(args.first, options[:date_format]).call ConsoleFormatter
13
13
  end
14
14
  end
15
15
 
@@ -8,7 +8,7 @@ class TechcorCli
8
8
  command.flag :fm, :format
9
9
 
10
10
  command.action do |global, options, args|
11
- puts ListProjects.new(options[:format], args.first).call
11
+ puts ListProjects.new(options[:format], args.first).call ConsoleFormatter
12
12
  end
13
13
  end
14
14
  end
@@ -1,14 +1,14 @@
1
1
  class ListProjects < Struct.new :format, :criteria
2
- def call formatter = formatter, projects = projects
3
- formatter.present projects
2
+ def call formatter_class = formatter_class, projects = projects
3
+ formatter(formatter_class).present projects
4
4
  end
5
5
 
6
6
  def projects catalog = ProjectCatalog.load, criteria = criteria
7
7
  catalog.projects criteria
8
8
  end
9
9
 
10
- def formatter(format = format.present? ? eval(format) : default_format)
11
- ConsoleFormatter.new format
10
+ def formatter(formatter_class, format = format.present? ? eval(format) : default_format)
11
+ formatter_class.new format
12
12
  end
13
13
 
14
14
  def default_format projects = projects
@@ -1,18 +1,7 @@
1
1
  class ConsoleFormatter < Struct.new :format
2
+ include Formatter
2
3
 
3
- def present records, format = format
4
- Hirb::Helpers::AutoTable.render(render_each(records), fields: format.keys, resize: false)
5
- end
6
-
7
- def render_each records
8
- records.map { |record|
9
- render_record record
10
- }
11
- end
12
-
13
- def render_record record, format = format
14
- format.merge(format) do |_, expression|
15
- record.instance_eval expression
16
- end
4
+ def present records
5
+ Hirb::Helpers::AutoTable.render(render_each(records, format), fields: format.keys, resize: false)
17
6
  end
18
7
  end
data/lib/formatter.rb ADDED
@@ -0,0 +1,14 @@
1
+ module Formatter
2
+ def render_each records, format
3
+ records.map { |record|
4
+ render_record record, format
5
+ }
6
+ end
7
+
8
+ def render_record record, format
9
+ format.merge(format) do |_, expression|
10
+ record.instance_eval expression
11
+ end
12
+ end
13
+
14
+ end
@@ -2,7 +2,7 @@ module Techcor
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 8
5
+ PATCH = 9
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
data/lib/techcor.rb CHANGED
@@ -11,6 +11,7 @@ $: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../lib')
11
11
  require 'project'
12
12
  require 'property_value'
13
13
  require 'project_catalog'
14
+ require 'formatter'
14
15
  require 'console_formatter'
15
16
  require 'metrics/metric'
16
17
  require 'metrics/number_metric'
@@ -25,4 +26,4 @@ require 'commands/describe_project'
25
26
  require 'storage/metric_mongo'
26
27
  require 'storage/project_mongo'
27
28
  require 'storage/property_value_mongo'
28
- require 'techcor/seed'
29
+ require 'techcor/seed'
@@ -1,20 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DescribeProject do
4
- it 'presents properties to table view' do
5
- result = stub(:result)
6
4
 
5
+ class DummyDescribeFormatter < Struct.new :format
6
+ def present records
7
+ records
8
+ end
9
+ end
10
+
11
+
12
+ it 'presents properties to table view' do
7
13
  records = stub(:records)
8
- formatter = stub(:formatter).tap { |f| f.should_receive(:present).with(records) { result } }
9
14
 
10
- subject.call(formatter, records).should == result
15
+ subject.call(DummyDescribeFormatter, records).should == records
11
16
  end
12
17
 
13
- it 'passes format to console formatter' do
18
+ it 'passes format to formatter class' do
14
19
  format = stub(:format)
15
- ConsoleFormatter.should_receive(:new).with(format)
20
+ formatter = stub.tap { |f| f.should_receive(:new).with(format) }
16
21
 
17
- subject.formatter(format)
22
+ subject.formatter(formatter, format)
18
23
  end
19
24
 
20
25
  it 'collects metrics from project' do
@@ -1,11 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ListProjects do
4
- it 'passes format to console formatter' do
4
+
5
+ class DummyListFormatter < Struct.new :format
6
+ def present records
7
+ records
8
+ end
9
+ end
10
+
11
+ it 'passes format to formatter class' do
5
12
  format = '42'
6
- ConsoleFormatter.should_receive(:new).with(eval(format))
7
13
 
8
- ListProjects.new(format).formatter
14
+ ListProjects.new(format).formatter(DummyListFormatter).format.should == 42
9
15
  end
10
16
 
11
17
  it 'gets list of projects from catalog according to criteria' do
@@ -18,12 +24,9 @@ describe ListProjects do
18
24
  end
19
25
 
20
26
  it 'presents projects to table view' do
21
- result = stub(:result)
22
-
23
27
  projects = stub(:projects)
24
- formatter = stub(:formatter).tap { |f| f.should_receive(:present).with(projects) { result } }
25
28
 
26
- subject.call(formatter, projects).should == result
29
+ ListProjects.new('42').call(DummyListFormatter, projects).should == projects
27
30
  end
28
31
 
29
32
  it 'uses default format if no format string was specified' do
@@ -32,7 +35,7 @@ describe ListProjects do
32
35
  command = ListProjects.new(nil)
33
36
  command.should_receive(:default_format) { result }
34
37
 
35
- command.formatter
38
+ command.formatter(DummyListFormatter)
36
39
  end
37
40
 
38
41
  it 'builds default format as list of all metrics for all projects' do
@@ -5,25 +5,12 @@ describe ConsoleFormatter do
5
5
  format = stub(:format, :keys => stub(:format_keys))
6
6
  records = stub(:records)
7
7
 
8
- subject.stub(:render_each => records)
8
+ formatter = ConsoleFormatter.new(format)
9
+ formatter.stub(:render_each => records)
9
10
 
10
11
  Hirb::Helpers::AutoTable.should_receive(:render).with(records, fields: format.keys, resize: false)
11
12
 
12
- subject.present(records, format)
13
+ formatter.present(records)
13
14
  end
14
15
 
15
- it 'renders each record in collection' do
16
- record = stub(:record)
17
-
18
- subject.should_receive(:render_record).with(record).twice
19
- subject.render_each([record, record])
20
- end
21
-
22
- it 'uses expressions in format to render each record' do
23
- expression = stub(:expression)
24
- format = {stub(:key) => expression}
25
- record = stub(:record).tap { |p| p.should_receive(:instance_eval).with(expression) }
26
-
27
- subject.render_record record, format
28
- end
29
16
  end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Formatter do
4
+ subject {
5
+ class DummyFormatter
6
+ include Formatter
7
+ end.new
8
+ }
9
+ it 'renders each record in collection' do
10
+ record = stub(:record)
11
+ format = stub(:format)
12
+
13
+ subject.should_receive(:render_record).with(record, format).twice
14
+ subject.render_each([record, record], format)
15
+ end
16
+
17
+ it 'uses expressions in format to render each record' do
18
+ expression = stub(:expression)
19
+ format = {stub(:key) => expression}
20
+ record = stub(:record).tap { |p| p.should_receive(:instance_eval).with(expression) }
21
+
22
+ subject.render_record record, format
23
+ end
24
+
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: techcor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -32,17 +32,17 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ~>
35
+ - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 3.0.0.rc
37
+ version: '0'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ~>
43
+ - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 3.0.0.rc
45
+ version: '0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bson_ext
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -251,6 +251,7 @@ files:
251
251
  - lib/commands/list_projects.rb
252
252
  - lib/commands/view_history.rb
253
253
  - lib/console_formatter.rb
254
+ - lib/formatter.rb
254
255
  - lib/gli_interface.rb
255
256
  - lib/metrics/boolean_metric.rb
256
257
  - lib/metrics/metric.rb
@@ -273,6 +274,7 @@ files:
273
274
  - spec/lib/commands/list_projects_spec.rb
274
275
  - spec/lib/commands/view_history_spec.rb
275
276
  - spec/lib/console_formatter_spec.rb
277
+ - spec/lib/formatter_spec.rb
276
278
  - spec/lib/metrics/boolean_metric_spec.rb
277
279
  - spec/lib/metrics/metric_spec.rb
278
280
  - spec/lib/metrics/number_metric_spec.rb
@@ -298,7 +300,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
298
300
  version: '0'
299
301
  segments:
300
302
  - 0
301
- hash: 1310382809361252165
303
+ hash: -809524545492569509
302
304
  required_rubygems_version: !ruby/object:Gem::Requirement
303
305
  none: false
304
306
  requirements: