custom_streams 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
+ db/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in custom_streams.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Andrea Campolonghi
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,28 @@
1
+ # CustomStreams
2
+
3
+ Create custom activities streams from a streamer "Model".
4
+ Just an idea up to now.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'custom_streams'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install custom_streams
19
+
20
+ ## Usage
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'custom_streams/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "custom_streams"
8
+ spec.version = CustomStreams::VERSION
9
+ spec.authors = ["Andrea Campolonghi"]
10
+ spec.email = ["acampolonghi@gmail.com"]
11
+ spec.description = %q{Create custom activities streams from a streamer "Model"}
12
+ spec.summary = %q{Create custom activities streams from a streamer "Model"}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "activerecord"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "sqlite3"
27
+ end
@@ -0,0 +1,3 @@
1
+ class Activity < ActiveRecord::Base
2
+
3
+ end
@@ -0,0 +1,36 @@
1
+ module CustomStreams
2
+ module Streamer
3
+
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def streamer args={}
11
+
12
+ define_method :streamer_options do
13
+ args
14
+ end
15
+
16
+ define_method :create_activity do |activity|
17
+ namespace = streamer_options.fetch(:namespace, nil)
18
+ p namespace
19
+ name = namespace ? "#{namespace}.#{activity}" : activity
20
+ p name
21
+ Activity.create owner_id: self.id, owner_type: self.class.to_s, name: name
22
+ end
23
+
24
+ define_method :stream do |args={}|
25
+ order = args.fetch(:order, 'created_at DESC')
26
+ Activity.where(owner_id: self.id).order(order)
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+
36
+ ActiveRecord::Base.send :include, CustomStreams::Streamer
@@ -0,0 +1,3 @@
1
+ module CustomStreams
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "custom_streams/version"
2
+ require "custom_streams/streamer"
3
+ require "custom_streams/activity"
4
+
5
+ module CustomStreams
6
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Document do
4
+ let(:document) { Document.create }
5
+
6
+ specify { described_class.respond_to?(:streamer).should be_true }
7
+ it { subject.respond_to?(:create_activity).should be_true }
8
+
9
+ describe "#create_activity" do
10
+ before do
11
+ document.create_activity("new_activity")
12
+ end
13
+ specify { Activity.count.should eq 1 }
14
+ specify { Activity.first.owner_id.should eq document.id }
15
+ specify { Activity.first.owner_type.should eq 'Document' }
16
+ specify { Activity.first.name.should eq 'new_activity' }
17
+ end
18
+
19
+ describe "#stream" do
20
+ before do
21
+ document.create_activity("one")
22
+ document.create_activity("two")
23
+ document.create_activity("three")
24
+ end
25
+ specify { document.stream.should have(3).records }
26
+ specify { document.stream.first.name.should eq 'three' }
27
+ specify { document.stream.last.name.should eq 'one' }
28
+ end
29
+
30
+ describe "namespace" do
31
+
32
+ class DocumentWithNamespace < ActiveRecord::Base
33
+ self.table_name = :documents
34
+ streamer namespace: 'document'
35
+ end
36
+
37
+ let(:document) { DocumentWithNamespace.create }
38
+
39
+ before { document.create_activity("one") }
40
+ specify { document.stream.last.name.should eq 'document.one' }
41
+
42
+ end
43
+
44
+
45
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'active_record'
3
+ require 'sqlite3'
4
+ require 'custom_streams'
5
+ require_relative '../templates/activities'
6
+
7
+ Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each { |f| require f }
8
+ FileUtils.mkdir_p File.dirname(__FILE__) + '/../db/'
9
+ ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => "db/test.sqlite3"
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+
21
+ config.before :suite do
22
+ ActiveRecord::Base.connection.create_table(:documents, :force => true) do |t|
23
+ t.timestamps
24
+ end
25
+ CreateActivities.up
26
+ end
27
+
28
+ config.before(:each) do
29
+ Document.delete_all
30
+ Activity.delete_all
31
+ end
32
+
33
+ config.after(:suite) do
34
+ ActiveRecord::Base.connection.drop_table(:documents)
35
+ CreateActivities.down
36
+ end
37
+
38
+ end
@@ -0,0 +1,3 @@
1
+ class Document < ActiveRecord::Base
2
+ streamer
3
+ end
@@ -0,0 +1,17 @@
1
+ class CreateActivities < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :activities do |t|
4
+ t.integer :owner_id, :null => false
5
+ t.string :owner_type, :name, :null => false
6
+ t.string :name, :null => false
7
+ t.timestamps
8
+ end
9
+
10
+ add_index :activities, :owner_type
11
+ add_index :activities, :owner_id
12
+ end
13
+
14
+ def self.down
15
+ drop_table :activities
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: custom_streams
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrea Campolonghi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
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: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
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'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '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: '0'
94
+ description: Create custom activities streams from a streamer "Model"
95
+ email:
96
+ - acampolonghi@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - .rspec
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - custom_streams.gemspec
108
+ - lib/custom_streams.rb
109
+ - lib/custom_streams/activity.rb
110
+ - lib/custom_streams/streamer.rb
111
+ - lib/custom_streams/version.rb
112
+ - spec/custom_streams_spec.rb
113
+ - spec/spec_helper.rb
114
+ - spec/support/document.rb
115
+ - templates/activities.rb
116
+ homepage: ''
117
+ licenses:
118
+ - MIT
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ! '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ segments:
130
+ - 0
131
+ hash: 4119074303309682510
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ segments:
139
+ - 0
140
+ hash: 4119074303309682510
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 1.8.25
144
+ signing_key:
145
+ specification_version: 3
146
+ summary: Create custom activities streams from a streamer "Model"
147
+ test_files:
148
+ - spec/custom_streams_spec.rb
149
+ - spec/spec_helper.rb
150
+ - spec/support/document.rb