resubject 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9622a9c1f2e6e745fb007dfb4c5171feefaafcf1
4
- data.tar.gz: 31a1819fdd559781b98612dfaf2f336a46d4bc31
3
+ metadata.gz: 5af4c75bfa632e18875bdb64492fa3a7454020d5
4
+ data.tar.gz: baa37ace997ee7b47ab2cdd1ebb6fcace4c049c5
5
5
  SHA512:
6
- metadata.gz: 58bdd1ed48e037f0b4774baf8cbe264f4274c4ffbf00658a4adafba2857f1bfb86877d4435322afca3e4f3cb02c73ac3f2d52912a4848fab7a1b2f2a12fe8a65
7
- data.tar.gz: caa9e377c606d3512ade4ec8fa23d3a3aad78ae534cc34dc073b97c77d06c71056c9c525cc6150472313409df300928012c33d57a682cf503864365720daace0
6
+ metadata.gz: 0ded2dd3031e370ed25f9d67c5b3512eba510d0bbcd3da2b77a277860d2d3556afc9cf8d68a0a66892ed392035572e2d0025e781e74ef538783c012e9787e7c5
7
+ data.tar.gz: 5f169109e23e0169dfbc514eccc5abe8dd545833271f693b3a2bf1bc86deb2b621e5fb2add954063e45629cae5f2adb3c76cf87d75c8a3a87fede2b9b9d11665
@@ -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'
@@ -1,3 +1,6 @@
1
+ # 0.2.2
2
+ - rubocop style changes
3
+
1
4
  # 0.2.1
2
5
  - update yard and nokogiri due to security vulnerabilities (only on dev environment)
3
6
 
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
@@ -11,7 +11,7 @@ Uber simple presenters using Ruby's SimpleDelegator.
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'resubject', '~> 0.2.1'
14
+ gem 'resubject', '~> 0.2.2'
15
15
  ```
16
16
 
17
17
  And then execute:
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 :default => :spec
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 = ['lib/**/*.rb']
12
+ t.files = ['lib/**/*.rb']
13
13
  end
@@ -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.new("Expected a presenter in #{presenters.inspect}")
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("4")
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
@@ -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
- when Symbol
19
- presentable.to_s
20
- when String
21
- presentable
22
- else
23
- presentable.class.to_s
24
- end
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
 
@@ -5,8 +5,8 @@ module Resubject
5
5
  extend Resubject::Extensions::TemplateMethods
6
6
 
7
7
  # the HTML helpers context
8
- attr_reader :context
9
- alias_method :template, :context
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
- alias_method :to_model, :__getobj__
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
- private
87
+ private
88
88
 
89
89
  def translate(*args, &block)
90
90
  context.t(*args, &block)
91
91
  end
92
92
 
93
- alias_method :t, :translate
93
+ alias t translate
94
94
 
95
95
  def localize(*args, &block)
96
96
  context.l(*args, &block)
97
97
  end
98
98
 
99
- alias_method :l, :localize
99
+ alias l localize
100
100
 
101
101
  def helpers
102
102
  context
103
103
  end
104
104
 
105
- alias_method :h, :helpers
105
+ alias h helpers
106
106
  end
107
107
  end
@@ -8,6 +8,6 @@ module Resubject
8
8
  ::Rails.application.routes.url_helpers
9
9
  end
10
10
 
11
- alias_method :r, :routes
11
+ alias r routes
12
12
  end
13
13
  end
@@ -1,6 +1,6 @@
1
1
  module Resubject
2
2
  class Engine < ::Rails::Engine #:nodoc:
3
- initializer "resubject.helpers" do
3
+ initializer 'resubject.helpers' do
4
4
  ActiveSupport.on_load(:action_controller) do
5
5
  require 'resubject/rails/helpers'
6
6
  include Resubject::Helpers
@@ -14,9 +14,7 @@ module Resubject
14
14
  presenters = Builder.present(objects, view_context, *presenters)
15
15
 
16
16
  presenters.tap do |p|
17
- if block_given?
18
- yield p
19
- end
17
+ yield p if block_given?
20
18
  end
21
19
  end
22
20
  end
@@ -46,13 +46,13 @@ module Resubject
46
46
  end
47
47
 
48
48
  ::RSpec.configure do |c|
49
- if ::RSpec::Core::Version::STRING.split(".").first.to_i >= 3
49
+ if ::RSpec::Core::Version::STRING.split('.').first.to_i >= 3
50
50
  c.include Resubject::Rspec,
51
- type: :presenter,
52
- file_path: %r(spec/presenters)
51
+ type: :presenter,
52
+ file_path: %r{spec/presenters}
53
53
  else
54
54
  c.include Resubject::Rspec,
55
- type: :presenter,
56
- example_group: { file_path: %r(spec/presenters) }
55
+ type: :presenter,
56
+ example_group: { file_path: %r{spec/presenters} }
57
57
  end
58
58
  end
@@ -1,3 +1,3 @@
1
1
  module Resubject
2
- VERSION = "0.2.1"
2
+ VERSION = '0.2.2'.freeze
3
3
  end
@@ -1,26 +1,26 @@
1
- # -*- encoding: utf-8 -*-
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 = "resubject"
7
+ gem.name = 'resubject'
8
8
  gem.version = Resubject::VERSION
9
- gem.authors = ["Felipe Elias Philipp", "Piotr Jakubowski"]
10
- gem.email = ["felipe@applicake.com", "piotr.jakubowski@applicake.com"]
11
- gem.description = %q{Uber simple presenters}
12
- gem.summary = %q{Uber simple presenters using Ruby's SimpleDelegator}
13
- gem.homepage = "https://github.com/felipeelias/resubject"
14
- gem.license = "MIT"
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 = ["lib"]
19
+ gem.require_paths = ['lib']
20
20
 
21
21
  gem.add_dependency 'activesupport', '>= 3.2'
22
22
 
23
- gem.add_development_dependency "rake"
24
- gem.add_development_dependency "rspec", "~> 2.12.0"
25
- gem.add_development_dependency "yard", "~> 0.9"
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
- presented = Resubject::Builder.present_one Box.new, template, *presenters
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, *[nil, Class.new]
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 "$10.00"
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 "about 1 hour"
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 "95%"
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(1358082653).utc)
49
- expect(subject.created_at).to eq "13 Jan 13:10"
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 "Namespaced::Box"
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) { mock :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, :item => Item.new
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, :item => nil
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, :other_item => stub
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.1
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