visible_assignment 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6fa8d4e49ea29cb0caefed916505043202626e6c146c1f55fc9f6b4ee02f441b
4
+ data.tar.gz: 90e179d4b2142c452ff390870a82754bffa9a310284ffc5e31ed8f42b0241119
5
+ SHA512:
6
+ metadata.gz: 8721158607151de2df48e209991aadaa7be7e07653368831121f7b4bd2c302d26232ffe4b84038517a62c5cd7ce87081b45fac43d365254651a7338b022ff34f
7
+ data.tar.gz: 166c0aea988a3e2acbe95e26343f43293375d0e2ccba5d54627ea15e3dda18af07263cf4fe7fff6bd7657c9137ee9fa01809f81942dd1cbc939f213e49860fae
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 1.17.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in visible_assignment.gemspec
6
+ gemspec
@@ -0,0 +1,48 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ visible_assignment (0.1.0)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.2.2)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 0.7, < 2)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ concurrent-ruby (1.1.4)
16
+ diff-lcs (1.3)
17
+ i18n (1.5.3)
18
+ concurrent-ruby (~> 1.0)
19
+ minitest (5.11.3)
20
+ rake (10.5.0)
21
+ rspec (3.8.0)
22
+ rspec-core (~> 3.8.0)
23
+ rspec-expectations (~> 3.8.0)
24
+ rspec-mocks (~> 3.8.0)
25
+ rspec-core (3.8.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-expectations (3.8.2)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-mocks (3.8.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.8.0)
33
+ rspec-support (3.8.0)
34
+ thread_safe (0.3.6)
35
+ tzinfo (1.2.5)
36
+ thread_safe (~> 0.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.17)
43
+ rake (~> 10.0)
44
+ rspec (~> 3.0)
45
+ visible_assignment!
46
+
47
+ BUNDLED WITH
48
+ 1.17.3
@@ -0,0 +1,104 @@
1
+ # VisibleAssignment
2
+
3
+ Change the way data is passed from ActionController to ActionView.
4
+
5
+ Instead of copying all the instance variables of ActionController, VisibleAssignment copy only the explicit data to the instance variable of ActionView so that it can be used in the View.
6
+
7
+ Resolve the poor visibility of what is in the instance variables used by View. For example, an instance variable defined by before_action or an instance variable defined by an included module ...etc
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'visible_assignment'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install visible_assignment
24
+
25
+
26
+ ## Configuration
27
+
28
+ When set to true, the instance variable of the controller is also copied to the View instance variable.
29
+
30
+ ```rb
31
+ VisibleAssignment.configure do |config|
32
+ config.enable_instance_variables = true # default false.
33
+ end
34
+ ```
35
+
36
+ ## Usage
37
+
38
+ When you want to pass an instance variable to View.
39
+
40
+ ```rb
41
+ class BooksController < ApplicationController
42
+ def index
43
+ self.view_assign_variables = {
44
+ books: available_books,
45
+ }
46
+ end
47
+
48
+ def show
49
+ self.view_assign_variables = {
50
+ book: current_book,
51
+ }
52
+ end
53
+
54
+ private
55
+
56
+ def available_books
57
+ Book.available.page(params[:page])
58
+ end
59
+
60
+ def current_book
61
+ available_books.find(params[:id])
62
+ end
63
+ end
64
+ ```
65
+
66
+ ```books/index.erb
67
+ <% @books.each do |book| %>
68
+ <p><%= book.title %></p>
69
+ <% end %>
70
+ ```
71
+
72
+ ```books/show.erb
73
+ <p><%= @book.title %></p>
74
+ ```
75
+
76
+ When you want to pass an instance variable that is used for all actions to View
77
+
78
+ ```rb
79
+ class ApplicationController < ActionController::Base
80
+ before_action :set_global_view_assign_variables
81
+
82
+ def set_global_view_assign_variables
83
+ self.global_view_assign_variables = {
84
+ current_user: current_user,
85
+ }
86
+ end
87
+
88
+ private
89
+
90
+ def current_user
91
+ # ...
92
+ end
93
+ end
94
+ ```
95
+
96
+ ## Development
97
+
98
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
99
+
100
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
101
+
102
+ ## Contributing
103
+
104
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/visible_assignment.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "visible_assignment"
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__)
@@ -0,0 +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
@@ -0,0 +1,13 @@
1
+ require "visible_assignment/version"
2
+
3
+ require 'active_support'
4
+ require 'visible_assignment/config'
5
+ require 'visible_assignment/action_controller_extension'
6
+
7
+ module VisibleAssignment
8
+ class Error < StandardError; end
9
+
10
+ ActiveSupport.on_load(:action_controller) do
11
+ include ActionControllerExtension
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ module VisibleAssignment
2
+ module ActionControllerExtension
3
+ def view_assigns
4
+ if VisibleAssignment.config.enable_instance_variables
5
+ super.merge(all_view_assign_variables)
6
+ else
7
+ all_view_assign_variables
8
+ end
9
+ end
10
+
11
+ def view_assign_variables=(variables)
12
+ @_assign_variables = variables
13
+ end
14
+
15
+ def global_view_assign_variables=(variables)
16
+ @_global_assign_variables = variables
17
+ end
18
+
19
+ def all_view_assign_variables
20
+ @_assign_variables ||= {}
21
+ @_global_assign_variables ||= {}
22
+ @_global_assign_variables.merge(@_assign_variables)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ module VisibleAssignment
2
+ class << self
3
+ def configure
4
+ yield config
5
+ end
6
+
7
+ def config
8
+ @config ||= VisibleAssignment::Config.new
9
+ end
10
+ end
11
+
12
+ class Config
13
+ include ActiveSupport::Configurable
14
+ config_accessor :enable_instance_variables
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module VisibleAssignment
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "visible_assignment/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "visible_assignment"
8
+ spec.version = VisibleAssignment::VERSION
9
+ spec.authors = ["h1kita"]
10
+
11
+ spec.summary = "change the way data is passed from ActionController to ActionView"
12
+ spec.description = "change the way data is passed from ActionController to ActionView"
13
+ spec.license = "MIT"
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency 'activesupport'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.17"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: visible_assignment
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - h1kita
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: change the way data is passed from ActionController to ActionView
70
+ email:
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - ".gitignore"
76
+ - ".rspec"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/visible_assignment.rb
85
+ - lib/visible_assignment/action_controller_extension.rb
86
+ - lib/visible_assignment/config.rb
87
+ - lib/visible_assignment/version.rb
88
+ - visible_assignment.gemspec
89
+ homepage:
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.0.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: change the way data is passed from ActionController to ActionView
112
+ test_files: []