beso 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/rails/rails-*
data/Appraisals ADDED
@@ -0,0 +1,3 @@
1
+ appraise 'rails-3.0.10' do
2
+ gem 'rails', '3.0.10'
3
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in beso.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jeremy Ruppel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Beso
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'beso'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install beso
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'appraisal'
4
+ require 'rspec/core/rake_task'
5
+
6
+ namespace :beso do
7
+
8
+ desc "Set up current environment variables"
9
+ task :env do
10
+ require 'rails/version'
11
+ ENV[ 'BESO_RAILS_NAME' ] = "rails-#{Rails::VERSION::STRING}"
12
+ ENV[ 'BESO_RAILS_PATH' ] = "spec/rails/#{ENV[ 'BESO_RAILS_NAME' ]}"
13
+ end
14
+
15
+ desc "Remove all test rails apps"
16
+ task :clean => [ :env ] do
17
+ Dir[ 'spec/rails/rails-*' ].each do |app|
18
+ FileUtils.rm_rf app
19
+ end
20
+ end
21
+
22
+ desc "Create a test rails app if necessary"
23
+ task :rails do
24
+ if File.exist? ENV[ 'BESO_RAILS_PATH' ]
25
+ puts "Using existing #{ENV[ 'BESO_RAILS_NAME' ]} app"
26
+ else
27
+ sh "bundle exec rails new #{ENV[ 'BESO_RAILS_PATH' ]} -m spec/support/rails_template.rb"
28
+ end
29
+ end
30
+ end
31
+
32
+ RSpec::Core::RakeTask.new :spec => [ :'beso:env', :'beso:rails' ]
33
+
34
+ desc "Run specs for all supported rails versions"
35
+ task :all do
36
+ exec 'rake appraisal spec'
37
+ end
38
+
39
+ desc "Default: Clean, install dependencies, and run specs"
40
+ task :default => [ :'beso:clean', :'appraisal:install', :all ]
data/beso.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/beso/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jeremy Ruppel"]
6
+ gem.email = ["jeremy.ruppel@gmail.com"]
7
+ gem.description = %q{Sync your KISSmetrics history, guapo!}
8
+ gem.summary = %q{Sync your KISSmetrics history, guapo!}
9
+ gem.homepage = "https://github.com/remind101/beso"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "beso"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Beso::VERSION
17
+
18
+ gem.add_dependency 'rails', '>= 3.0.10'
19
+ gem.add_dependency 'comma', '>= 3.0.3'
20
+
21
+ gem.add_development_dependency 'sqlite3'
22
+ gem.add_development_dependency 'appraisal', '>= 0.4.1'
23
+ gem.add_development_dependency 'rspec', '>= 2.9.0'
24
+ end
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", "3.0.10"
6
+
7
+ gemspec :path=>"../"
@@ -0,0 +1,101 @@
1
+ PATH
2
+ remote: /Users/jeremyruppel/Git/beso
3
+ specs:
4
+ beso (0.0.1)
5
+ comma (>= 3.0.3)
6
+ rails (>= 3.0.10)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ abstract (1.0.0)
12
+ actionmailer (3.0.10)
13
+ actionpack (= 3.0.10)
14
+ mail (~> 2.2.19)
15
+ actionpack (3.0.10)
16
+ activemodel (= 3.0.10)
17
+ activesupport (= 3.0.10)
18
+ builder (~> 2.1.2)
19
+ erubis (~> 2.6.6)
20
+ i18n (~> 0.5.0)
21
+ rack (~> 1.2.1)
22
+ rack-mount (~> 0.6.14)
23
+ rack-test (~> 0.5.7)
24
+ tzinfo (~> 0.3.23)
25
+ activemodel (3.0.10)
26
+ activesupport (= 3.0.10)
27
+ builder (~> 2.1.2)
28
+ i18n (~> 0.5.0)
29
+ activerecord (3.0.10)
30
+ activemodel (= 3.0.10)
31
+ activesupport (= 3.0.10)
32
+ arel (~> 2.0.10)
33
+ tzinfo (~> 0.3.23)
34
+ activeresource (3.0.10)
35
+ activemodel (= 3.0.10)
36
+ activesupport (= 3.0.10)
37
+ activesupport (3.0.10)
38
+ appraisal (0.4.1)
39
+ bundler
40
+ rake
41
+ arel (2.0.10)
42
+ builder (2.1.2)
43
+ comma (3.0.3)
44
+ diff-lcs (1.1.3)
45
+ erubis (2.6.6)
46
+ abstract (>= 1.0.0)
47
+ i18n (0.5.0)
48
+ json (1.6.6)
49
+ mail (2.2.19)
50
+ activesupport (>= 2.3.6)
51
+ i18n (>= 0.4.0)
52
+ mime-types (~> 1.16)
53
+ treetop (~> 1.4.8)
54
+ mime-types (1.18)
55
+ polyglot (0.3.3)
56
+ rack (1.2.5)
57
+ rack-mount (0.6.14)
58
+ rack (>= 1.0.0)
59
+ rack-test (0.5.7)
60
+ rack (>= 1.0)
61
+ rails (3.0.10)
62
+ actionmailer (= 3.0.10)
63
+ actionpack (= 3.0.10)
64
+ activerecord (= 3.0.10)
65
+ activeresource (= 3.0.10)
66
+ activesupport (= 3.0.10)
67
+ bundler (~> 1.0)
68
+ railties (= 3.0.10)
69
+ railties (3.0.10)
70
+ actionpack (= 3.0.10)
71
+ activesupport (= 3.0.10)
72
+ rake (>= 0.8.7)
73
+ rdoc (~> 3.4)
74
+ thor (~> 0.14.4)
75
+ rake (0.9.2.2)
76
+ rdoc (3.12)
77
+ json (~> 1.4)
78
+ rspec (2.9.0)
79
+ rspec-core (~> 2.9.0)
80
+ rspec-expectations (~> 2.9.0)
81
+ rspec-mocks (~> 2.9.0)
82
+ rspec-core (2.9.0)
83
+ rspec-expectations (2.9.1)
84
+ diff-lcs (~> 1.1.3)
85
+ rspec-mocks (2.9.0)
86
+ sqlite3 (1.3.5)
87
+ thor (0.14.6)
88
+ treetop (1.4.10)
89
+ polyglot
90
+ polyglot (>= 0.3.1)
91
+ tzinfo (0.3.33)
92
+
93
+ PLATFORMS
94
+ ruby
95
+
96
+ DEPENDENCIES
97
+ appraisal (>= 0.4.1)
98
+ beso!
99
+ rails (= 3.0.10)
100
+ rspec (>= 2.9.0)
101
+ sqlite3
@@ -0,0 +1,25 @@
1
+ module Beso
2
+ module Config
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def configure
7
+ yield self
8
+ end
9
+
10
+ def start_time
11
+ if @start_time
12
+ @start_time
13
+ elsif defined? BESO_START_TIME
14
+ BESO_START_TIME.to_i
15
+ else
16
+ @start_time = 1.hour.ago.to_i
17
+ end
18
+ end
19
+
20
+ def start_time=( value )
21
+ @start_time = value
22
+ end
23
+ end
24
+ end
25
+ end
data/lib/beso/job.rb ADDED
@@ -0,0 +1,51 @@
1
+ require 'comma'
2
+
3
+ module Beso
4
+ class Job
5
+ def initialize( name, options )
6
+ @name = name.to_sym
7
+ @table = options.delete :table
8
+ @props = { }
9
+ end
10
+
11
+ def prop( sym, *args, &block )
12
+ # TODO this is weak, find a better way
13
+ # to do what you mean to do
14
+ args[ 0 ] = "Prop:#{args[ 0 ] || sym.to_s.titleize}"
15
+
16
+ @props[ sym.to_sym ] = [ args, block ]
17
+ end
18
+
19
+ def to_csv
20
+ model_class.class_exec( event_title ) do |event|
21
+ define_method( :event_title ) { event }
22
+ end
23
+
24
+ model_class.instance_exec( @name, @props ) do |name, props|
25
+ comma name do
26
+ id 'Identity'
27
+ created_at 'Timestamp' do |m|
28
+ m.to_i
29
+ end
30
+ event_title 'Event'
31
+
32
+ props.each do |sym, (args, block)|
33
+ self.send sym, *args, &block
34
+ end
35
+ end
36
+ end
37
+
38
+ model_class.all.to_comma @name
39
+ end
40
+
41
+ protected
42
+
43
+ def event_title
44
+ @name.to_s.titleize
45
+ end
46
+
47
+ def model_class
48
+ @table.to_s.classify.constantize
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,7 @@
1
+ module Beso
2
+ class Railtie < Rails::Railtie
3
+ rake_tasks do
4
+ load 'lib/beso.rake'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Beso
2
+ VERSION = "0.0.1"
3
+ end
data/lib/beso.rake ADDED
@@ -0,0 +1,6 @@
1
+ namespace :beso do
2
+ desc "Testing testing 1 2 3"
3
+ task :test do
4
+ puts "YATTA!"
5
+ end
6
+ end
data/lib/beso.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'beso/version'
2
+
3
+ module Beso
4
+ autoload :Config, 'beso/config'
5
+ autoload :Job, 'beso/job'
6
+ autoload :Railtie, 'beso/railtie'
7
+
8
+ include Config
9
+ end
10
+
11
+ require 'beso/railtie' if defined?(Rails)
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Beso do
4
+ subject { Beso }
5
+
6
+ describe '#configure' do
7
+ it { should respond_to( :configure ) }
8
+
9
+ it 'should yield itself to #configure' do
10
+ subject.configure do |config|
11
+ config.should eql( subject )
12
+ end
13
+ end
14
+ end
15
+
16
+ describe '#start_time' do
17
+ before do
18
+ Beso.start_time = nil
19
+ end
20
+
21
+ subject { Beso.start_time }
22
+
23
+ context 'when not set' do
24
+ it { should eq( 1.hour.ago.to_i ) }
25
+ end
26
+
27
+ context 'when ENV["BESO_START_TIME"] is set' do
28
+ around do |example|
29
+ with_const( :BESO_START_TIME, 2.hours.ago.to_i ) do
30
+ example.run
31
+ end
32
+ end
33
+
34
+ it { should eq( 2.hours.ago.to_i ) }
35
+ end
36
+
37
+ context 'when explicitly set in the config' do
38
+ around do |example|
39
+ with_const( :BESO_START_TIME, 2.hours.ago.to_i ) do
40
+ example.run
41
+ end
42
+ end
43
+
44
+ before do
45
+ Beso.start_time = 3.hours.ago.to_i
46
+ end
47
+
48
+ it { should eq( 3.hours.ago.to_i ) }
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe Beso::Job do
4
+
5
+ describe 'to_csv' do
6
+ subject { Beso::Job.new :message_sent, :table => :users }
7
+
8
+ before do
9
+ User.destroy_all
10
+ end
11
+
12
+ let!( :foo ){ User.create! :name => 'Foo' }
13
+ let!( :bar ){ User.create! :name => 'Bar' }
14
+
15
+ context 'with the default properties' do
16
+ its( :to_csv ){ should eq( <<-EOS
17
+ Identity,Timestamp,Event
18
+ #{foo.id},#{foo.created_at.to_i},Message Sent
19
+ #{bar.id},#{bar.created_at.to_i},Message Sent
20
+ EOS
21
+ ) }
22
+ end
23
+
24
+ context 'with a custom property' do
25
+ before do
26
+ subject.prop :name
27
+ end
28
+
29
+ its( :to_csv ){ should eq( <<-EOS
30
+ Identity,Timestamp,Event,Prop:Name
31
+ #{foo.id},#{foo.created_at.to_i},Message Sent,#{foo.name}
32
+ #{bar.id},#{bar.created_at.to_i},Message Sent,#{bar.name}
33
+ EOS
34
+ ) }
35
+ end
36
+
37
+ context 'with a custom property with a custom title' do
38
+ before do
39
+ subject.prop :name, 'Handle'
40
+ end
41
+
42
+ its( :to_csv ){ should eq( <<-EOS
43
+ Identity,Timestamp,Event,Prop:Handle
44
+ #{foo.id},#{foo.created_at.to_i},Message Sent,#{foo.name}
45
+ #{bar.id},#{bar.created_at.to_i},Message Sent,#{bar.name}
46
+ EOS
47
+ ) }
48
+ end
49
+
50
+ context 'with a custom property and a block' do
51
+ before do
52
+ subject.prop :name do |name|
53
+ name.length
54
+ end
55
+ end
56
+
57
+ its( :to_csv ){ should eq( <<-EOS
58
+ Identity,Timestamp,Event,Prop:Name
59
+ #{foo.id},#{foo.created_at.to_i},Message Sent,#{foo.name.length}
60
+ #{bar.id},#{bar.created_at.to_i},Message Sent,#{bar.name.length}
61
+ EOS
62
+ )}
63
+ end
64
+
65
+ context 'with a custom property with a custom title and a block' do
66
+ before do
67
+ subject.prop :name, 'Name Length' do |name|
68
+ name.length
69
+ end
70
+ end
71
+
72
+ its( :to_csv ){ should eq( <<-EOS
73
+ Identity,Timestamp,Event,Prop:Name Length
74
+ #{foo.id},#{foo.created_at.to_i},Message Sent,#{foo.name.length}
75
+ #{bar.id},#{bar.created_at.to_i},Message Sent,#{bar.name.length}
76
+ EOS
77
+ )}
78
+ end
79
+ end
80
+
81
+ end
File without changes
@@ -0,0 +1,31 @@
1
+ # Set the environment variables for the test app
2
+ ENV[ 'RAILS_ENV' ] = 'test'
3
+
4
+ # Add the test app to the load path
5
+ $: << ENV[ 'BESO_RAILS_PATH' ]
6
+
7
+ # Require all dependencies
8
+ Bundler.require
9
+
10
+ # Boot the rails app
11
+ require 'config/environment'
12
+
13
+ # Helpers
14
+ module ConstHelper
15
+
16
+ def with_const( const, value )
17
+ Object.const_set const, value
18
+ yield
19
+ Object.send :remove_const, const
20
+ end
21
+ end
22
+
23
+ # Configure RSpec
24
+ RSpec.configure do |config|
25
+ # Use color
26
+ config.color_enabled = true
27
+ # Change the formatter
28
+ config.formatter = :documentation
29
+ # Include helpers
30
+ config.include ConstHelper
31
+ end
@@ -0,0 +1,16 @@
1
+ # Clean up the app a bit
2
+ run 'rm -r test'
3
+ run 'rm -r doc'
4
+ run 'rm -r README.rdoc'
5
+ run 'rm -r vendor'
6
+
7
+ # Create some models
8
+ generate 'model', 'user name:string'
9
+ generate 'model', 'message user_id:integer'
10
+
11
+ # Set up the database
12
+ rake 'db:migrate'
13
+ rake 'test:prepare'
14
+
15
+ # Add our gem dependency
16
+ gem 'beso'
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: beso
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jeremy Ruppel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-11 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.10
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.10
30
+ - !ruby/object:Gem::Dependency
31
+ name: comma
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 3.0.3
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 3.0.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: appraisal
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.4.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.4.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.9.0
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.9.0
94
+ description: Sync your KISSmetrics history, guapo!
95
+ email:
96
+ - jeremy.ruppel@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Appraisals
103
+ - Gemfile
104
+ - LICENSE
105
+ - README.md
106
+ - Rakefile
107
+ - beso.gemspec
108
+ - gemfiles/rails-3.0.10.gemfile
109
+ - gemfiles/rails-3.0.10.gemfile.lock
110
+ - lib/beso.rake
111
+ - lib/beso.rb
112
+ - lib/beso/config.rb
113
+ - lib/beso/job.rb
114
+ - lib/beso/railtie.rb
115
+ - lib/beso/version.rb
116
+ - spec/beso/config_spec.rb
117
+ - spec/beso/job_spec.rb
118
+ - spec/rails/.gitkeep
119
+ - spec/spec_helper.rb
120
+ - spec/support/rails_template.rb
121
+ homepage: https://github.com/remind101/beso
122
+ licenses: []
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 1.8.19
142
+ signing_key:
143
+ specification_version: 3
144
+ summary: Sync your KISSmetrics history, guapo!
145
+ test_files:
146
+ - spec/beso/config_spec.rb
147
+ - spec/beso/job_spec.rb
148
+ - spec/rails/.gitkeep
149
+ - spec/spec_helper.rb
150
+ - spec/support/rails_template.rb