moribus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +35 -0
  3. data/.rspec +4 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/.simplecov +42 -0
  7. data/.travis.yml +8 -0
  8. data/Gemfile +19 -0
  9. data/LICENSE +20 -0
  10. data/README.md +104 -0
  11. data/Rakefile +15 -0
  12. data/lib/colorized_text.rb +33 -0
  13. data/lib/moribus.rb +133 -0
  14. data/lib/moribus/aggregated_behavior.rb +80 -0
  15. data/lib/moribus/aggregated_cache_behavior.rb +76 -0
  16. data/lib/moribus/alias_association.rb +106 -0
  17. data/lib/moribus/extensions.rb +37 -0
  18. data/lib/moribus/extensions/delegate_associated.rb +48 -0
  19. data/lib/moribus/extensions/has_aggregated_extension.rb +94 -0
  20. data/lib/moribus/extensions/has_current_extension.rb +17 -0
  21. data/lib/moribus/macros.rb +120 -0
  22. data/lib/moribus/tracked_behavior.rb +91 -0
  23. data/lib/moribus/version.rb +3 -0
  24. data/moribus.gemspec +33 -0
  25. data/spec/dummy/README.rdoc +261 -0
  26. data/spec/dummy/Rakefile +7 -0
  27. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  28. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  29. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  30. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  31. data/spec/dummy/app/mailers/.gitkeep +0 -0
  32. data/spec/dummy/app/models/.gitkeep +0 -0
  33. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/spec/dummy/config.ru +4 -0
  35. data/spec/dummy/config/application.rb +61 -0
  36. data/spec/dummy/config/boot.rb +10 -0
  37. data/spec/dummy/config/database.yml +25 -0
  38. data/spec/dummy/config/environment.rb +5 -0
  39. data/spec/dummy/config/environments/development.rb +37 -0
  40. data/spec/dummy/config/environments/production.rb +67 -0
  41. data/spec/dummy/config/environments/test.rb +37 -0
  42. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  43. data/spec/dummy/config/initializers/inflections.rb +15 -0
  44. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  45. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  46. data/spec/dummy/config/initializers/session_store.rb +8 -0
  47. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  48. data/spec/dummy/config/locales/en.yml +5 -0
  49. data/spec/dummy/config/routes.rb +58 -0
  50. data/spec/dummy/db/test.sqlite3 +0 -0
  51. data/spec/dummy/lib/assets/.gitkeep +0 -0
  52. data/spec/dummy/log/.gitkeep +0 -0
  53. data/spec/dummy/public/404.html +26 -0
  54. data/spec/dummy/public/422.html +26 -0
  55. data/spec/dummy/public/500.html +25 -0
  56. data/spec/dummy/public/favicon.ico +0 -0
  57. data/spec/dummy/script/rails +6 -0
  58. data/spec/moribus/alias_association_spec.rb +88 -0
  59. data/spec/moribus/macros_spec.rb +7 -0
  60. data/spec/moribus_spec.rb +332 -0
  61. data/spec/spec_helper.rb +15 -0
  62. data/spec/support/moribus_spec_model.rb +57 -0
  63. metadata +209 -0
