template_params 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1774f101a9565ae51656039844c05925f80b46d
4
- data.tar.gz: bb4459fed7f5bd7b606d7cf4249fd4b856d41e6d
3
+ metadata.gz: 8b1cf802577dadb1e6b66d780aa233b362d7b98b
4
+ data.tar.gz: dd783b0cd18b60cf08aaf1422ace70b483790a2e
5
5
  SHA512:
6
- metadata.gz: ebc359d467d0252da1d434900eb4fd14dbf36a5537da07130ca42d555921ea93e71cd6f05ad9ab8e3e7ca049c84adf2219ff13499848f42f9aefc3ff7957981d
7
- data.tar.gz: c77f65ca1a5c9eca6575d9c6578ea2bef4a7b0d1dddcdc7d19fc47da033a1dfff95fadf8961fe96a212d5e414e0b6ef69c34ebb6a5303d297ec217b36acd528c
6
+ metadata.gz: 98592ae0903886adcdda4806cb46ebca78fd6dd103d32b34495bc696b0f8c151ef16f75e2c63a87de58a526666fe0f604223cc72a87af7cfb18d02ffe73b6c14
7
+ data.tar.gz: 1f8538a1ce7aa5f6fc9db3fe5fe20fad09ca624dc70ff696bc2bc8dacd99b2c7af116449523e34880a07fa61b0f3bb4f5ef72142083d7b4a4e910e86b712d069
data/.rubocop.yml ADDED
@@ -0,0 +1,107 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+
4
+ # The number of lines in a method is not a useful metric compared to `AbcSize`.
5
+ # It's common to have very long methods (> 50 lines) which are quite simple. For
6
+ # example, a method that returns a long string with only a few interpolations.
7
+ Metrics/MethodLength:
8
+ Enabled: false
9
+
10
+ Style/AlignParameters:
11
+ EnforcedStyle: with_fixed_indentation
12
+
13
+ # Use the semantic style. If a block has side effects use `do`, and if it is
14
+ # pure use `{}`. This style is too nuanced for a linter, so the cop is
15
+ # disabled.
16
+ Style/BlockDelimiters:
17
+ Enabled: false
18
+
19
+ Style/BracesAroundHashParameters:
20
+ EnforcedStyle: context_dependent
21
+
22
+ # Used consistently, both leading and trailing styles are valid, but
23
+ # Singlebrook happens to use the trailing style.
24
+ Style/DotPosition:
25
+ EnforcedStyle: trailing
26
+
27
+ # Use double negation wherever it would otherwise be impractical to convert
28
+ # a value to an actual boolean.
29
+ Style/DoubleNegation:
30
+ Enabled: false
31
+
32
+ Style/EmptyElse:
33
+ EnforcedStyle: empty
34
+
35
+ # Use a postfix (aka. modifier) conditional operator for single lines unless
36
+ # doing so would exceed 60 chars.
37
+ Style/IfUnlessModifier:
38
+ MaxLineLength: 60
39
+
40
+ # The decision about when to use a guard clause is too nuanced for a linter.
41
+ Style/GuardClause:
42
+ Enabled: false
43
+
44
+ # In a multiline method call, put the closing parenthesis on its own line.
45
+ # The first argument may either be on the first line, or the second. Both of the
46
+ # following are correct:
47
+ #
48
+ # ```
49
+ # # A. correct
50
+ # create(:user,
51
+ # client: foo,
52
+ # long_line: blah
53
+ # )
54
+ #
55
+ # # B. also correct
56
+ # create(
57
+ # :user,
58
+ # client: foo,
59
+ # long_line: blah
60
+ # )
61
+ #
62
+ # # C. not preferred
63
+ # user = create :user,
64
+ # client: foo,
65
+ # long_line: blah
66
+ # ```
67
+ #
68
+ # Rubocop supports B, but not A. This project allows both, so this cop is
69
+ # disabled.
70
+ Style/MultilineMethodCallBraceLayout:
71
+ Enabled: false
72
+
73
+ Style/MultilineMethodCallIndentation:
74
+ EnforcedStyle: indented
75
+
76
+ Style/MultilineOperationIndentation:
77
+ EnforcedStyle: indented
78
+
79
+ # This is a new cop in rubocop 0.41, and I'm not sure if I want to adopt it yet.
80
+ Style/NumericLiteralPrefix:
81
+ Enabled: false
82
+
83
+ # Use `x > 0` because it is more specific than `x.positive?`.
84
+ # However, `x.zero?` is acceptable because it is specific enough.
85
+ Style/NumericPredicate:
86
+ Enabled: false
87
+
88
+ # This is a new cop, and has a bug: https://github.com/bbatsov/rubocop/issues/3515
89
+ # When that bug is fixed, we can try it again.
90
+ Style/SafeNavigation:
91
+ Enabled: false
92
+
93
+ # The decision between double quotes and single quotes is not something Leon
94
+ # or I feel strongly about, but we might as well be consistent, especially if
95
+ # rubocop is going to `--auto-correct` for us. Double quotes are slightly
96
+ # easier to read and there is no difference in performance. -Jared 2016-02-18
97
+ Style/StringLiterals:
98
+ EnforcedStyle: double_quotes
99
+
100
+ # Predicate methods, aka. question-mark methods, such as `def x?; @x; end` are
101
+ # acceptable. See https://github.com/bbatsov/rubocop/issues/2736 for discussion.
102
+ Style/TrivialAccessors:
103
+ AllowPredicates: true
104
+
105
+ # Use numbers wherever you like in your variables. Who cares.
106
+ Style/VariableNumber:
107
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # template_params Changelog
2
+
3
+ ## 0.1.1 (2016-10-10)
4
+
5
+ Just updating a few development tools and writing a little documentation.
6
+
7
+ Breaking changes
8
+
9
+ - None
10
+
11
+ New features
12
+
13
+ - None
14
+
15
+ Fixed
16
+
17
+ - None
18
+
19
+ ## 0.1.0
20
+
21
+ Initial release
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+ source "https://rubygems.org"
2
3
 
