resubject 0.2.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/.rubocop.yml +28 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +3 -2
- data/README.md +1 -1
- data/Rakefile +2 -2
- data/lib/resubject/builder.rb +1 -1
- data/lib/resubject/extensions/template_methods.rb +1 -1
- data/lib/resubject/naming.rb +7 -7
- data/lib/resubject/presenter.rb +7 -7
- data/lib/resubject/rails.rb +1 -1
- data/lib/resubject/rails/engine.rb +1 -1
- data/lib/resubject/rails/helpers.rb +1 -3
- data/lib/resubject/rspec.rb +5 -5
- data/lib/resubject/version.rb +1 -1
- data/resubject.gemspec +14 -14
- data/spec/resubject/builder_spec.rb +2 -2
- data/spec/resubject/extensions/template_methods_spec.rb +5 -5
- data/spec/resubject/naming_spec.rb +1 -1
- data/spec/resubject/presenter_spec.rb +4 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5af4c75bfa632e18875bdb64492fa3a7454020d5
|
4
|
+
data.tar.gz: baa37ace997ee7b47ab2cdd1ebb6fcace4c049c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ded2dd3031e370ed25f9d67c5b3512eba510d0bbcd3da2b77a277860d2d3556afc9cf8d68a0a66892ed392035572e2d0025e781e74ef538783c012e9787e7c5
|
7
|
+
data.tar.gz: 5f169109e23e0169dfbc514eccc5abe8dd545833271f693b3a2bf1bc86deb2b621e5fb2add954063e45629cae5f2adb3c76cf87d75c8a3a87fede2b9b9d11665
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Metrics/AbcSize:
|
2
|
+
Max: 20
|
3
|
+
|
4
|
+
Metrics/BlockLength:
|
5
|
+
Exclude:
|
6
|
+
- 'spec/**/*'
|
7
|
+
- 'test/**/*'
|
8
|
+
|
9
|
+
Metrics/LineLength:
|
10
|
+
Max: 103
|
11
|
+
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Max: 15
|
14
|
+
Exclude:
|
15
|
+
- 'spec/**/*'
|
16
|
+
- 'test/**/*'
|
17
|
+
|
18
|
+
Style/AsciiComments:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/Documentation:
|
22
|
+
Exclude:
|
23
|
+
- 'spec/**/*'
|
24
|
+
- 'test/**/*'
|
25
|
+
- 'lib/resubject/builder.rb'
|
26
|
+
- 'lib/resubject/naming.rb'
|
27
|
+
- 'lib/resubject/presenter.rb'
|
28
|
+
- 'lib/resubject/rails.rb'
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -5,8 +5,9 @@ source 'https://rubygems.org'
|
|
5
5
|
rails_version = ENV['rails']
|
6
6
|
gem 'actionpack', "~> #{rails_version}"
|
7
7
|
|
8
|
-
gem 'redcarpet'
|
9
|
-
gem 'rake', '< 11.0'
|
10
8
|
gem 'nokogiri', '~> 1.8'
|
9
|
+
gem 'rake', '< 11.0'
|
10
|
+
gem 'redcarpet'
|
11
|
+
gem 'rubocop'
|
11
12
|
# Specify your gem's dependencies in resubject.gemspec
|
12
13
|
gemspec
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -3,11 +3,11 @@ require 'rspec/core/rake_task'
|
|
3
3
|
require 'yard'
|
4
4
|
|
5
5
|
desc 'Default: run specs.'
|
6
|
-
task :
|
6
|
+
task default: :spec
|
7
7
|
|
8
8
|
desc 'Run all specs'
|
9
9
|
RSpec::Core::RakeTask.new(:spec)
|
10
10
|
|
11
11
|
YARD::Rake::YardocTask.new do |t|
|
12
|
-
t.files
|
12
|
+
t.files = ['lib/**/*.rb']
|
13
13
|
end
|
data/lib/resubject/builder.rb
CHANGED
@@ -69,7 +69,7 @@ module Resubject
|
|
69
69
|
presenters = [Naming.presenter_for(object)] unless presenters.any?
|
70
70
|
|
71
71
|
unless presenters.all? { |p| p.is_a?(Class) && p.ancestors.include?(Resubject::Presenter) }
|
72
|
-
raise InvalidPresenterArgument
|
72
|
+
raise InvalidPresenterArgument, "Expected a presenter in #{presenters.inspect}"
|
73
73
|
end
|
74
74
|
|
75
75
|
presenters.inject(object) do |presented, klass|
|
@@ -47,7 +47,7 @@ module Resubject
|
|
47
47
|
# @param [Symbol] attribute the name of the attribute to be generated
|
48
48
|
# @see http://apidock.com/rails/ActionView/Helpers/DateHelper/time_ago_in_words
|
49
49
|
def time_ago(attribute, include_seconds = false)
|
50
|
-
if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new(
|
50
|
+
if Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new('4')
|
51
51
|
define_method attribute do
|
52
52
|
return if to_model.send(attribute).nil?
|
53
53
|
template.time_ago_in_words to_model.send(attribute), include_seconds
|
data/lib/resubject/naming.rb
CHANGED
@@ -15,13 +15,13 @@ module Resubject
|
|
15
15
|
# @return [Presenter] the related presenter class based on the object
|
16
16
|
def self.presenter_for(presentable)
|
17
17
|
klass = case presentable
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
when Symbol
|
19
|
+
presentable.to_s
|
20
|
+
when String
|
21
|
+
presentable
|
22
|
+
else
|
23
|
+
presentable.class.to_s
|
24
|
+
end
|
25
25
|
|
26
26
|
presenter = "#{klass.camelize}Presenter"
|
27
27
|
|
data/lib/resubject/presenter.rb
CHANGED
@@ -5,8 +5,8 @@ module Resubject
|
|
5
5
|
extend Resubject::Extensions::TemplateMethods
|
6
6
|
|
7
7
|
# the HTML helpers context
|
8
|
-
attr_reader
|
9
|
-
|
8
|
+
attr_reader :context
|
9
|
+
alias template context
|
10
10
|
|
11
11
|
# Create a new presenter
|
12
12
|
#
|
@@ -23,7 +23,7 @@ module Resubject
|
|
23
23
|
super(model)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
alias to_model __getobj__
|
27
27
|
|
28
28
|
# Builds a collection of presenters given an array of objects
|
29
29
|
#
|
@@ -84,24 +84,24 @@ module Resubject
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
-
|
87
|
+
private
|
88
88
|
|
89
89
|
def translate(*args, &block)
|
90
90
|
context.t(*args, &block)
|
91
91
|
end
|
92
92
|
|
93
|
-
|
93
|
+
alias t translate
|
94
94
|
|
95
95
|
def localize(*args, &block)
|
96
96
|
context.l(*args, &block)
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
alias l localize
|
100
100
|
|
101
101
|
def helpers
|
102
102
|
context
|
103
103
|
end
|
104
104
|
|
105
|
-
|
105
|
+
alias h helpers
|
106
106
|
end
|
107
107
|
end
|
data/lib/resubject/rails.rb
CHANGED
data/lib/resubject/rspec.rb
CHANGED
@@ -46,13 +46,13 @@ module Resubject
|
|
46
46
|
end
|
47
47
|
|
48
48
|
::RSpec.configure do |c|
|
49
|
-
if ::RSpec::Core::Version::STRING.split(
|
49
|
+
if ::RSpec::Core::Version::STRING.split('.').first.to_i >= 3
|
50
50
|
c.include Resubject::Rspec,
|
51
|
-
|
52
|
-
|
51
|
+
type: :presenter,
|
52
|
+
file_path: %r{spec/presenters}
|
53
53
|
else
|
54
54
|
c.include Resubject::Rspec,
|
55
|
-
|
56
|
-
|
55
|
+
type: :presenter,
|
56
|
+
example_group: { file_path: %r{spec/presenters} }
|
57
57
|
end
|
58
58
|
end
|
data/lib/resubject/version.rb
CHANGED
data/resubject.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'resubject/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
|
-
gem.name =
|
7
|
+
gem.name = 'resubject'
|
8
8
|
gem.version = Resubject::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
11
|
-
gem.description =
|
12
|
-
gem.summary =
|
13
|
-
gem.homepage =
|
14
|
-
gem.license =
|
9
|
+
gem.authors = ['Felipe Elias Philipp', 'Piotr Jakubowski']
|
10
|
+
gem.email = ['felipe@applicake.com', 'piotr.jakubowski@applicake.com']
|
11
|
+
gem.description = 'Uber simple presenters'
|
12
|
+
gem.summary = "Uber simple presenters using Ruby's SimpleDelegator"
|
13
|
+
gem.homepage = 'https://github.com/felipeelias/resubject'
|
14
|
+
gem.license = 'MIT'
|
15
15
|
|
16
|
-
gem.files = `git ls-files`.split(
|
17
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
-
gem.require_paths = [
|
19
|
+
gem.require_paths = ['lib']
|
20
20
|
|
21
21
|
gem.add_dependency 'activesupport', '>= 3.2'
|
22
22
|
|
23
|
-
gem.add_development_dependency
|
24
|
-
gem.add_development_dependency
|
25
|
-
gem.add_development_dependency
|
23
|
+
gem.add_development_dependency 'rake'
|
24
|
+
gem.add_development_dependency 'rspec', '~> 2.12.0'
|
25
|
+
gem.add_development_dependency 'yard', '~> 0.9'
|
26
26
|
end
|
@@ -28,12 +28,12 @@ describe Resubject::Builder do
|
|
28
28
|
it 'presents the object with multiple classes' do
|
29
29
|
OtherBoxPresenter.should_receive(:new).twice
|
30
30
|
presenters = [OtherBoxPresenter, OtherBoxPresenter]
|
31
|
-
|
31
|
+
Resubject::Builder.present_one Box.new, template, *presenters
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'raises an error if custom presenter is not a presenter' do
|
35
35
|
expect do
|
36
|
-
Resubject::Builder.present_one Box.new, template,
|
36
|
+
Resubject::Builder.present_one Box.new, template, nil, Class.new
|
37
37
|
end.to raise_error(Resubject::Builder::InvalidPresenterArgument)
|
38
38
|
end
|
39
39
|
end
|
@@ -20,14 +20,14 @@ describe Resubject::Presenter, 'template methods' do
|
|
20
20
|
describe '.currency' do
|
21
21
|
it 'returns currency format' do
|
22
22
|
model.should_receive(:price).and_return(10.0)
|
23
|
-
expect(subject.price).to eq
|
23
|
+
expect(subject.price).to eq '$10.00'
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe '.time_ago' do
|
28
28
|
it 'returns time ago in words' do
|
29
29
|
model.stub(:posted_at).and_return(Time.now - 60 * 60)
|
30
|
-
expect(subject.posted_at).to eq
|
30
|
+
expect(subject.posted_at).to eq 'about 1 hour'
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'returns nothing if value is nil' do
|
@@ -39,14 +39,14 @@ describe Resubject::Presenter, 'template methods' do
|
|
39
39
|
describe '.percentage' do
|
40
40
|
it 'returns formatted percentage' do
|
41
41
|
model.stub(:rating).and_return(95.123)
|
42
|
-
expect(subject.rating).to eq
|
42
|
+
expect(subject.rating).to eq '95%'
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
describe '.date_format' do
|
47
47
|
it 'returns formatted date' do
|
48
|
-
model.stub(:created_at).and_return(Time.at(
|
49
|
-
expect(subject.created_at).to eq
|
48
|
+
model.stub(:created_at).and_return(Time.at(1_358_082_653).utc)
|
49
|
+
expect(subject.created_at).to eq '13 Jan 13:10'
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'returns nothing if value is nil' do
|
@@ -28,7 +28,7 @@ describe Resubject::Naming do
|
|
28
28
|
stub_const 'Namespaced', Class.new
|
29
29
|
stub_const 'Namespaced::BoxPresenter', Class.new
|
30
30
|
|
31
|
-
presenter = Resubject::Naming.presenter_for
|
31
|
+
presenter = Resubject::Naming.presenter_for 'Namespaced::Box'
|
32
32
|
|
33
33
|
expect(presenter).to eq Namespaced::BoxPresenter
|
34
34
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Resubject::Presenter do
|
4
|
-
let(:object)
|
4
|
+
let(:object) { mock :object }
|
5
5
|
|
6
6
|
subject { Resubject::Presenter.new(object) }
|
7
7
|
|
@@ -49,19 +49,19 @@ describe Resubject::Presenter do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'generates a method preseting the attribute' do
|
52
|
-
box = stub :box, :
|
52
|
+
box = stub :box, item: Item.new
|
53
53
|
|
54
54
|
expect(presenter.new(box).item).to be_a ItemPresenter
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'does not attempt to find a class from nil' do
|
58
|
-
box = stub :box, :
|
58
|
+
box = stub :box, item: nil
|
59
59
|
|
60
60
|
expect(presenter.new(box).item).to be_nil
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'presents the attributes with custom presenter' do
|
64
|
-
box = stub :box, :
|
64
|
+
box = stub :box, other_item: stub
|
65
65
|
|
66
66
|
expect(presenter.new(box).other_item).to be_a ItemPresenter
|
67
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resubject
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Elias Philipp
|
@@ -77,6 +77,7 @@ extra_rdoc_files: []
|
|
77
77
|
files:
|
78
78
|
- ".gitignore"
|
79
79
|
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
80
81
|
- ".travis.yml"
|
81
82
|
- ".yardopts"
|
82
83
|
- CHANGELOG.md
|