media_types-serialization 0.3.0 → 0.3.1

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
  SHA256:
3
- metadata.gz: d00191a59e5d1c2df575e66ade4f41fcf525cb4c1ea5878eeeb8a8cc2b86b3a5
4
- data.tar.gz: 27c6b628de9e717955a1d3f9fcc548ac5f3d253cc392ea7cf5d1ed50a1b851fe
3
+ metadata.gz: 3a1225815ea23d47af5c71f2dd37d409c01f0ed8d89cdb19749293b69f97f36d
4
+ data.tar.gz: 2461ce3d3411bcffe257388d6664f923e7e08254c85a4cfa25515d0120afce81
5
5
  SHA512:
6
- metadata.gz: 7486b226c973e8e2aba5b3ed4c1b0054530717dec192fecd17412a10def1436718337d851dac0defeaae58cd95e1f494811b4bd42faa967c8fba1f8ce27984ee
7
- data.tar.gz: 0c88f619c963cc0feb0a8dea38cc567bbd2c541211b245a06fa48a55f6aac221e0d8885ab7253a227f0f90d9f29e9d0791e2d285b0afb7799164416098c30d4a
6
+ metadata.gz: 69bfd29c4c01120ea65ef06a6cb0d5814004a390affcf310b89fb4114f43d8f07888dd14162ebb41b07a681bda20b394ad83db14e758b6d648ddea5841785239
7
+ data.tar.gz: 7eeafca27e995fad16bd1f0a9e3e9a5f655b977765e73bb66ae7ed42dae4dc6350864e0376bf061039fc532ea0756761622ee43334a218c1fec5d28f57a1d2e1
data/.gitignore CHANGED
@@ -1,12 +1,12 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- .idea/workspace.xml
11
- .idea/usage.statistics.xml
12
- .idea/tasks.xml
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .idea/workspace.xml
11
+ .idea/usage.statistics.xml
12
+ .idea/tasks.xml
data/.idea/.rakeTasks CHANGED
@@ -4,4 +4,4 @@ You are allowed to:
4
4
  1. Remove rake task
5
5
  2. Add existing rake tasks
6
6
  To add existing rake tasks automatically delete this file and reload the project.
7
- --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build media_types-serialization-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install media_types-serialization-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install media_types-serialization-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push media_types-serialization-0.1.0.gem to TODO: Set to 'http://mygemserver.com'" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build media_types-serialization-0.3.1.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install media_types-serialization-0.3.1.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install media_types-serialization-0.3.1.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.3.1 and build and push media_types-serialization-0.3.1.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" addBOMForNewFiles="with NO BOM" />
4
+ </project>
@@ -1,6 +1,6 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
- </profile>
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ </profile>
6
6
  </component>
@@ -1,20 +1,20 @@
1
- <component name="ProjectRunConfigurationManager">
2
- <configuration default="false" name="test" type="RakeRunConfigurationType" factoryName="Rake">
3
- <module name="media_types-serialization" />
4
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="" />
5
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
6
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
7
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
8
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
9
- <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
10
- <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
11
- <EXTENSION ID="RubyCoverageRunConfigurationExtension" track_test_folders="true" runner="rcov" />
12
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_NAME" VALUE="test" />
13
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_ARGS" VALUE="" />
14
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_ATTACHED_TEST_FRAMEWORKS" VALUE=":test_unit " />
15
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_TRACE" VALUE="false" />
16
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_DRYRUN" VALUE="false" />
17
- <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_PREREQS" VALUE="false" />
18
- <method v="2" />
19
- </configuration>
1
+ <component name="ProjectRunConfigurationManager">
2
+ <configuration default="false" name="test" type="RakeRunConfigurationType" factoryName="Rake">
3
+ <module name="media_types-serialization" />
4
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RUBY_ARGS" VALUE="" />
5
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="WORK DIR" VALUE="$MODULE_DIR$" />
6
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="SHOULD_USE_SDK" VALUE="false" />
7
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="ALTERN_SDK_NAME" VALUE="" />
8
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="myPassParentEnvs" VALUE="true" />
9
+ <EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
10
+ <EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
11
+ <EXTENSION ID="RubyCoverageRunConfigurationExtension" track_test_folders="true" runner="rcov" />
12
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_NAME" VALUE="test" />
13
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_ARGS" VALUE="" />
14
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_ATTACHED_TEST_FRAMEWORKS" VALUE=":test_unit " />
15
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_TRACE" VALUE="false" />
16
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_DRYRUN" VALUE="false" />
17
+ <RAKE_RUN_CONFIG_SETTINGS_ID NAME="RAKE_TASK_OPTION_PREREQS" VALUE="false" />
18
+ <method v="2" />
19
+ </configuration>
20
20
  </component>
