burgundy 0.3.0 → 0.4.0

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +13 -0
  3. data/.travis.yml +6 -5
  4. data/CHANGELOG.md +8 -0
  5. data/CODE_OF_CONDUCT.md +76 -0
  6. data/Gemfile +2 -0
  7. data/README.md +30 -0
  8. data/Rakefile +3 -1
  9. data/burgundy.gemspec +6 -2
  10. data/lib/burgundy.rb +2 -0
  11. data/lib/burgundy/collection.rb +4 -2
  12. data/lib/burgundy/item.rb +8 -2
  13. data/lib/burgundy/rails.rb +10 -6
  14. data/lib/burgundy/version.rb +3 -1
  15. data/test/dummy/Rakefile +3 -1
  16. data/test/dummy/app/controllers/application_controller.rb +2 -0
  17. data/test/dummy/app/helpers/application_helper.rb +2 -0
  18. data/test/dummy/bin/bundle +4 -2
  19. data/test/dummy/bin/rails +5 -3
  20. data/test/dummy/bin/rake +4 -2
  21. data/test/dummy/config.ru +3 -1
  22. data/test/dummy/config/application.rb +3 -3
  23. data/test/dummy/config/boot.rb +5 -3
  24. data/test/dummy/config/environment.rb +3 -1
  25. data/test/dummy/config/environments/development.rb +2 -0
  26. data/test/dummy/config/environments/production.rb +3 -1
  27. data/test/dummy/config/environments/test.rb +2 -0
  28. data/test/dummy/config/initializers/backtrace_silencers.rb +1 -0
  29. data/test/dummy/config/initializers/filter_parameter_logging.rb +2 -0
  30. data/test/dummy/config/initializers/inflections.rb +1 -0
  31. data/test/dummy/config/initializers/mime_types.rb +1 -0
  32. data/test/dummy/config/initializers/secret_token.rb +3 -1
  33. data/test/dummy/config/initializers/session_store.rb +3 -1
  34. data/test/dummy/config/initializers/wrap_parameters.rb +2 -0
  35. data/test/dummy/config/routes.rb +2 -0
  36. data/test/test_helper.rb +2 -0
  37. data/test/unit/burgundy_test.rb +42 -6
  38. metadata +35 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 627aed370f1235851c0330858cb8132589b2763dd1e98ce217950a4e3f610285
4
- data.tar.gz: 83c93daace0616835204810154b38b34c3ac9f325ca08d1dc4656118a2c30597
3
+ metadata.gz: 7b33ddf407012b8721c8c5c26266a676fe714a54adf4591587745c3aecd5fa2b
4
+ data.tar.gz: ebf9996be106b868511e5ed13ca78bc37c1d8442f72bd7a0b94cd7e3c09184fd
5
5
  SHA512:
6
- metadata.gz: 1c732548588122cda059ec94dbab67f6e3a722249df688f339b812a75ba45e0d1809538771a2f9979f7fc08ae07f360c70969363d426047c82a8405c6cf9eaa7
7
- data.tar.gz: 5dc524c77481653f1949e79ed8981e00cd9e1cfa1ab44781bdcd0ab2ef15b6e32bb9ed9fc1c0cf2ce6299c839b0f81a792f6419df1beaec20499e112d9da3e08
6
+ metadata.gz: 6c12a95c9d67b134241b436e5014b4fc87c8a5e7a43a537049df0ac38dab5389c36254c6b76728c227708c2dcc2cbf8efa72c80b10e699336d652a1b727ffb8e
7
+ data.tar.gz: 329a4ebf4eb90f7ed15dd50675a33546ca26f426f667c5810e32bc4f050d72b2dc2a51aa23f0dffe4bdb216c170cbac0069375e1d24cf285a67d5894e2fb7627
@@ -0,0 +1,13 @@
1
+ ---
2
+
3
+ inherit_gem:
4
+ rubocop-fnando: .rubocop.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.6
8
+ Exclude:
9
+ - test/dummy/**/*
10
+
11
+ Metrics/ClassLength:
12
+ Exclude:
13
+ - test/**/*
@@ -1,16 +1,17 @@
1
+ ---
1
2
  language: ruby
2
3
  sudo: false
3
4
  cache: bundler