3
4
  # Specify your gem's dependencies in template_params.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -1,37 +1,37 @@
1
1
  # TemplateParams
2
2
 
3
- Runtime type-check for template preconditions, including instance variables
4
- and local variables. Think of this as the method signature of a template.
5
- There should be at least one of these assertions in almost every template.
3
+ Runtime type-check for **template preconditions**, including instance variables and local
4
+ variables. Think of this as the method signature of a template, as the **documentation**.
6
5
 
7
6
  ## Installation
8
7
 
9
- Add this line to your application's Gemfile:
8
+ 1. Add it to your Gemfile and run `bundle`.
10
9
 
11
- ```ruby
12
- gem 'template_params'
13
- ```
10
+ ```ruby
11
+ gem 'template_params'
12
+ ```
14
13
 
15
- then run `bundle`.
14
+ 2. If you're using rails, add a helper method.
16
15
 
17
- ## Usage
16
+ ```ruby
17
+ # app/helpers/application_helper.rb
18
+ def template_param(*args, &block)
19
+ ::TemplateParams::Assertion.assert(*args, &block)
20
+ end
21
+ ```
18
22
 
19
- In rails, you may want a helper method like this:
23
+ If you're not using rails, let me know how you install it, and I'll put that here.
20
24
 
21
- ```ruby
22
- # app/helpers/application_helper.rb
23
- require "template_params"
24
- def template_param(*args, &block)
25
- ::TemplateParams::Assertion.assert(*args, &block)
26
- end
25
+ ## Usage
27
26
 
27
+ ```ruby
28
28
  # Assert `poll` is defined. If not, raises an `ArgumentError` (the "arguments"
29
29
  # of the template are invalid).
30
- template_param { poll }
30
+ template_param { poll }
31
31
 
32
32
  # Assert `@course` is defined. Meaningless because instance variables are
33
33
  # always defined.
34
- template_param { @course }
34
+ template_param { @course }
35
35
 
36
36
  # Assert `poll.is_a?(::Poll)`. If not, raises a `TypeError`.
37
37
  template_param(::Poll) { poll }
data/Rakefile CHANGED
@@ -1,6 +1,15 @@
1
+ # frozen_string_literal: true
1
2
  require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ require "rubocop/rake_task"
5
+ RuboCop::RakeTask.new
6
+
7
+ require "rspec/core/rake_task"
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.verbose = false
10
+ end
5
11
 
