trollo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ spec/internal/db/*.sqlite
6
+ spec/internal/config/database.yml
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@trollo --create
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ # language: ruby
2
+ # before_script:
3
+ # - cp spec/internal/config/database.yml.sample spec/internal/config/database.yml
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in trollo.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rspec'
8
+ gem 'rspec-rails'
9
+ gem 'sqlite3'
10
+ gem 'database_cleaner', '>= 1.2.0'
11
+ end
data/README.md ADDED
File without changes
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
8
+ require "bundler/gem_tasks"
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize!
7
+ run Combustion::Application
@@ -0,0 +1,54 @@
1
+ class CreateTrolloTables < ActiveRecord::Migration
2
+ def self.change
3
+
4
+ create_table :trollo_lists do |t|
5
+ t.string :name
6
+ t.references :trollable, polymorphic: true
7
+ t.timestamps
8
+ end
9
+
10
+ create_table :trollo_cards do |t|
11
+ t.references :list
12
+ t.integer :ordinal
13
+ t.string :name
14
+ t.string :workflow_state
15
+ t.timestamp :due_at
16
+ t.references :trollable, polymorphic: true
17
+ t.timestamps
18
+ end
19
+
20
+ create_table :trollo_tasklists do |t|
21
+ t.references :card
22
+ t.integer :ordinal
23
+ t.string :name
24
+ t.string :workflow_state
25
+ t.timestamp :due_at
26
+ t.references :trollable, polymorphic: true
27
+ t.timestamps
28
+ end
29
+
30
+ create_table :trollo_tasks do |t|
31
+ t.references :tasklist
32
+ t.integer :ordinal
33
+ t.string :name
34
+ t.string :group
35
+ t.string :workflow_state
36
+ t.timestamp :due_at
37
+ t.references :trollable, polymorphic: true
38
+ t.timestamps
39
+ end
40
+
41
+ add_index :trollo_lists, [:trollable_type, :trollable_id]
42
+
43
+ add_index :trollo_cards, :list_id
44
+ add_index :trollo_cards, [:trollable_type, :trollable_id]
45
+
46
+ add_index :trollo_tasklists, :card_id
47
+ add_index :trollo_tasklists, [:trollable_type, :trollable_id]
48
+
49
+ add_index :trollo_tasks, :tasklist_id
50
+ add_index :trollo_tasks, [:trollable_type, :trollable_id]
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,30 @@
1
+ module Trollo
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ include Rails::Generators::Migration
5
+
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ desc <<-CONTENT
9
+ Copies the trollo migration file to the migrations
10
+ folder.
11
+
12
+ Please run rake db:migrate once the installer is
13
+ complete.
14
+
15
+ CONTENT
16
+
17
+ def self.next_migration_number(dirname) #:nodoc:
18
+ if ActiveRecord::Base.timestamped_migrations
19
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
20
+ else
21
+ "%.3d" % (current_migration_number(dirname) + 1)
22
+ end
23
+ end
24
+
25
+ def create_migration_file
26
+ migration_template 'migration.rb', 'db/migrate/create_trollo_tables.rb'
27
+ end
28
+ end
29
+ end
30
+ end
data/lib/trollo.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "active_record"
2
+ require "workflow"
3
+ require "trollo/version"
4
+
5
+ module Trollo
6
+
7
+ def self.table_name_prefix
8
+ 'trollo_'
9
+ end
10
+
11
+ end
12
+
13
+ require "trollo/exception"
14
+ require "trollo/invoiceable"
15
+ require "trollo/transaction"
16
+ require "trollo/credit_transaction"
17
+ require "trollo/debit_transaction"
18
+ require "trollo/late_payment"
19
+ require "trollo/line_item"
20
+ require "trollo/payment_reference"
21
+ require "trollo/seller"
22
+ require "trollo/buyer"
23
+ require "trollo/invoice_decorator"
24
+ require "trollo/credit_note_invoice"
25
+ require "trollo/credit_note_credit_transaction"
26
+
27
+ require "trollo/invoice"
28
+ require "trollo/credit_note"
29
+ require "trollo/overdue_invoice"
30
+ require "trollo/invoice_adjustment"
31
+ require "trollo/line_item_type"
@@ -0,0 +1,49 @@
1
+ module Trollo
2
+
3
+ class Card < ActiveRecord::Base
4
+ include Troller
5
+ include Workflow
6
+
7
+ belongs_to :list, touch: true
8
+ has_many :tasklists, order: :ordinal, dependent: :destroy
9
+ before_save :set_ordinal
10
+ attr_accessible :name, :workflow_state, :trollable
11
+
12
+ scope :due_today, lambda { where(due_at: Time.now.beginning_of_day..Time.now.end_of_day) }
13
+ scope :overdue, lambda { where('due_at < ?', Time.now) }
14
+
15
+ workflow do
16
+ state :complete do
17
+ event :undo, :transitions_to => :incomplete
18
+ end
19
+
20
+ state :incomplete do
21
+ event :finish, :transitions_to => :complete
22
+ end
23
+ end
24
+
25
+ def set_ordinal
26
+ self.ordinal ||= list.cards.length + 1
27
+ end
28
+
29
+ def check
30
+ check_complete
31
+ check_due_at
32
+ end
33
+
34
+ def check_complete
35
+ if complete?
36
+ undo! if tasklists.any?(&:incomplete?)
37
+ elsif incomplete?
38
+ finish! if tasklists.all?(&:complete?)
39
+ end
40
+ end
41
+
42
+ def check_due_at
43
+ self.due_at = tasklists.minimum(:due_at)
44
+ self.save!
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,10 @@
1
+ module Trollo
2
+
3
+ class List < ActiveRecord::Base
4
+ include Troller
5
+
6
+ has_many :cards, order: 'due_at ASC', dependent: :destroy
7
+ attr_accessible :name, :trollable
8
+ end
9
+
10
+ end
@@ -0,0 +1,35 @@
1
+ module Trollo
2
+
3
+ class Task < ActiveRecord::Base
4
+ include Troller
5
+ include Workflow
6
+
7
+ belongs_to :tasklist, touch: true
8
+ before_save :set_ordinal
9
+ after_save :update_tasklist
10
+ attr_accessible :name, :group, :workflow_state, :trollable
11
+
12
+ workflow do
13
+ state :incomplete do
14
+ event :finish, :transitions_to => :complete
15
+ end
16
+
17
+ state :complete do
18
+ event :undo, :transitions_to => :incomplete
19
+ end
20
+ end
21
+
22
+ def set_ordinal
23
+ self.ordinal ||= tasklist.tasks.length + 1
24
+ end
25
+
26
+ def overdue?
27
+ incomplete? && due_at && (Time.now > due_at)
28
+ end
29
+
30
+ def update_tasklist
31
+ tasklist.check
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,55 @@
1
+ module Trollo
2
+
3
+ class Tasklist < ActiveRecord::Base
4
+ include Troller
5
+ include Workflow
6
+
7
+ belongs_to :card, touch: true
8
+ has_many :tasks, order: :ordinal, dependent: :destroy
9
+ before_save :set_ordinal
10
+ after_save :update_card
11
+ attr_accessible :name, :workflow_state, :trollable
12
+
13
+ workflow do
14
+ state :complete do
15
+ event :undo, :transitions_to => :incomplete
16
+ end
17
+
18
+ state :incomplete do
19
+ event :finish, :transitions_to => :complete
20
+ end
21
+ end
22
+
23
+ def set_ordinal
24
+ self.ordinal ||= card.tasklists.length + 1
25
+ end
26
+
27
+ def next_task
28
+ tasks.select(&:incomplete?).first
29
+ end
30
+
31
+ def check
32
+ check_complete
33
+ check_due_at
34
+ end
35
+
36
+ def check_complete
37
+ if complete?
38
+ undo! if tasks.any?(&:incomplete?)
39
+ elsif incomplete?
40
+ finish! if tasks.all?(&:complete?)
41
+ end
42
+ end
43
+
44
+ def check_due_at
45
+ self.due_at = tasks.minimum(:due_at)
46
+ self.save!
47
+ end
48
+
49
+ def update_card
50
+ card.check
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,35 @@
1
+ module Trollo
2
+
3
+ module Troller
4
+
5
+ def self.included(base)
6
+ base.send :include, InstanceMethods
7
+ base.send :extend, ClassMethods
8
+ end
9
+
10
+ module InstanceMethods
11
+
12
+ def trollable
13
+ trollable_type.constantize.find(trollable_id)
14
+ end
15
+
16
+ def trollable=(thing)
17
+ self.trollable_type = thing.class.name
18
+ self.trollable_id = thing.id
19
+ end
20
+
21
+ end
22
+
23
+ module ClassMethods
24
+
25
+ def trolling(trollable)
26
+ where(trollable_type: trollable.class.name, trollable_id: trollable.id)
27
+ end
28
+
29
+ def named(name)
30
+ where(name: name).first
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Trollo
2
+ VERSION = "0.0.1"
3
+ end
data/spec/README ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/trollo_test.sqlite
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+ #
3
+ end
@@ -0,0 +1,51 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ create_table :trollo_lists do |t|
4
+ t.string :name
5
+ t.references :trollable, polymorphic: true
6
+ t.timestamps
7
+ end
8
+
9
+ create_table :trollo_cards do |t|
10
+ t.references :list
11
+ t.integer :ordinal
12
+ t.string :name
13
+ t.string :workflow_state
14
+ t.timestamp :due_at
15
+ t.references :trollable, polymorphic: true
16
+ t.timestamps
17
+ end
18
+
19
+ create_table :trollo_tasklists do |t|
20
+ t.references :card
21
+ t.integer :ordinal
22
+ t.string :name
23
+ t.string :workflow_state
24
+ t.timestamp :due_at
25
+ t.references :trollable, polymorphic: true
26
+ t.timestamps
27
+ end
28
+
29
+ create_table :trollo_tasks do |t|
30
+ t.references :tasklist
31
+ t.integer :ordinal
32
+ t.string :name
33
+ t.string :group
34
+ t.string :workflow_state
35
+ t.timestamp :due_at
36
+ t.references :trollable, polymorphic: true
37
+ t.timestamps
38
+ end
39
+
40
+ add_index :trollo_lists, [:trollable_type, :trollable_id]
41
+
42
+ add_index :trollo_cards, :list_id
43
+ add_index :trollo_cards, [:trollable_type, :trollable_id]
44
+
45
+ add_index :trollo_tasklists, :card_id
46
+ add_index :trollo_tasklists, [:trollable_type, :trollable_id]
47
+
48
+ add_index :trollo_tasks, :tasklist_id
49
+ add_index :trollo_tasks, [:trollable_type, :trollable_id]
50
+
51
+ end
@@ -0,0 +1 @@
1
+ *.log
File without changes
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize! :active_record
7
+
8
+ require 'rspec/rails'
9
+
10
+ RSpec.configure do |config|
11
+ config.use_transactional_fixtures = true
12
+ config.color_enabled = true
13
+ config.formatter = :documentation
14
+
15
+ config.before(:suite) do
16
+ DatabaseCleaner.strategy = :truncation
17
+ end
18
+
19
+ config.before(:each) do
20
+ DatabaseCleaner.clean
21
+ end
22
+
23
+ end
data/trollo.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "trollo/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "trollo"
7
+ s.version = Trollo::VERSION
8
+ s.authors = ["Douglas Anderson"]
9
+ s.email = ["i.am.douglas.anderson@gmail.com"]
10
+ s.homepage = 'https://github.com/teachme2/trollo'
11
+ s.summary = %q{ A trollo gem. }
12
+ s.description = %q{ Trolololo. }
13
+
14
+ s.rubyforge_project = "trollo"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "activesupport"
22
+ s.add_dependency "activerecord", "~> 3.0"
23
+ s.add_dependency "i18n"
24
+ s.add_dependency "workflow", '= 0.8.7'
25
+
26
+ s.add_development_dependency 'combustion', '~> 0.3.1'
27
+ s.add_development_dependency 'database_cleaner', '~> 1.2.0'
28
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trollo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Douglas Anderson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-11-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
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: activerecord
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '3.0'
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'
46
+ - !ruby/object:Gem::Dependency
47
+ name: i18n
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
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: workflow
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - '='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.8.7
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.8.7
78
+ - !ruby/object:Gem::Dependency
79
+ name: combustion
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.3.1
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.3.1
94
+ - !ruby/object:Gem::Dependency
95
+ name: database_cleaner
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 1.2.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.2.0
110
+ description: ! ' Trolololo. '
111
+ email:
112
+ - i.am.douglas.anderson@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - .rvmrc
119
+ - .travis.yml
120
+ - Gemfile
121
+ - README.md
122
+ - Rakefile
123
+ - config.ru
124
+ - lib/generators/active_record/templates/migration.rb
125
+ - lib/generators/active_record/trollo_generator.rb
126
+ - lib/trollo.rb
127
+ - lib/trollo/card.rb
128
+ - lib/trollo/list.rb
129
+ - lib/trollo/task.rb
130
+ - lib/trollo/tasklist.rb
131
+ - lib/trollo/troller.rb
132
+ - lib/trollo/version.rb
133
+ - spec/README
134
+ - spec/internal/config/database.yml.sample
135
+ - spec/internal/config/routes.rb
136
+ - spec/internal/db/schema.rb
137
+ - spec/internal/log/.gitignore
138
+ - spec/internal/public/favicon.ico
139
+ - spec/spec_helper.rb
140
+ - trollo.gemspec
141
+ homepage: https://github.com/teachme2/trollo
142
+ licenses: []
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ requirements: []
160
+ rubyforge_project: trollo
161
+ rubygems_version: 1.8.24
162
+ signing_key:
163
+ specification_version: 3
164
+ summary: A trollo gem.
165
+ test_files:
166
+ - spec/README
167
+ - spec/internal/config/database.yml.sample
168
+ - spec/internal/config/routes.rb
169
+ - spec/internal/db/schema.rb
170
+ - spec/internal/log/.gitignore
171
+ - spec/internal/public/favicon.ico
172
+ - spec/spec_helper.rb