4
5
  notifications:
5
6
  email: false
6
7
  rvm:
7
- - 2.5.2
8
+ - 2.5.2
8
9
  before_script:
9
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
10
- - chmod +x ./cc-test-reporter
11
- - "./cc-test-reporter before-build"
10
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
11
+ - chmod +x ./cc-test-reporter
12
+ - "./cc-test-reporter before-build"
12
13
  after_script:
13
- - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
14
+ - "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
14
15
  env:
15
16
  global:
16
17
  secure: LIU2voUl12O5yOXGTwOFOJgdv49YOpFN4FyH3Eqvc48tvy3cRypMuqvFiG/KL4jQvE2IydZZmG+DtsgTsi6kOe5cYlxeU2fTiK9dflNqBIV7+CfwXqguUAcwJLW1dt6Gtmis2VuOffJDBqpojTpFDrUosDdISc1gkOXh4+8yHQA=
@@ -1,3 +1,11 @@
1
+ ## [0.4.0] - 2019-12-10
2
+
3
+ - Add `Burgundy::Item#as_json(*)`, which returns `Burgundy::Item#attributes`.
4
+
5
+ ## [0.3.0] - 2018-12-26
6
+
7
+ - Stop using `Delegator` and use `method_missing` instead.
8
+
1
9
  ## [0.2.0] - 2015-10-14
2
10
 
3
11
  ### Added
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at me@fnando.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in burgundy.gemspec
data/README.md CHANGED
@@ -122,8 +122,13 @@ UserPresenter.new(User.first).to_hash
122
122
 
123
123
  UserPresenter.new(User.first).to_h
124
124
  #=> {:username=>'johndoe', :name=>'John Doe', :email=>'john@example.org'}
125
+
126
+ UserPresenter.new(User.first).as_json
127
+ #=> {:username=>'johndoe', :name=>'John Doe', :email=>'john@example.org'}
125
128
  ```
126
129
 
130
+ Notice that `as_json` will ignore any options provided.
131
+
127
132
  If you want to remap an attribute, provide a hash.
128
133
 
129
134
  ```ruby
@@ -146,3 +151,28 @@ UserPresenter.new(User.first).attributes
146
151
  3. Commit your changes (`git commit -am 'Add some feature'`)
147
152
  4. Push to the branch (`git push origin my-new-feature`)
148
153
  5. Create new Pull Request
154
+
155
+ ## License
156
+
157
+ Copyright (c) 2013 Nando Vieira
158
+
159
+ MIT License
160
+
161
+ Permission is hereby granted, free of charge, to any person obtaining
162
+ a copy of this software and associated documentation files (the
163
+ "Software"), to deal in the Software without restriction, including
164
+ without limitation the rights to use, copy, modify, merge, publish,
165
+ distribute, sublicense, and/or sell copies of the Software, and to
166
+ permit persons to whom the Software is furnished to do so, subject to
167
+ the following conditions:
168
+
169
+ The above copyright notice and this permission notice shall be
170
+ included in all copies or substantial portions of the Software.
171
+
172
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
173
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
174
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
175
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
176
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
177
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
178
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
 
@@ -7,4 +9,4 @@ Rake::TestTask.new(:test) do |t|
7
9
  t.warning = false
8
10
  end
9
11
 
10
- task :default => :test
12
+ task default: :test
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "./lib/burgundy/version"
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -5,12 +7,12 @@ Gem::Specification.new do |spec|
5
7
  spec.version = Burgundy::VERSION
6
8
  spec.authors = ["Nando Vieira"]
7
9
  spec.email = ["fnando.vieira@gmail.com"]
8
- spec.description = "A simple wrapper for objects (think of Burgundy as a decorator/presenter) in less than 100 lines."
10
+ spec.description = "A simple wrapper for objects in less than 100 lines."
9
11
  spec.summary = spec.description
10
12
  spec.homepage = "http://github.com/fnando/burgundy"
11
13
  spec.license = "MIT"
12
14
 
13
- spec.files = `git ls-files`.split($/)
15
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
14
16
  spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
15
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
18
  spec.require_paths = ["lib"]
@@ -20,5 +22,7 @@ Gem::Specification.new do |spec|
20
22
  spec.add_development_dependency "pry-meta"