@@ -0,0 +1,15 @@
1
+ ENV["RAILS_ENV"] ||= 'test'
2
+
3
+ require "simplecov" unless ENV['CI']
4
+
5
+ require File.expand_path("../../spec/dummy/config/environment", __FILE__)
6
+ require "rspec/rails"
7
+ require "rspec/autorun"
8
+ require "moribus"
9
+
10
+ Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
11
+
12
+ RSpec.configure do |config|
13
+ config.mock_with :rspec
14
+ config.use_transactional_fixtures = true
15
+ end
@@ -0,0 +1,57 @@
1
+ # SpecModule tracks class names created via SpecModel method for next cleanup.
2
+ module MoribusSpecModel
3
+ def self.cleanup!
4
+ ObjectSpace.each_object(MoribusSpecModel) do |klass|
5
+ if Object.const_defined? klass.name.to_sym
6
+ conn, table_name = klass.connection, klass.table_name
7
+ conn.drop_table(table_name) if conn.tables.include?(table_name)
8
+ Object.send :remove_const, klass.name.to_sym
9
+ end
10
+ end
11
+ ActiveSupport::Dependencies::Reference.clear!
12
+ end
13
+ end
14
+
15
+ # Creates an anonymous class, inherited from AR::Base. When inherited itself,
16
+ # creates a table based on passed parameters.
17
+ # Example:
18
+ # class Foo < MoribusSpecModel(:name => :string)
19
+ # has_many :bars
20
+ # end
21
+ # class Bar < MoribusSpecModel(:foo_id => :integer, :amount => :float)
22
+ # belongs_to :foo
23
+ # end
24
+ # ....
25
+ # MoribusSpecModel.cleanup!
26
+ def MoribusSpecModel(column_definition = {})
27
+ Class.new(ActiveRecord::Base) do
28
+ self.abstract_class = true
29
+
30
+ singleton_class.class_eval do
31
+ alias_method :orig_inherited, :inherited
32
+ define_method :inherited do |base|
33
+ base.extend MoribusSpecModel
34
+ orig_inherited base
35
+
36
+ table_name = base.table_name
37
+ conn = base.connection
38
+ unless conn.tables.include? table_name
39
+ conn.create_table(table_name) do |t|
40
+ column_definition.each do |name, type|
41
+ options = {}
42
+ if type.to_s =~ /^(.+)!$/
43
+ type = $1.to_sym
44
+ options[:null] = false
45
+ end
46
+ options[:default] = 0 if name == :lock_version
47
+ args = [type, name]
48
+ args << options unless options.empty?
49
+ t.send(*args)
50
+ end
51
+ end
52
+ end
53
+ base.reset_column_information
54
+ end
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,209 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moribus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - TMX Credit
8
+ - Artem Kuzko
9
+ - Sergey Potapov
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-02-06 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rails
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '3.2'
29
+ - !ruby/object:Gem::Dependency
30
+ name: power_enum
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '1.3'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '1.3'
43
+ - !ruby/object:Gem::Dependency
44
+ name: yard
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rake
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: rspec-rails
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: sqlite3
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ description: ! "Introduces Aggregated and Tracked behavior to ActiveRecord::Base models,
114
+ as well\n as Macros and Extensions modules for more efficient usage."
115
+ email:
116
+ - rubygems@tmxcredit.com
117
+ - a.kuzko@gmail.com
118
+ - blake131313@gmail.com
119
+ executables: []
120
+ extensions: []
121
+ extra_rdoc_files: []
122
+ files:
123
+ - .gitignore
124
+ - .rspec
125
+ - .ruby-gemset
126
+ - .ruby-version
127
+ - .simplecov
128
+ - .travis.yml
129
+ - Gemfile
130
+ - LICENSE
131
+ - README.md
132
+ - Rakefile
133
+ - lib/colorized_text.rb
134
+ - lib/moribus.rb
135
+ - lib/moribus/aggregated_behavior.rb
136
+ - lib/moribus/aggregated_cache_behavior.rb
137
+ - lib/moribus/alias_association.rb
138
+ - lib/moribus/extensions.rb
139
+ - lib/moribus/extensions/delegate_associated.rb
140
+ - lib/moribus/extensions/has_aggregated_extension.rb
141
+ - lib/moribus/extensions/has_current_extension.rb
142
+ - lib/moribus/macros.rb
143
+ - lib/moribus/tracked_behavior.rb
144
+ - lib/moribus/version.rb
145
+ - moribus.gemspec
146
+ - spec/dummy/README.rdoc
147
+ - spec/dummy/Rakefile
148
+ - spec/dummy/app/assets/javascripts/application.js
149
+ - spec/dummy/app/assets/stylesheets/application.css
150
+ - spec/dummy/app/controllers/application_controller.rb
151
+ - spec/dummy/app/helpers/application_helper.rb
152
+ - spec/dummy/app/mailers/.gitkeep
153
+ - spec/dummy/app/models/.gitkeep
154
+ - spec/dummy/app/views/layouts/application.html.erb
155
+ - spec/dummy/config.ru
156
+ - spec/dummy/config/application.rb
157
+ - spec/dummy/config/boot.rb
158
+ - spec/dummy/config/database.yml
159
+ - spec/dummy/config/environment.rb
160
+ - spec/dummy/config/environments/development.rb
161
+ - spec/dummy/config/environments/production.rb
162
+ - spec/dummy/config/environments/test.rb
163
+ - spec/dummy/config/initializers/backtrace_silencers.rb
164
+ - spec/dummy/config/initializers/inflections.rb
165
+ - spec/dummy/config/initializers/mime_types.rb
166
+ - spec/dummy/config/initializers/secret_token.rb
167
+ - spec/dummy/config/initializers/session_store.rb
168
+ - spec/dummy/config/initializers/wrap_parameters.rb
169
+ - spec/dummy/config/locales/en.yml
170
+ - spec/dummy/config/routes.rb
171
+ - spec/dummy/db/test.sqlite3
172
+ - spec/dummy/lib/assets/.gitkeep
173
+ - spec/dummy/log/.gitkeep
174
+ - spec/dummy/public/404.html
175
+ - spec/dummy/public/422.html
176
+ - spec/dummy/public/500.html
177
+ - spec/dummy/public/favicon.ico
178
+ - spec/dummy/script/rails
179
+ - spec/moribus/alias_association_spec.rb
180
+ - spec/moribus/macros_spec.rb
181
+ - spec/moribus_spec.rb
182
+ - spec/spec_helper.rb
183
+ - spec/support/moribus_spec_model.rb
184
+ homepage: https://github.com/TMXCredit/moribus
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project: moribus
204
+ rubygems_version: 2.2.1
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: Introduces Aggregated and Tracked behavior to ActiveRecord::Base models
208
+ test_files: []
209
+ has_rdoc: