publishing_logic 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.document +1 -1
  3. data/.gitignore +9 -23
  4. data/.rspec +2 -0
  5. data/.specification.example +34 -34
  6. data/.travis.yml +4 -0
  7. data/CODE_OF_CONDUCT.md +49 -0
  8. data/Gemfile +4 -0
  9. data/LICENSE +1 -1
  10. data/README.md +65 -0
  11. data/Rakefile +3 -49
  12. data/bin/console +14 -0
  13. data/bin/setup +8 -0
  14. data/lib/generators/publishing_logic/fields_generator.rb +13 -0
  15. data/lib/generators/publishing_logic/templates/migration.erb +10 -0
  16. data/lib/locale/en.yml +9 -0
  17. data/lib/locale/hu.yml +9 -0
  18. data/lib/publishing_logic.rb +7 -1
  19. data/lib/publishing_logic/model_logic.rb +51 -0
  20. data/lib/publishing_logic/version.rb +3 -0
  21. data/publishing_logic.gemspec +29 -0
  22. metadata +114 -176
  23. data/README.rdoc +0 -29
  24. data/VERSION +0 -1
  25. data/lib/model_logic.rb +0 -82
  26. data/rails_generators/publishing_logic_fields/USAGE +0 -2
  27. data/rails_generators/publishing_logic_fields/publishing_logic_fields_generator.rb +0 -34
  28. data/rails_generators/publishing_logic_fields/templates/app/views/publishing_logic_fields.html.erb +0 -12
  29. data/rails_generators/publishing_logic_fields/templates/db/migrate/add_publishing_logic_fields.rb.erb +0 -18
  30. data/spec/general_model_logic.rb +0 -93
  31. data/spec/models_with_all_fields_spec.rb +0 -85
  32. data/spec/models_with_no_published_until_field_spec.rb +0 -68
  33. data/spec/spec.opts +0 -1
  34. data/spec/spec_helper.rb +0 -55
  35. data/spec/support/database_cleanliness.rb +0 -14
  36. data/spec/support/database_connection.rb +0 -4
  37. data/spec/support/database_migrations.rb +0 -56
  38. data/spec/support/factories.rb +0 -10
  39. data/spec/support/logging.rb +0 -2
  40. data/spec/support/models/article.rb +0 -3
  41. data/spec/support/models/programme.rb +0 -3