6
- task :default => :spec
12
+ # Default task: lint then test
13
+ task default: [] # in case it hasn't been set
14
+ Rake::Task[:default].clear
15
+ task default: [:rubocop, :spec]
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "template_params"
data/bin/rake ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rake", "rake")
data/bin/rubocop ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rubocop' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rubocop", "rubocop")
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  require "template_params/version"
2
3
  require "template_params/assertion"
3
4
 
5
+ # Runtime type-checks for template preconditions.
4
6
  module TemplateParams
5
7
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
1
2
  require "method_source"
2
3
 
3
4
  module TemplateParams
5
+ # A simple assertion suitable for view template preconditions.
4
6
  class Assertion
5
-
6
7
  # @api public
7
8
  def initialize(type, options)
8
9
  @type = type
@@ -45,7 +46,7 @@ module TemplateParams
45
46
  # @api private
46
47
  def assert_type(value)
47
48
  unless @type.nil? || value.is_a?(@type) || allow_nil && value.nil?
48
- fail TypeError, format("Expected %s, got %s", @type, value.class)
49
+ raise TypeError, format("Expected %s, got %s", @type, value.class)
49
50
  end
50
51
  end
51
52
 
@@ -59,11 +60,12 @@ module TemplateParams
59
60
  #
60
61
  # @api private
61
62
  def udef_msg(name_error, block)
62
- msg = "Undefined template parameter: #{name_error}"
63
+ prefix = "Undefined template parameter: #{name_error}"
63
64
  if block.respond_to?(:source)
64
- msg << ": " + block.source.strip
65
+ format("%s: %s", prefix, block.source.strip)
66
+ else
67
+ prefix
65
68
  end
66
- msg
67
69
  end
68
70
  end
69
71
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module TemplateParams
2
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
3
4
  end
@@ -1,22 +1,26 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+ # frozen_string_literal: true
3
+ lib = File.expand_path("../lib", __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'template_params/version'
5
+ require "template_params/version"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "template_params"
8
- spec.version = TemplateParams::VERSION
9
- spec.authors = ["Jared Beck"]
10
- spec.email = ["jared@jaredbeck.com"]
11
- spec.summary = "Parameter assertions for your view templates"
12
- spec.homepage = "https://github.com/jaredbeck/template_params"
13
- spec.license = "MIT"
14
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
- spec.bindir = "exe"
16
- spec.executables = []
8
+ spec.name = "template_params"
9
+ spec.version = TemplateParams::VERSION
10
+ spec.authors = ["Jared Beck"]
11
+ spec.email = ["jared@jaredbeck.com"]
12
+ spec.summary = "Parameter assertions for your view templates"
13
+ spec.homepage = "https://github.com/jaredbeck/template_params"
14
+ spec.license = "MIT"
15
+ spec.files = `git ls-files -z`.
16
+ split("\x0").
17
+ reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = []
17
20
  spec.require_paths = ["lib"]
18
21
  spec.add_runtime_dependency "method_source", "~> 0.8.2"
19
22
  spec.add_development_dependency "bundler", "~> 1.10"
20
23
  spec.add_development_dependency "rake", "~> 10.0"
21
24
  spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "rubocop"
22
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: template_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Beck
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-30 00:00:00.000000000 Z
11
+ date: 2016-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description:
70
84
  email:
71
85
  - jared@jaredbeck.com
@@ -75,13 +89,17 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - ".gitignore"
77
91
  - ".rspec"
92
+ - ".rubocop.yml"
78
93
  - ".travis.yml"
94
+ - CHANGELOG.md
79
95
  - CODE_OF_CONDUCT.md
80
96
  - Gemfile
81
97
  - LICENSE.txt
82
98
  - README.md
83
99
  - Rakefile
84
100
  - bin/console
101
+ - bin/rake
102
+ - bin/rubocop
85
103
  - bin/setup
86
104
  - lib/template_params.rb
87
105
  - lib/template_params/assertion.rb
@@ -107,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
125
  version: '0'
108
126
  requirements: []
109
127
  rubyforge_project:
110
- rubygems_version: 2.4.5.1
128
+ rubygems_version: 2.5.1
111
129
  signing_key:
112
130
  specification_version: 4
113
131
  summary: Parameter assertions for your view templates