21
23
  spec.add_development_dependency "rails"
22
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rubocop"
26
+ spec.add_development_dependency "rubocop-fnando"
23
27
  spec.add_development_dependency "simplecov"
24
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "delegate"
2
4
  require "burgundy/version"
3
5
  require "burgundy/item"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Burgundy
2
4
  class Collection
3
5
  def initialize(items, wrapping_class = nil, *args)
@@ -6,7 +8,7 @@ module Burgundy
6
8
  @args = args
7
9
  end
8
10
 
9
- def method_missing(name, *args, &block)
11
+ def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing, Style/MethodMissingSuper
10
12
  to_ary.send(name, *args, &block)
11
13
  end
12
14
 
@@ -21,6 +23,6 @@ module Burgundy
21
23
  @items.to_a
22
24
  end
23
25
  end
24
- alias_method :to_a, :to_ary
26
+ alias to_a to_ary
25
27
  end
26
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Burgundy
2
4
  class Item < SimpleDelegator
3
5
  attr_reader :item
@@ -38,7 +40,11 @@ module Burgundy
38
40
  end
39
41
  end
40
42
 
41
- alias_method :to_hash, :attributes
42
- alias_method :to_h, :attributes
43
+ def as_json(*)
44
+ attributes
45
+ end
46
+
47
+ alias to_hash attributes
48
+ alias to_h attributes
43
49
  end
44
50
  end
@@ -1,12 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Burgundy
2
4
  module UrlMethods
3
5
  def default_url_options
4
6
  action_mailer_default_url_options ||
5
- Rails.application.routes.default_url_options
7
+ Rails.application.routes.default_url_options
6
8
  end
7
9
 
8
10
  def action_mailer_default_url_options
9
- Rails.configuration.action_mailer.default_url_options if Rails.configuration.respond_to?(:action_mailer)
11
+ return unless Rails.configuration.respond_to?(:action_mailer)
12
+
13
+ Rails.configuration.action_mailer.default_url_options
10
14
  end
11
15
  end
12
16
 
@@ -20,7 +24,7 @@ module Burgundy
20
24
  def helpers
21
25
  ApplicationController.helpers
22
26
  end
23
- alias_method :h, :helpers
27
+ alias h helpers
24
28
  end
25
29
 
26
30
  module RouteHelpers
@@ -43,14 +47,14 @@ module Burgundy
43
47
  item.to_param
44
48
  end
45
49
 
46
- def eql?(obj)
47
- obj == self || item.eql?(obj)
50
+ def eql?(other)
51
+ other == self || item.eql?(other)
48
52
  end
49
53
 
50
54
  def routes
51
55
  self.class.routes
52
56
  end
53
- alias_method :r, :routes
57
+ alias r routes
54
58
  end
55
59
 
56
60
  class Item
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Burgundy
2
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
3
5
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
4
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
5
 
4
- require File.expand_path('../config/application', __FILE__)
6
+ require File.expand_path("config/application", __dir__)
5
7
 
6
8
  Dummy::Application.load_tasks
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ApplicationController < ActionController::Base
2
4
  # Prevent CSRF attacks by raising an exception.
3
5
  # For APIs, you may want to use :null_session instead.
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ApplicationHelper
2
4
  end
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
- load Gem.bin_path('bundler', 'bundle')
2
+ # frozen_string_literal: true
3
+
4
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
5
+ load Gem.bin_path("bundler", "bundle")
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- APP_PATH = File.expand_path('../../config/application', __FILE__)
3
- require_relative '../config/boot'
4
- require 'rails/commands'
2
+ # frozen_string_literal: true
3
+
4
+ APP_PATH = File.expand_path("../config/application", __dir__)
5
+ require_relative "../config/boot"
6
+ require "rails/commands"
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
- require_relative '../config/boot'
3
- require 'rake'
2
+ # frozen_string_literal: true
3
+
4
+ require_relative "../config/boot"
5
+ require "rake"
4
6
  Rake.application.run
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is used by Rack-based servers to start the application.
2
4
 
3
- require ::File.expand_path('../config/environment', __FILE__)
5
+ require ::File.expand_path("../config/environment", __FILE__)
4
6
  run Rails.application
