dry-struct-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecea6c529510496372eaf3940bbe636af2c97530
4
+ data.tar.gz: 77a5565d280e2ca62af578b1f9c0f0a604577464
5
+ SHA512:
6
+ metadata.gz: 576dff9ff54179119f6e0f825c04f83a187fe28b974217aa356358ebb95d37670e8d89338aeeeb16018b593cf8ab88f5372492b3dfdc1d76e2220fdf94c505cf
7
+ data.tar.gz: 6c2e10688455b024ad06f4d039582c002e91f5a3276f107d8c1a7a9037ccf539cd3ae8e0585d12b9150c7d757c5743c3481847fc788a536476ac0caa05c2ac76
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,7 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2
5
+ - 2.3
6
+ - 2.4
7
+ script: bundle exec rake
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in dry-struct-rails.gemspec
4
+ gemspec
@@ -0,0 +1,40 @@
1
+ # Dry::Struct::Rails [![Build Status](https://travis-ci.org/fnordfish/dry-struct-rails.svg?branch=master)](https://travis-ci.org/fnordfish/dry-struct-rails)
2
+
3
+ Railtie gem to let `dry-struct` cope with Rails' reloading.
4
+
5
+ This gem is quite EXPERIMENTAL, it's goal is to let subclasses of `Dry::Struct` survive a Rails Application reload in development.
6
+
7
+ ## Previous Work
8
+
9
+ This gem is based on [dry-types-rails](https://github.com/jeromegn/dry-types-rails). Licensed under The MIT License (MIT), Copyright (c) 2016 Jerome Gravel-Niquet.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'dry-struct-rails', group: :development
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install dry-struct-rails
26
+
27
+ ## Usage
28
+
29
+ Nothing more to do.
30
+
31
+ ## Development
32
+
33
+ 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.
34
+
35
+ 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).
36
+
37
+
38
+ ## Contributing
39
+
40
+ Pull requests are welcome on GitHub at https://github.com/fnordfish/dry-struct-rails.
@@ -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,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'combustion'
5
+ require 'active_support/dependencies'
6
+
7
+ require "dry/struct/rails"
8
+
9
+ # You can add fixtures and/or initialization code here to make experimenting
10
+ # with your gem easier. You can also use a different console, if you like.
11
+
12
+ # (If you use this, don't forget to add pry to your Gemfile!)
13
+ # require "pry"
14
+ # Pry.start
15
+
16
+ require "irb"
17
+ 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,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize! :all
7
+ run Combustion::Application
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dry/struct/rails/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dry-struct-rails"
8
+ spec.version = Dry::Struct::Rails::VERSION
9
+ spec.authors = ["Robert Schulze"]
10
+ spec.email = ["robert@dotless.de"]
11
+
12
+ spec.summary = %q{Dry::Struct railties}
13
+ spec.description = %q{Rails reloading for `dry-struct`}
14
+ spec.homepage = "https://github.com/fnordfish/dry-struct-rails"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "combustion", "~> 0.7.0"
26
+ spec.add_development_dependency "rspec-rails", "~> 3.7"
27
+
28
+ spec.add_runtime_dependency "rails", ">= 5.1"
29
+ spec.add_runtime_dependency "dry-struct", "~> 0.4.0"
30
+ end
@@ -0,0 +1,9 @@
1
+ require "dry/struct/rails/version"
2
+
3
+ require "dry/struct"
4
+ require "dry/struct/rails/railtie"
5
+
6
+ module Dry
7
+ class Struct
8
+ end
9
+ end
@@ -0,0 +1,44 @@
1
+ module Dry
2
+ class Struct
3
+ module Rails
4
+ module StructRegistration
5
+ REGISTERED_STRUCTS = Concurrent::Array.new
6
+
7
+ def attributes(new_schema)
8
+ unless StructRegistration::REGISTERED_STRUCTS.include?(self)
9
+ # Check to see if we need to remove the registered type
10
+ autoloaded = ActiveSupport::Dependencies.will_unload?(self)
11
+ # ActiveSupport::Dependencies.will_unload?(klass) won't return true yet
12
+ # if it's the first time a constant is being autoloaded
13
+ # so we have to see if we're in the middle of loading a missing constants
14
+ autoloaded |= caller.any? { |line| line =~ /\:in.*?new_constants_in/ }
15
+
16
+ StructRegistration::REGISTERED_STRUCTS << self if autoloaded
17
+ end
18
+ super
19
+ end
20
+ end
21
+
22
+ Dry::Struct.module_eval do
23
+ class << self
24
+ prepend(StructRegistration)
25
+ end
26
+ end
27
+
28
+ class Railtie < ::Rails::Railtie
29
+ initializer "dry-struct-rails.configure_rails_initialization" do
30
+ ActiveSupport::Reloader.before_class_unload do
31
+ structs = StructRegistration::REGISTERED_STRUCTS.dup
32
+ structs.each do |struct|
33
+ StructRegistration::REGISTERED_STRUCTS.delete(struct)
34
+
35
+ struct.schema({})
36
+ struct.remove_instance_variable(:@attribute_names) if struct.instance_variable_defined?(:@attribute_names)
37
+ struct.equalizer.instance_variable_get(:@keys).clear
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,7 @@
1
+ module Dry
2
+ class Struct
3
+ module Rails
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dry-struct-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Robert Schulze
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: combustion
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.7.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.7.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '5.1'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '5.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: dry-struct
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.4.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.4.0
97
+ description: Rails reloading for `dry-struct`
98
+ email:
99
+ - robert@dotless.de
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - config.ru
113
+ - dry-struct-rails.gemspec
114
+ - lib/dry/struct/rails.rb
115
+ - lib/dry/struct/rails/railtie.rb
116
+ - lib/dry/struct/rails/version.rb
117
+ homepage: https://github.com/fnordfish/dry-struct-rails
118
+ licenses: []
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.6.13
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Dry::Struct railties
140
+ test_files: []