data/.travis.yml CHANGED
@@ -1,17 +1,17 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.5
7
- - 2.6
8
- - ruby-head
9
- before_install:
10
- - gem install bundler -v 2.0.1
11
- - gem update --system
12
- - gem --version
13
- matrix:
14
- allow_failures:
15
- - rvm: ruby-head
16
- install:
17
- - bundle install --with development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5
7
+ - 2.6
8
+ - ruby-head
9
+ before_install:
10
+ - gem install bundler -v 2.0.1
11
+ - gem update --system
12
+ - gem --version
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: ruby-head
16
+ install:
17
+ - bundle install --with development --jobs=3 --retry=3 --path=${BUNDLE_PATH:-vendor/bundle}
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.1
4
+
5
+ - Fix classes sharing `media_type_constructable`, `serializes_html_flag` and `media_type_versions`
6
+ - Change `instance_methods(false)` check to `instance_methods` check in `MimeTypeSupport`
7
+ - Add `view` to `header_links` call
8
+ - Add `collect_links_for_index` option to collect links for index views
9
+ - Add `collect_links_for_collection` option to collect links for collection views
10
+
3
11
  ## 0.3.0
4
12
 
5
13
  - Change `to_link_header` to return a string ready to be used as header
data/CODE_OF_CONDUCT.md CHANGED
@@ -1,74 +1,74 @@
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, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- 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 derk-jan+github@karrenbeld.info. 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 [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
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, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ 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 derk-jan+github@karrenbeld.info. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in media_types-serialization.gemspec
4
- gemspec
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in media_types-serialization.gemspec
4
+ gemspec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- media_types-serialization (0.3.0)
4
+ media_types-serialization (0.3.1)
5
5
  actionpack (>= 4.0.0)
6
6
  activesupport (>= 4.0.0)
7
7
  http_headers-accept (< 1.0.0)
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 Derk-Jan Karrenbeld
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Derk-Jan Karrenbeld
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
3
-
4
- Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
7
- t.test_files = FileList["test/**/*_test.rb"]
8
- end
9
-
10
- task :default => :test
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "media_types/serialization"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "media_types/serialization"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup CHANGED
@@ -1,8 +1,8 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -25,7 +25,7 @@ module MediaTypes
25
25
  end
26
26
 
27
27
  def to_link_header
28
- entries = header_links.each_with_index.map do |(rel, opts), index|
28
+ entries = header_links(view: current_view).each_with_index.map do |(rel, opts), index|
29
29
  href = opts.is_a?(String) ? opts : opts.delete(:href)
30
30
  parameters = { rel: rel }.merge(opts.is_a?(String) ? {} : opts)
31
31
  HttpHeaders::Link::Entry.new("<#{href}>", index: index, parameters: parameters)
@@ -68,7 +68,8 @@ module MediaTypes
68
68
  {}
69
69
  end
70
70
 
71
- def header_links
71
+ # noinspection RubyUnusedLocalVariable
72
+ def header_links(view: current_view)
72
73
  extract_links
73
74
  end
74
75
 
@@ -9,7 +9,16 @@ module MediaTypes
9
9
  extend ActiveSupport::Concern
10
10
 
11
11
  included do
12
- mattr_accessor :migrations
12
+ # This is the same as doing matrr_accessor but have it isolated to the class. Subclass changes to change these
13
+ # values, but this allows for definition as a concern.
14
+
15
+ class << self
16
+ attr_accessor :migrations
17
+ end
18
+
19
+ delegate :migrations,
20
+ :migrations=,
21
+ to: :class
13
22
  end
14
23
 
15
24
  class_methods do
@@ -8,7 +8,16 @@ module MediaTypes
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  included do
11
- mattr_accessor :media_type_constructable, :serializes_html_flag, :media_type_versions
11
+ # This is the same as doing matrr_accessor but have it isolated to the class. Subclass changes to change these
12
+ # values, but this allows for definition as a concern.
13
+
14
+ class << self
15
+ attr_accessor :media_type_constructable, :serializes_html_flag, :media_type_versions
16
+ end
17
+
18
+ delegate :media_type_constructable, :serializes_html_flag, :media_type_versions,
19
+ :media_type_constructable=, :serializes_html_flag=, :media_type_versions=,
20
+ to: :class
12
21
  end
13
22
 
14
23
  class_methods do
@@ -20,20 +29,20 @@ module MediaTypes
20
29
  media_type_view = current_mime_type(view: view)
21
30
 
22
31
  suffixes = [].tap do |result|
23
- result << :json if self.instance_methods(false).include?(:to_json)
24
- result << :xml if self.instance_methods(false).include?(:to_xml)
32
+ result << :json if instance_methods.include?(:to_json)
33
+ result << :xml if instance_methods.include?(:to_xml)
25
34
  end
26
35
 
27
36
  additionals = [].tap do |result|
28
- result << 'text/html' if serializes_html_flag || self.instance_methods(false).include?(:to_html)
37
+ result << 'text/html' if serializes_html_flag || instance_methods.include?(:to_html)
29
38
  end
30
39
 
31
40
  [media_type_view].concat(
32
- media_type_versions.map { |version| media_type_view&.version(version) },
33
- media_type_versions.flat_map do |version|
34
- (suffixes).map { |suffix| media_type_view&.suffix(suffix)&.version(version) }
35
- end,
36
- additionals
41
+ media_type_versions.map { |version| media_type_view&.version(version) },
42
+ media_type_versions.flat_map do |version|
43
+ (suffixes).map { |suffix| media_type_view&.suffix(suffix)&.version(version) }
44
+ end,
45
+ additionals
37
46
  ).compact.uniq
38
47
  end
39
48
 
@@ -1,5 +1,5 @@
1
- module MediaTypes
2
- module Serialization
3
- VERSION = '0.3.0'
4
- end
5
- end
1
+ module MediaTypes
2
+ module Serialization
3
+ VERSION = '0.3.1'
4
+ end
5
+ end
@@ -28,7 +28,11 @@ module MediaTypes
28
28
  alias to_h to_hash
29
29
 
30
30
  def collect_links
31
- {}
31
+ if serializable && ::MediaTypes::Serialization.collect_links_for_collection
32
+ __getobj__.send(:header_links)
33
+ else
34
+ {}
35
+ end
32
36
  end
33
37
 
34
38
  private
@@ -28,7 +28,11 @@ module MediaTypes
28
28
  alias to_h to_hash
29
29
 
30
30
  def collect_links
31
- {}
31
+ if serializable && ::MediaTypes::Serialization.collect_links_for_index
32
+ __getobj__.send(:header_links)
33
+ else
34
+ {}
35
+ end
32
36
  end
33
37
 
34
38
  private
@@ -5,7 +5,6 @@ require 'delegate'
5
5
  require 'active_support/core_ext/string/inflections'
6
6
 
7
7
  require 'media_types/serialization/base'
8
- require 'media_types/serialization/wrapper/media_wrapper'
9
8
  require 'media_types/serialization/wrapper/root_key'
10
9
 
11
10
  module MediaTypes
@@ -1,194 +1,194 @@
1
- require 'media_types/serialization/version'
2
-
3
- require 'abstract_controller'
4
- require 'action_controller/metal/mime_responds'
5
- require 'action_dispatch/http/mime_type'
6
- require 'active_support/concern'
7
- require 'active_support/core_ext/module/attribute_accessors'
8
-
9
- require 'http_headers/accept'
10
-
11
- require 'media_types/serialization/no_media_type_serializers'
12
- require 'media_types/serialization/no_serializer_for_content_type'
13
- require 'media_types/serialization/wrapper/html_wrapper'
14
- require 'media_types/serialization/wrapper/media_wrapper'
15
-
16
- module MediaTypes
17
- module Serialization
18
-
19
- mattr_accessor :common_suffix
20
-
21
- extend ActiveSupport::Concern
22
-
23
- HEADER_ACCEPT = 'HTTP_ACCEPT'
24
- MEDIA_TYPE_HTML = 'text/html'
25
-
26
- # rubocop:disable Metrics/BlockLength
27
- class_methods do
28
- # @see #freeze_accepted_media!
29
- #
30
- def accept_serialization(serializer, view: [nil], accept_html: true, **filter_opts)
31
- before_action(**filter_opts) do
32
- self.serializers = resolved_media_types(serializer, view: view) do |media_type, media_view, res|
33
- opts = { media_type: media_type, media_view: media_view }
34
-
35
- res[MEDIA_TYPE_HTML] = wrap_html(serializer, **opts) if accept_html && !res[MEDIA_TYPE_HTML]
36
- res[String(media_type)] = wrap_media(serializer, **opts) if media_type != MEDIA_TYPE_HTML
37
- end
38
- end
39
- end
40
-
41
- def accept_html(serializer, **filter_opts)
42
- before_action(**filter_opts) do
43
- self.serializers = resolved_media_types(serializer, view: nil) do |_, media_view, res|
44
- res[MEDIA_TYPE_HTML] = wrap_html(serializer, media_view: media_view, media_type: MEDIA_TYPE_HTML)
45
- break
46
- end
47
- end
48
- end
49
-
50
- ##
51
- # Register a mime type, but explicitly notify that it can't be serialized.
52
- # This is done for file serving and redirects.
53
- #
54
- # @param [Symbol] mimes takes a list of symbols that should resolve through Mime::Type
55
- #
56
- # @see #freeze_accepted_media!
57
- #
58
- # @example fingerpint binary format
59
- #
60
- # no_serializer_for :fingerprint_bin, :fingerprint_deprecated_bin
61
- #
62
- def accept_without_serialization(*mimes, **filter_opts)
63
- before_action(**filter_opts) do
64
- self.serializers = Array(mimes).each_with_object(Hash(serializers)) do |mime, res|
65
- res[(Mime::Type.lookup_by_extension(mime) || mime).to_s] = nil
66
- end
67
- end
68
- end
69
-
70
- ##
71
- # Freezes additions to the serializes and notifies the controller what it will be able to respond to.
72
- #
73
- def freeze_accepted_media!
74
- before_action do
75
- # If the responders gem is available, this freezes what a controller can respond to
76
- if self.class.respond_to?(:respond_to)
77
- self.class.respond_to(*Hash(serializers).keys.map { |type| Mime::Type.lookup(type) })
78
- end
79
- serializers.freeze
80
- end
81
- end
82
- end
83
- # rubocop:enable Metrics/BlockLength
84
-
85
- included do
86
- protected
87
-
88
- attr_accessor :serializers
89
- end
90
-
91
- protected
92
-
93
- def media_type_serializer
94
- @media_type_serializer ||= resolve_media_type_serializer
95
- end
96
-
97
- def serialize_media(media, serializer: media_type_serializer)
98
- @last_serialize_media = media
99
- @last_media_serializer = serializer.call(media, context: self)
100
- end
101
-
102
- def media_type_json_root
103
- String(request.format.symbol).sub(/_json$/, '')
104
- end
105
-
106
- def respond_to_matching(matcher, &block)
107
- respond_to do |format|
108
- serializers.each_key do |mime|
109
- next unless matcher.call(mime: mime, format: format)
110
- format.custom(mime, &block)
111
- end
112
- end
113
- end
114
-
115
- def respond_to_accept(&block)
116
- respond_to do |format|
117
- serializers.each_key do |mime|
118
- format.custom(mime, &block)
119
- end
120
-
121
- format.any { raise_no_accept_serializer }
122
- end
123
- end
124
-
125
- def request_accept
126
- @request_accept ||= HttpHeaders::Accept.new(request.get_header(HEADER_ACCEPT) || '')
127
- end
128
-
129
- def raise_no_accept_serializer
130
- raise NoSerializerForContentType.new(request_accept, serializers.keys)
131
- end
132
-
133
- private
134
-
135
- def extract_synonym_version(synonym)
136
- synonym.rpartition('.').last[1..-1]
137
- end
138
-
139
- def resolve_media_type_serializer
140
- raise NoMediaTypeSerializers unless serializers
141
-
142
- # Rails negotiation
143
- if serializers[request.format.to_s]
144
- return serializers[request.format.to_s]
145
- end
146
-
147
- # Ruby negotiation
148
- request.accepts.each do |mime_type|
149
- next unless serializers.key?(mime_type.to_s)
150
- # Override Rails selected format
151
- request.set_header("action_dispatch.request.formats", [mime_type])
152
- return serializers[mime_type.to_s]
153
- end
154
-
155
- raise_no_accept_serializer
156
- end
157
-
158
- def resolved_media_types(serializer, view:)
159
- Array(view).each_with_object(Hash(serializers)) do |media_view, res|
160
- media_view = String(media_view)
161
- Array(serializer.media_type(view: media_view)).each do |media_type|
162
- yield media_type, media_view, res
163
- end
164
- end
165
- end
166
-
167
- def wrap_media(serializer, media_view:, media_type:)
168
- lambda do |*args, **opts|
169
- Wrapper::MediaWrapper.new(
170
- serializer.new(*args, media_type: media_type, view: media_view, **opts),
171
- view: media_view
172
- )
173
- end
174
- end
175
-
176
- def wrap_html(serializer, media_view:, media_type:)
177
- lambda do |*args, **opts|
178
- media_serializer = wrap_media(
179
- serializer,
180
- media_view: media_view,
181
- media_type: media_type
182
- ).call(*args, **opts)
183
-
184
- Wrapper::HtmlWrapper.new(
185
- media_serializer,
186
- view: media_view,
187
- mime_type: media_type.to_s,
188
- representations: serializers.keys,
189
- url_context: request.original_fullpath.chomp(".#{request.format.symbol}")
190
- )
191
- end
192
- end
193
- end
194
- end
1
+ require 'media_types/serialization/version'
2
+
3
+ require 'abstract_controller'
4
+ require 'action_controller/metal/mime_responds'
5
+ require 'action_dispatch/http/mime_type'
6
+ require 'active_support/concern'
7
+ require 'active_support/core_ext/module/attribute_accessors'
8
+
9
+ require 'http_headers/accept'
10
+
11
+ require 'media_types/serialization/no_media_type_serializers'
12
+ require 'media_types/serialization/no_serializer_for_content_type'
13
+ require 'media_types/serialization/wrapper/html_wrapper'
14
+ require 'media_types/serialization/wrapper/media_wrapper'
15
+
16
+ module MediaTypes
17
+ module Serialization
18
+
19
+ mattr_accessor :common_suffix, :collect_links_for_collection, :collect_links_for_index
20
+
21
+ extend ActiveSupport::Concern
22
+
23
+ HEADER_ACCEPT = 'HTTP_ACCEPT'
24
+ MEDIA_TYPE_HTML = 'text/html'
25
+
26
+ # rubocop:disable Metrics/BlockLength
27
+ class_methods do
28
+ # @see #freeze_accepted_media!
29
+ #
30
+ def accept_serialization(serializer, view: [nil], accept_html: true, **filter_opts)
31
+ before_action(**filter_opts) do
32
+ self.serializers = resolved_media_types(serializer, view: view) do |media_type, media_view, res|
33
+ opts = { media_type: media_type, media_view: media_view }
34
+
35
+ res[MEDIA_TYPE_HTML] = wrap_html(serializer, **opts) if accept_html && !res[MEDIA_TYPE_HTML]
36
+ res[String(media_type)] = wrap_media(serializer, **opts) if media_type != MEDIA_TYPE_HTML
37
+ end
38
+ end
39
+ end
40
+
41
+ def accept_html(serializer, **filter_opts)
42
+ before_action(**filter_opts) do
43
+ self.serializers = resolved_media_types(serializer, view: nil) do |_, media_view, res|
44
+ res[MEDIA_TYPE_HTML] = wrap_html(serializer, media_view: media_view, media_type: MEDIA_TYPE_HTML)
45
+ break
46
+ end
47
+ end
48
+ end
49
+
50
+ ##
51
+ # Register a mime type, but explicitly notify that it can't be serialized.
52
+ # This is done for file serving and redirects.
53
+ #
54
+ # @param [Symbol] mimes takes a list of symbols that should resolve through Mime::Type
55
+ #
56
+ # @see #freeze_accepted_media!
57
+ #
58
+ # @example fingerpint binary format
59
+ #
60
+ # no_serializer_for :fingerprint_bin, :fingerprint_deprecated_bin
61
+ #
62
+ def accept_without_serialization(*mimes, **filter_opts)
63
+ before_action(**filter_opts) do
64
+ self.serializers = Array(mimes).each_with_object(Hash(serializers)) do |mime, res|
65
+ res[(Mime::Type.lookup_by_extension(mime) || mime).to_s] = nil
66
+ end
67
+ end
68
+ end
69
+
70
+ ##
71
+ # Freezes additions to the serializes and notifies the controller what it will be able to respond to.
72
+ #
73
+ def freeze_accepted_media!
74
+ before_action do
75
+ # If the responders gem is available, this freezes what a controller can respond to
76
+ if self.class.respond_to?(:respond_to)
77
+ self.class.respond_to(*Hash(serializers).keys.map { |type| Mime::Type.lookup(type) })
78
+ end
79
+ serializers.freeze
80
+ end
81
+ end
82
+ end
83
+ # rubocop:enable Metrics/BlockLength
84
+
85
+ included do
86
+ protected
87
+
88
+ attr_accessor :serializers
89
+ end
90
+
91
+ protected
92
+
93
+ def media_type_serializer
94
+ @media_type_serializer ||= resolve_media_type_serializer
95
+ end
96
+
97
+ def serialize_media(media, serializer: media_type_serializer)
98
+ @last_serialize_media = media
99
+ @last_media_serializer = serializer.call(media, context: self)
100
+ end
101
+
102
+ def media_type_json_root
103
+ String(request.format.symbol).sub(/_json$/, '')
104
+ end
105
+
106
+ def respond_to_matching(matcher, &block)
107
+ respond_to do |format|
108
+ serializers.each_key do |mime|
109
+ next unless matcher.call(mime: mime, format: format)
110
+ format.custom(mime, &block)
111
+ end
112
+ end
113
+ end
114
+
115
+ def respond_to_accept(&block)
116
+ respond_to do |format|
117
+ serializers.each_key do |mime|
118
+ format.custom(mime, &block)
119
+ end
120
+
121
+ format.any { raise_no_accept_serializer }
122
+ end
123
+ end
124
+
125
+ def request_accept
126
+ @request_accept ||= HttpHeaders::Accept.new(request.get_header(HEADER_ACCEPT) || '')
127
+ end
128
+
129
+ def raise_no_accept_serializer
130
+ raise NoSerializerForContentType.new(request_accept, serializers.keys)
131
+ end
132
+
133
+ private
134
+
135
+ def extract_synonym_version(synonym)
136
+ synonym.rpartition('.').last[1..-1]
137
+ end
138
+
139
+ def resolve_media_type_serializer
140
+ raise NoMediaTypeSerializers unless serializers
141
+
142
+ # Rails negotiation
143
+ if serializers[request.format.to_s]
144
+ return serializers[request.format.to_s]
145
+ end
146
+
147
+ # Ruby negotiation
148
+ request.accepts.each do |mime_type|
149
+ next unless serializers.key?(mime_type.to_s)
150
+ # Override Rails selected format
151
+ request.set_header("action_dispatch.request.formats", [mime_type])
152
+ return serializers[mime_type.to_s]
153
+ end
154
+
155
+ raise_no_accept_serializer
156
+ end
157
+
158
+ def resolved_media_types(serializer, view:)
159
+ Array(view).each_with_object(Hash(serializers)) do |media_view, res|
160
+ media_view = String(media_view)
161
+ Array(serializer.media_type(view: media_view)).each do |media_type|
162
+ yield media_type, media_view, res
163
+ end
164
+ end
165
+ end
166
+
167
+ def wrap_media(serializer, media_view:, media_type:)
168
+ lambda do |*args, **opts|
169
+ Wrapper::MediaWrapper.new(
170
+ serializer.new(*args, media_type: media_type, view: media_view, **opts),
171
+ view: media_view
172
+ )
173
+ end
174
+ end
175
+
176
+ def wrap_html(serializer, media_view:, media_type:)
177
+ lambda do |*args, **opts|
178
+ media_serializer = wrap_media(
179
+ serializer,
180
+ media_view: media_view,
181
+ media_type: media_type
182
+ ).call(*args, **opts)
183
+
184
+ Wrapper::HtmlWrapper.new(
185
+ media_serializer,
186
+ view: media_view,
187
+ mime_type: media_type.to_s,
188
+ representations: serializers.keys,
189
+ url_context: request.original_fullpath.chomp(".#{request.format.symbol}")
190
+ )
191
+ end
192
+ end
193
+ end
194
+ end
@@ -1,48 +1,48 @@
1
-
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "media_types/serialization/version"
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "media_types-serialization"
8
- spec.version = MediaTypes::Serialization::VERSION
9
- spec.authors = ["Derk-Jan Karrenbeld"]
10
- spec.email = ["derk-jan@xpbytes.com"]
11
-
12
- spec.summary = 'Add media types supported serialization using your favourite serializer'
13
- spec.homepage = 'https://github.com/XPBytes/media_types-serialization'
14
- spec.license = 'MIT'
15
-
16
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
- # to allow pushing to a single host or delete this section to allow pushing to any host.
18
- if spec.respond_to?(:metadata)
19
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
-
21
- spec.metadata["homepage_uri"] = spec.homepage
22
- spec.metadata["source_code_uri"] = spec.homepage
23
- spec.metadata["changelog_uri"] = spec.homepage + '/CHANGELOG.md'
24
- else
25
- raise "RubyGems 2.0 or newer is required to protect against " \
26
- "public gem pushes."
27
- end
28
-
29
- # Specify which files should be added to the gem when it is released.
30
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
- end
34
- spec.bindir = "exe"
35
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
- spec.require_paths = ["lib"]
37
-
38
- spec.add_dependency 'actionpack', '>= 4.0.0'
39
- spec.add_dependency 'activesupport', '>= 4.0.0'
40
- spec.add_dependency 'media_types', '>= 0.6.0'
41
- spec.add_dependency 'oj', '>= 3.5.0'
42
- spec.add_dependency 'http_headers-accept', '< 1.0.0'
43
- spec.add_dependency 'http_headers-link', '< 1.0.0'
44
-
45
- spec.add_development_dependency "bundler", "~> 2.0"
46
- spec.add_development_dependency "rake", "~> 10.0"
47
- spec.add_development_dependency "minitest", "~> 5.0"
48
- end
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "media_types/serialization/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "media_types-serialization"
8
+ spec.version = MediaTypes::Serialization::VERSION
9
+ spec.authors = ["Derk-Jan Karrenbeld"]
10
+ spec.email = ["derk-jan@xpbytes.com"]
11
+
12
+ spec.summary = 'Add media types supported serialization using your favourite serializer'
13
+ spec.homepage = 'https://github.com/XPBytes/media_types-serialization'
14
+ spec.license = 'MIT'
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ spec.metadata["source_code_uri"] = spec.homepage
23
+ spec.metadata["changelog_uri"] = spec.homepage + '/CHANGELOG.md'
24
+ else
25
+ raise "RubyGems 2.0 or newer is required to protect against " \
26
+ "public gem pushes."
27
+ end
28
+
29
+ # Specify which files should be added to the gem when it is released.
30
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
32
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
33
+ end
34
+ spec.bindir = "exe"
35
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
+ spec.require_paths = ["lib"]
37
+
38
+ spec.add_dependency 'actionpack', '>= 4.0.0'
39
+ spec.add_dependency 'activesupport', '>= 4.0.0'
40
+ spec.add_dependency 'media_types', '>= 0.6.0'
41
+ spec.add_dependency 'oj', '>= 3.5.0'
42
+ spec.add_dependency 'http_headers-accept', '< 1.0.0'
43
+ spec.add_dependency 'http_headers-link', '< 1.0.0'
44
+
45
+ spec.add_development_dependency "bundler", "~> 2.0"
46
+ spec.add_development_dependency "rake", "~> 10.0"
47
+ spec.add_development_dependency "minitest", "~> 5.0"
48
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: media_types-serialization
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derk-Jan Karrenbeld
@@ -146,6 +146,7 @@ files:
146
146
  - ".gitignore"
147
147
  - ".idea/.rakeTasks"
148
148
  - ".idea/dictionaries/Derk_Jan.xml"
149
+ - ".idea/encodings.xml"
149
150
  - ".idea/inspectionProfiles/Project_Default.xml"
150
151
  - ".idea/media_types-serialization.iml"
151
152
  - ".idea/misc.xml"
@@ -204,8 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  - !ruby/object:Gem::Version
205
206
  version: '0'
206
207
  requirements: []
207
- rubyforge_project:
208
- rubygems_version: 2.7.6
208
+ rubygems_version: 3.0.2
209
209
  signing_key:
210
210
  specification_version: 4
211
211
  summary: Add media types supported serialization using your favourite serializer