@@ -1,8 +1,9 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("boot", __dir__)
2
4
 
3
5
  require "action_controller/railtie"
4
6
  require "action_mailer/railtie"
5
- require "sprockets/railtie"
6
7
 
7
8
  Bundler.require(*Rails.groups)
8
9
  require "burgundy"
@@ -11,4 +12,3 @@ module Dummy
11
12
  class Application < Rails::Application
12
13
  end
13
14
  end
14
-
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Set up gems listed in the Gemfile.
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
4
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
3
5
 
4
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5
- $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
6
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
7
+ $LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Load the Rails application.
2
- require File.expand_path('../application', __FILE__)
4
+ require File.expand_path("application", __dir__)
3
5
 
4
6
  # Initialize the Rails application.
5
7
  Dummy::Application.initialize!
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb.
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb.
3
5
 
@@ -33,7 +35,7 @@ Dummy::Application.configure do
33
35
  config.assets.digest = true
34
36
 
35
37
  # Version of your assets, change this if you want to expire all your assets.
36
- config.assets.version = '1.0'
38
+ config.assets.version = "1.0"
37
39
 
38
40
  # Specifies the header that your server uses for sending files.
39
41
  # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.configure do
2
4
  # Settings specified here will take precedence over those in config/application.rb.
3
5
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Be sure to restart your server when you modify this file.
2
3
 
3
4
  # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # Configure sensitive parameters which will be filtered from the log file.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Be sure to restart your server when you modify this file.
2
3
 
3
4
  # Add new inflection rules using the following format. Inflections
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Be sure to restart your server when you modify this file.
2
3
 
3
4
  # Add new mime types for use in respond_to blocks:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # Your secret key is used for verifying the integrity of signed cookies.
@@ -9,4 +11,4 @@
9
11
 
10
12
  # Make sure your secret_key_base is kept private
11
13
  # if you're sharing your code publicly.
12
- Dummy::Application.config.secret_key_base = 'ad57e0c56963bee4eca9bccd6a9a0f3d5a176af9fed341f4debccbb050326066a9181b9502ea296e838548f75b7df7962268ed89c51e13466975606c8737afef'
14
+ Dummy::Application.config.secret_key_base = "ad57e0c56963bee4eca9bccd6a9a0f3d5a176af9fed341f4debccbb050326066a9181b9502ea296e838548f75b7df7962268ed89c51e13466975606c8737afef"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
- Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
5
+ Dummy::Application.config.session_store :cookie_store, key: "_dummy_session"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Be sure to restart your server when you modify this file.
2
4
 
3
5
  # This file contains settings for ActionController::ParamsWrapper which
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Dummy::Application.routes.draw do
2
4
  get ":username", to: "application#users", as: "profile"
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "simplecov"
2
4
  SimpleCov.start do
3
5
  add_filter "/test/"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "test_helper"
2
4
 
3
5
  class BurgundyTest < Minitest::Test
@@ -27,7 +29,8 @@ class BurgundyTest < Minitest::Test
27
29
  end
28
30
 
29
31
  test "deprecates Burgundy::Item.map" do
30
- message = "Burgundy::Item.map is deprecated; use Burgundy::Item.wrap instead."
32
+ message =
33
+ "Burgundy::Item.map is deprecated; use Burgundy::Item.wrap instead."
31
34
 
32
35
  _, err = capture_io do
33
36
  wrapper.map([1, 2, 3])
@@ -80,6 +83,12 @@ class BurgundyTest < Minitest::Test
80
83
  assert_respond_to item, :h
81
84
  end
82
85
 
86
+ test "makes helpers accessible" do
87
+ item = wrapper.new("hello")
88
+
89
+ assert_equal "less than a minute", item.helpers.time_ago_in_words(Time.now)
90
+ end
91
+
83
92
  test "responds to the I18n methods" do
84
93
  item = wrapper.new("hello")
85
94
 
@@ -96,7 +105,11 @@ class BurgundyTest < Minitest::Test
96
105
  end
97
106
  end
98
107
 
99
- Rails.configuration.action_mailer.default_url_options = {host: "example.com"}
108
+ Rails
109
+ .configuration
110
+ .action_mailer
111
+ .default_url_options = {host: "example.com"}
112
+
100
113
  item = wrapper.new OpenStruct.new(username: "johndoe")