@@ -0,0 +1,51 @@
1
+ module PublishingLogic
2
+ module ModelLogic
3
+ def self.included(base)
4
+ base.class_eval do
5
+ validates_presence_of :published_at, if: :publishing_enabled?
6
+ validate :published_until_is_not_before_published_at
7
+ validate :publishing_until_in_future
8
+
9
+ # If objects have identical published_at values, order by created_at. If these are
10
+ # identical as well, then order by id. This is done to ensure there is a unique
11
+ # ordering of objects, ordering by newest and oldest should result in arrays that are
12
+ # the inverse of the other.
13
+ scope :by_publication_date_oldest_first, lambda {
14
+ order("#{base.table_name}.published_at ASC, #{base.table_name}.created_at ASC, #{base.table_name}.id ASC")
15
+ }
16
+
17
+ scope :by_publication_date_newest_first, lambda {
18
+ order("#{base.table_name}.published_at DESC, #{base.table_name}.created_at DESC, #{base.table_name}.id DESC")
19
+ }
20
+
21
+ scope :published, lambda { where("#{base.table_name}.publishing_enabled = ? AND \
22
+ (#{base.table_name}.published_until IS NULL or #{base.table_name}.published_until > ?) AND \
23
+ (#{base.table_name}.published_at IS NULL or #{base.table_name}.published_at < ?)",
24
+ true, Time.now.utc, Time.now.utc) } do
25
+ def newest
26
+ order("#{table_name}.published_at DESC").first
27
+ end
28
+
29
+ def oldest
30
+ order("#{table_name}.published_at DESC").last
31
+ end
32
+ end
33
+
34
+ def published?
35
+ return false if published_at && Time.now < published_at
36
+ return false if published_until && Time.now > published_until
37
+ publishing_enabled?
38
+ end
39
+
40
+ private
41
+ def published_until_is_not_before_published_at
42
+ errors.add(:published_until, :must_be_before_publishing_at) if published_until.present? && published_at.present? && published_until < published_at
43
+ end
44
+
45
+ def publishing_until_in_future
46
+ errors.add(:published_until, :must_be_in_the_future) if published_until && !published_until.future?
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,3 @@
1
+ module PublishingLogic
2
+ VERSION = "0.3.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'publishing_logic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "publishing_logic"
8
+ spec.version = PublishingLogic::VERSION
9
+ spec.authors = ["Unboxed Consulting", "Attila Györffy"]
10
+ spec.email = ["enquiries@unboxedconsulting.com"]
11
+
12
+ spec.summary = %q{Publishing logic for ActiveRecord models}
13
+ spec.description = %q{Publishing logic for ActiveRecord models}
14
+ spec.homepage = "https://github.com/unboxed/publishing_logic"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'activerecord', ">= 3.0.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency 'database_cleaner', ">= 0.5.0"
28
+ spec.add_development_dependency 'sqlite3'
29
+ end
metadata CHANGED
@@ -1,211 +1,149 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: publishing_logic
3
- version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Unboxed Consulting
8
+ - Attila Györffy
14
9
  autorequire:
15
- bindir: bin
10
+ bindir: exe
16
11
  cert_chain: []
17
-
18
- date: 2010-08-20 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
12
+ date: 2016-04-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activerecord
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
27
18
  - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 1
32
- - 2
33
- - 9
34
- version: 1.2.9
35
- type: :development
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: cucumber
19
+ - !ruby/object:Gem::Version
20
+ version: 3.0.0
21
+ type: :runtime
39
22
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
43
25
  - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
26
+ - !ruby/object:Gem::Version
27
+ version: 3.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.11'
49
35
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: rspec-rails
53
36
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 27
60
- segments:
61
- - 1
62
- - 3
63
- - 0
64
- version: 1.3.0
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.11'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
65
49
  type: :development
66
- version_requirements: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: factory_girl
69
50
  prerelease: false
70
- requirement: &id004 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 31
76
- segments:
77
- - 1
78
- - 2
79
- - 0
80
- version: 1.2.0
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
81
63
  type: :development
82
- version_requirements: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: activesupport
85
64
  prerelease: false
86
- requirement: &id005 !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '3.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: database_cleaner
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
89
74
  - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 2
94
- - 3
95
- - 0
96
- version: 2.3.0
75
+ - !ruby/object:Gem::Version
76
+ version: 0.5.0
97
77
  type: :development
98
- version_requirements: *id005
99
- - !ruby/object:Gem::Dependency
100
- name: activerecord
101
78
  prerelease: false
102
- requirement: &id006 !ruby/object:Gem::Requirement
103
- none: false
104
- requirements:
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 0.5.0
84
+ - !ruby/object:Gem::Dependency
85
+ name: sqlite3
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
105
88
  - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 3
108
- segments:
109
- - 2
110
- - 3
111
- - 0
112
- version: 2.3.0
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
113
91
  type: :development
114
- version_requirements: *id006
115
- - !ruby/object:Gem::Dependency
116
- name: database_cleaner
117
92
  prerelease: false
118
- requirement: &id007 !ruby/object:Gem::Requirement
119
- none: false
120
- requirements:
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
121
95
  - - ">="
122
- - !ruby/object:Gem::Version
123
- hash: 11
124
- segments:
125
- - 0
126
- - 5
127
- - 0
128
- version: 0.5.0
129
- type: :development
130
- version_requirements: *id007
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
131
98
  description: Publishing logic for ActiveRecord models
132
- email: enquiries@unboxedconsulting.com
99
+ email:
100
+ - enquiries@unboxedconsulting.com
133
101
  executables: []
134
-
135
102
  extensions: []
136
-
137
- extra_rdoc_files:
138
- - LICENSE
139
- - README.rdoc
140
- files:
141
- - .document
142
- - .gitignore
143
- - .specification.example
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".document"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".specification.example"
109
+ - ".travis.yml"
110
+ - CODE_OF_CONDUCT.md
111
+ - Gemfile
144
112
  - LICENSE
145
- - README.rdoc
113
+ - README.md
146
114
  - Rakefile
147
- - VERSION
148
- - lib/model_logic.rb
115
+ - bin/console
116
+ - bin/setup
117
+ - lib/generators/publishing_logic/fields_generator.rb
118
+ - lib/generators/publishing_logic/templates/migration.erb
119
+ - lib/locale/en.yml
120
+ - lib/locale/hu.yml
149
121
  - lib/publishing_logic.rb
150
- - rails_generators/publishing_logic_fields/USAGE
151
- - rails_generators/publishing_logic_fields/publishing_logic_fields_generator.rb
152
- - rails_generators/publishing_logic_fields/templates/app/views/publishing_logic_fields.html.erb
153
- - rails_generators/publishing_logic_fields/templates/db/migrate/add_publishing_logic_fields.rb.erb
154
- - spec/general_model_logic.rb
155
- - spec/models_with_all_fields_spec.rb
156
- - spec/models_with_no_published_until_field_spec.rb
157
- - spec/spec.opts
158
- - spec/spec_helper.rb
159
- - spec/support/database_cleanliness.rb
160
- - spec/support/database_connection.rb
161
- - spec/support/database_migrations.rb
162
- - spec/support/factories.rb
163
- - spec/support/logging.rb
164
- - spec/support/models/article.rb
165
- - spec/support/models/programme.rb
166
- has_rdoc: true
167
- homepage: http://github.com/unboxed/publishing_logic
168
- licenses: []
169
-
122
+ - lib/publishing_logic/model_logic.rb
123
+ - lib/publishing_logic/version.rb
124
+ - publishing_logic.gemspec
125
+ homepage: https://github.com/unboxed/publishing_logic
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
170
129
  post_install_message:
171
- rdoc_options:
172
- - --charset=UTF-8
173
- require_paths:
130
+ rdoc_options: []
131
+ require_paths:
174
132
  - lib
175
- required_ruby_version: !ruby/object:Gem::Requirement
176
- none: false
177
- requirements:
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
178
135
  - - ">="
179
- - !ruby/object:Gem::Version
180
- hash: 3
181
- segments:
182
- - 0
183
- version: "0"
184
- required_rubygems_version: !ruby/object:Gem::Requirement
185
- none: false
186
- requirements:
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
187
140
  - - ">="
188
- - !ruby/object:Gem::Version
189
- hash: 3
190
- segments:
191
- - 0
192
- version: "0"
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
193
143
  requirements: []
194
-
195
144
  rubyforge_project:
196
- rubygems_version: 1.3.7
145
+ rubygems_version: 2.4.5.1
197
146
  signing_key:
198
- specification_version: 3
147
+ specification_version: 4
199
148
  summary: Publishing logic for ActiveRecord models
200
- test_files:
201
- - spec/general_model_logic.rb
202
- - spec/models_with_all_fields_spec.rb
203
- - spec/models_with_no_published_until_field_spec.rb
204
- - spec/spec_helper.rb
205
- - spec/support/database_cleanliness.rb
206
- - spec/support/database_connection.rb
207
- - spec/support/database_migrations.rb
208
- - spec/support/factories.rb
209
- - spec/support/logging.rb
210
- - spec/support/models/article.rb
211
- - spec/support/models/programme.rb
149
+ test_files: []
data/README.rdoc DELETED
@@ -1,29 +0,0 @@
1
- = publishing_logic
2
-
3
- Publishing logic for ActiveRecord models
4
- * Generates a migration with fields required for publishing
5
- logic. Fields are:
6
- * publishing_enabled:boolean
7
- * published_at:datetime
8
- * published_until:datetime (optional)
9
- * Defines logic on models that include PublishingLogic::ModelLogic
10
- * published named scope
11
- * published? method
12
- * ordering by published_at
13
-
14
- The source for this gem can be found on http://github.com/unboxed/publishing_logic
15
-
16
- == Note on Patches/Pull Requests
17
-
18
- * Fork the project.
19
- * Make your feature addition or bug fix.
20
- * Add tests for it. This is important so I don't break it in a
21
- future version unintentionally.
22
- * Commit, do not mess with rakefile, version, or history.
23
- (if you want to have your own version, that is fine but
24
- bump version in a commit by itself I can ignore when I pull)
25
- * Send me a pull request. Bonus points for topic branches.
26
-
27
- == Copyright
28
-
29
- Copyright (c) 2009 Unboxed Consulting and Channel 5 Broadcasting Ltd. See LICENSE for details.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.0
data/lib/model_logic.rb DELETED
@@ -1,82 +0,0 @@
1
- module PublishingLogic
2
- module ModelLogic
3
-
4
- def self.included(base)
5
- module_to_include = if base.column_names.include?('published_until')
6
- WithPublishedUntilField
7
- else
8
- WithoutPublishedUntilField
9
- end
10
- base.class_eval do
11
- # If objects have identical published_at values, order by created_at. If these are
12
- # identical as well, then order by id. This is done to ensure there is a unique
13
- # ordering of objects, ordering by newest and oldest should result in arrays that are
14
- # the inverse of the other.
15
- named_scope :by_publication_date_oldest_first, :order => "#{base.table_name}.published_at ASC, #{base.table_name}.created_at ASC, #{base.table_name}.id ASC"
16
- named_scope :by_publication_date_newest_first, :order => "#{base.table_name}.published_at DESC, #{base.table_name}.created_at DESC, #{base.table_name}.id DESC"
17
-
18
- include module_to_include
19
-
20
- class << self
21
- def by_date_oldest_first
22
- ::ActiveSupport::Deprecation.warn("by_date_oldest_first is deprecated and will be removed in the next version of this gem (use by_publication_date_oldest_first instead, it's more intention revealing).", caller)
23
- by_publication_date_oldest_first
24
- end
25
-
26
- def by_date_newest_first
27
- ::ActiveSupport::Deprecation.warn("by_date_newest_first is deprecated and will be removed in the next version of this gem (use by_publication_date_newest_first instead, it's more intention revealing).", caller)
28
- by_publication_date_newest_first
29
- end
30
- end
31
- end
32
- end
33
-
34
- module WithoutPublishedUntilField
35
- def self.included(base)
36
- base.class_eval do
37
- named_scope :published, lambda {{ :conditions => ["#{base.table_name}.publishing_enabled = ? AND \
38
- (#{base.table_name}.published_at is null or #{base.table_name}.published_at < ?)",
39
- true, Time.now.utc] }} do
40
- def newest
41
- find(:first, :order => "#{proxy_scope.table_name}.published_at DESC")
42
- end
43
-
44
- def oldest
45
- find(:last, :order => "#{proxy_scope.table_name}.published_at DESC")
46
- end
47
- end
48
-
49
- def published?
50
- return false if published_at && Time.now < published_at
51
- publishing_enabled?
52
- end
53
- end
54
- end
55
- end
56
-
57
- module WithPublishedUntilField
58
- def self.included(base)
59
- base.class_eval do
60
- named_scope :published, lambda {{ :conditions => ["#{base.table_name}.publishing_enabled = ? AND \
61
- (#{base.table_name}.published_until is null or #{base.table_name}.published_until > ?) AND \
62
- (#{base.table_name}.published_at is null or #{base.table_name}.published_at < ?)",
63
- true, Time.now.utc, Time.now.utc] }} do
64
- def newest
65
- find(:first, :order => "#{proxy_scope.table_name}.published_at DESC")
66
- end
67
-
68
- def oldest
69
- find(:last, :order => "#{proxy_scope.table_name}.published_at DESC")
70
- end
71
- end
72
-
73
- def published?
74
- return false if published_at && Time.now < published_at
75
- return false if published_until && Time.now > published_until
76
- publishing_enabled?
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end