well-actually 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c826e95643c9ec3ec3eb2b326ab2317a7d13c791
4
+ data.tar.gz: 0c9b711fdf5c097b2fd7494cd16ab5f7a9bfb0a5
5
+ SHA512:
6
+ metadata.gz: 96826dbee1d0cc607cb5f2d523e985999f80ac79735e77b04666ab45583acb7eab3df059d64da5045625cf86bea2f6246250530ff55736f7ec5d1764d2183409
7
+ data.tar.gz: e0c0032189ca07bd2401e9858c4ac0abdb6bd3d508c21111eebd87d865499088a26ae39b62448ddf61823b77c6beada47725de636e06b2eafba14337eb6b1c22
data/.gitignore ADDED
@@ -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
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.14.6
data/Appraisals ADDED
@@ -0,0 +1,13 @@
1
+ appraise "without-rails" do
2
+
3
+ end
4
+
5
+ appraise "rails-4" do
6
+ gem "rails", "4.2.9"
7
+ gem "sqlite3"
8
+ end
9
+
10
+ appraise "rails-5" do
11
+ gem "rails", "5.1.3"
12
+ gem "sqlite3"
13
+ end
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in well_actually.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Andrew Rove
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/README.md ADDED
@@ -0,0 +1,60 @@
1
+ ## Installation
2
+
3
+ Add this line to your application's Gemfile:
4
+
5
+ ```ruby
6
+ gem 'well-actually'
7
+ ```
8
+
9
+ And then execute:
10
+
11
+ $ bundle
12
+
13
+ Or install it yourself as:
14
+
15
+ $ gem install well_actually
16
+
17
+ ## Usage
18
+ ```ruby
19
+ Dog < ActiveRecord::Base
20
+ extend WellActually
21
+ well_actually overwrite: :overwrite, attributes: [:name, :show, :birthday]
22
+ end
23
+
24
+ dog = Dog.new(name: "Radar", breed: "Korgi", age: 10, show: true, birthday: Time.new(2010,1,1))
25
+ puts dog.name
26
+ => "Radar"
27
+ puts dog.age
28
+ => 10
29
+
30
+ # Overwrite an overwriteable attribute
31
+ dog.overwrite["name"] = "Sadie"
32
+ # Can't overwrite an unoverwriteable attribute
33
+ dog.overwrite["age"] = 12
34
+ dog_actually = dog.well_actually
35
+ puts dog_actually.name
36
+ => "Sadie"
37
+ puts dog_actually.age
38
+ => 10
39
+
40
+ #Oringal Object Doesn't Change
41
+ puts dog.name
42
+ => "Radar"
43
+ puts dog.age
44
+ => 10
45
+ ```
46
+
47
+ ## Development
48
+
49
+ After checking out the repo, run `gem install bundle`, then `gem install appraisal `, and run `bin/setup` to install dependencies. Then, run `bundle exec appraisal rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
50
+
51
+ 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).
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/RealSavvy/well_actually.
56
+
57
+
58
+ ## License
59
+
60
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -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
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "well_actually"
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 ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ appraisal install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,60 @@
1
+ module WellActually
2
+ class Mounter
3
+ attr_reader :klass, :overwrite, :attributes
4
+
5
+ BLANK_RE = defined?(String::BLANK_RE) ? String::BLANK_RE : /\A[[:space:]]*\z/
6
+
7
+ def initialize(klass:, overwrite:, attributes:)
8
+ raise ArgumentError.new("overwrite must be a symbol") unless overwrite.is_a?(Symbol)
9
+ raise ArgumentError.new("attributes must be an array of symbols") unless attributes.is_a?(Array) && attributes.all?{|a| a.is_a?(Symbol)}
10
+ @klass = klass
11
+ @overwrite = overwrite
12
+ @attributes = attributes.uniq
13
+ end
14
+
15
+ def mount
16
+ klass.class_variable_set(:@@well_actually_attributes, attributes.map{|_attr| _attr.to_s})
17
+ klass.class_variable_set(:@@well_actually_overwrite, overwrite)
18
+
19
+ klass.send(:define_singleton_method, :well_actually_attributes) do
20
+ self.class_variable_get(:@@well_actually_attributes)
21
+ end
22
+
23
+ klass.send(:define_method, :well_actually_attributes) do
24
+ self.class.well_actually_attributes
25
+ end
26
+
27
+ klass.send(:define_singleton_method, :well_actually_overwrite) do
28
+ self.class_variable_get(:@@well_actually_overwrite)
29
+ end
30
+
31
+ klass.send(:define_method, :well_actually_overwrite) do
32
+ self.public_send(self.class.well_actually_overwrite)
33
+ end
34
+
35
+ klass.send(:define_method, :well_actually?) do
36
+ !!self.instance_variable_get(:@well_actually)
37
+ end
38
+
39
+ klass.send(:define_method, :well_actually) do
40
+ self.clone.tap do |actually|
41
+ actually.readonly! if actually.respond_to?(:readonly!)
42
+ actually.instance_variable_set(:@well_actually, true)
43
+ self.send(:well_actually_overwrite_safe).each do |_attr, _value|
44
+ if actually.respond_to?(:"#{_attr}=")
45
+ actually.public_send(:"#{_attr}=", _value)
46
+ else
47
+ actually.instance_variable_set(:"@#{_attr}", _value)
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ klass.send(:define_method, :well_actually_overwrite_safe) do
54
+ (self.well_actually_overwrite || {}).select do |key, value|
55
+ self.well_actually_attributes.include?(key) && !value.nil? && (!value.is_a?(String) || !value.match(BLANK_RE))
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module WellActually
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "well_actually/version"
2
+ require "well_actually/mounter"
3
+
4
+ module WellActually
5
+ def well_actually(options={})
6
+ Mounter.new(options.merge(klass: self)).mount
7
+ end
8
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'well_actually/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "well-actually"
8
+ spec.version = WellActually::VERSION
9
+ spec.authors = ["Andrew Rove"]
10
+ spec.email = ["andrew@realsavvy.com"]
11
+
12
+ spec.summary = %q{Easy safe overwrites.}
13
+ spec.description = %q{Allows you to overwrite using an overwrite hash.}
14
+ spec.homepage = "https://www.realsavvy.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features|gemfiles)/})
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_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "appraisal", "~> 2.2"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: well-actually
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Rove
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-09 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.2'
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: Allows you to overwrite using an overwrite hash.
70
+ email:
71
+ - andrew@realsavvy.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Appraisals
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/well_actually.rb
87
+ - lib/well_actually/mounter.rb
88
+ - lib/well_actually/version.rb
89
+ - well_actually.gemspec
90
+ homepage: https://www.realsavvy.com
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.6.11
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Easy safe overwrites.
114
+ test_files: []