101
114
 
102
115
  assert_equal "http://example.com/johndoe", item.profile_url
@@ -115,12 +128,29 @@ class BurgundyTest < Minitest::Test
115
128
  assert_equal "http://example.com/johndoe", item.profile_url
116
129
  end
117
130
 
131
+ test "returns to_param" do
132
+ klass = Class.new do
133
+ def to_param
134
+ "some-param"
135
+ end
136
+ end
137
+
138
+ wrapper = Class.new(Burgundy::Item)
139
+ item = wrapper.new(klass.new)
140
+
141
+ assert_equal "some-param", item.to_param
142
+ end
143
+
118
144
  test "returns attributes" do
119
145
  wrapper = Class.new(Burgundy::Item) do
120
146
  attributes :name, :email
121
147
  end
122
148
 
123
- object = OpenStruct.new(name: "John Doe", email: "john@example.com", username: "johndoe")
149
+ object = OpenStruct.new(
150
+ name: "John Doe",
151
+ email: "john@example.com",
152
+ username: "johndoe"
153
+ )
124
154
  item = wrapper.new(object)
125
155
 
126
156
  expected = {name: "John Doe", email: "john@example.com"}
@@ -130,7 +160,7 @@ class BurgundyTest < Minitest::Test
130
160
 
131
161
  test "returns remaps attribute" do
132
162
  wrapper = Class.new(Burgundy::Item) do
133
- attributes :name, :username => :login
163
+ attributes :name, username: :login
134
164
  end
135
165
 
136
166
  object = OpenStruct.new(name: "John Doe", username: "johndoe")
@@ -141,16 +171,22 @@ class BurgundyTest < Minitest::Test
141
171
  assert_equal expected, item.attributes
142
172
  end
143
173
 
144
- test "implements to_hash/to_h protocol" do
174
+ test "implements to_hash/to_h/as_json protocols" do
145
175
  wrapper = Class.new(Burgundy::Item) do
146
176
  attributes :name, :email
147
177
  end
148
178
 
149
- object = OpenStruct.new(name: "John Doe", email: "john@example.com", username: "johndoe")
179
+ object = OpenStruct.new(
180
+ name: "John Doe",
181
+ email: "john@example.com",
182
+ username: "johndoe"
183
+ )
150
184
  item = wrapper.new(object)
151
185
 
152
186
  assert_equal item.to_hash, item.attributes
153
187
  assert_equal item.to_h, item.attributes
188
+ assert_equal item.as_json, item.attributes
189
+ assert_equal item.as_json(:name), item.attributes
154
190
  end
155
191
 
156
192
  test "inherits attributes" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: burgundy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-27 00:00:00.000000000 Z
11
+ date: 2019-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-fnando
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: simplecov
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -94,8 +122,7 @@ dependencies:
94
122
  - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
- description: A simple wrapper for objects (think of Burgundy as a decorator/presenter)
98
- in less than 100 lines.
125
+ description: A simple wrapper for objects in less than 100 lines.
99
126
  email:
100
127
  - fnando.vieira@gmail.com
101
128
  executables: []
@@ -103,8 +130,10 @@ extensions: []
103
130
  extra_rdoc_files: []
104
131
  files:
105
132
  - ".gitignore"
133
+ - ".rubocop.yml"
106
134
  - ".travis.yml"
107
135
  - CHANGELOG.md
136
+ - CODE_OF_CONDUCT.md
108
137
  - Gemfile
109
138
  - LICENSE.txt
110
139
  - README.md
@@ -175,12 +204,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
204
  - !ruby/object:Gem::Version
176
205
  version: '0'
177
206
  requirements: []
178
- rubyforge_project:
179
- rubygems_version: 2.7.6
207
+ rubygems_version: 3.0.3
180
208
  signing_key:
181
209
  specification_version: 4
182
- summary: A simple wrapper for objects (think of Burgundy as a decorator/presenter)
183
- in less than 100 lines.
210
+ summary: A simple wrapper for objects in less than 100 lines.
184
211
  test_files:
185
212
  - test/dummy/README.rdoc
186
213
  - test/dummy/Rakefile