archivable 0.0.1

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: c99c85a31687ceb92b1cc20f779cc59560c96b6b
4
+ data.tar.gz: beb573cd3b2f128d481133ed2d9eea145e0a5291
5
+ SHA512:
6
+ metadata.gz: 69699ae1fe2b734b49bd82b45008b31a6b6e094d8943e95a5ce431cc6a6e47462a9256a463807f6c0bdd2796b0ad16f309c6a4602f18d9695e3f8954b0c4b0e6
7
+ data.tar.gz: d0588f09c8918bd87a587b7d1ee2d40c6e629c37dd4d1b31b3b055ec8501b76d7590a9ca53d80e83d1c2251a7fa548be9c5c9f02ac15a8268a962955be862df8
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+
7
+ notifications:
8
+ email:
9
+ - johnotander@gmail.com
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in archivable.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 John Otander
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ # Archivable
2
+
3
+ [![Build Status](https://travis-ci.org/johnotander/archivable.svg?branch=master)](https://travis-ci.org/johnotander/archivable)
4
+
5
+ _Currently under development._
6
+
7
+ Archive your Rails models rather than delete them.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'archivable'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install archivable
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( http://github.com/johnotander/archivable/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create new Pull Request
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
7
+ task test: :spec
8
+
9
+ task :build do
10
+ system 'gem build archivable.gemspec'
11
+ 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 'archivable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "archivable"
8
+ spec.version = Archivable::VERSION
9
+ spec.authors = ["John Otander"]
10
+ spec.email = ["johnotander@gmail.com"]
11
+ spec.summary = %q{Archive your Rails models rather than delete them.}
12
+ spec.description = %q{Archive your Rails models rather than delete them, with model and controller concerns.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'activesupport'
22
+ spec.add_dependency 'meta_magic'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.5'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec'
27
+ spec.add_development_dependency 'actionpack'
28
+ end
@@ -0,0 +1,7 @@
1
+ require 'archivable/version'
2
+
3
+ require 'archivable/model'
4
+ require 'archivable/controller'
5
+
6
+ module Archivable
7
+ end
@@ -0,0 +1,32 @@
1
+ require 'active_support/concern'
2
+ require 'meta_magic'
3
+
4
+ module Archivable
5
+ module Controller
6
+ include MetaMagic::Controller
7
+ extend ActiveSupport::Concern
8
+
9
+ def archive
10
+ archivable_model = set_model_instance_variable
11
+ archivable_model.toggle(:archived)
12
+
13
+ if archivable_model.save
14
+ redirect_to action: :show, notice: get_archivable_flash(archivable_model, success: true)
15
+ else
16
+ render :edit, alert: get_archivable_flash(archivable_model, success: false)
17
+ end
18
+ end
19
+
20
+ def archived
21
+ assign_models_instance_variable_array.archived
22
+ render :index
23
+ end
24
+
25
+ def get_archivable_flash(model, opts = {})
26
+ "#{ model.class.name } was"\
27
+ "#{ ' not' unless opts[:success] } "\
28
+ "#{ model.archived ? :archived : :unarchived } "\
29
+ "successfully."
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,21 @@
1
+ require 'active_support/concern'
2
+
3
+ module Archivable
4
+ module Model
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods
8
+ def archived
9
+ scoped(conditions: { archived: true })
10
+ end
11
+
12
+ def unarchived
13
+ scoped(conditions: { archived: false })
14
+ end
15
+ end
16
+
17
+ def archived?
18
+ archived
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Archivable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Archivable::Controller do
4
+
5
+ let(:controller) { FakesController.new }
6
+
7
+ subject { controller }
8
+
9
+ it { should respond_to(:archive) }
10
+
11
+ describe '.archive' do
12
+
13
+ it 'should set the instance variable' do
14
+ subject.archive
15
+ subject.get_model_instance_variable.should eq(subject.fake)
16
+ end
17
+
18
+ context 'when successfully archived' do
19
+
20
+ it 'should render the :show action' do
21
+ pending 'controller mocking tweaks needed'
22
+ subject.should_receive(:redirect_to).with(action: :show, notice: "Fake was archived successfully.")
23
+ subject.archive
24
+ end
25
+ end
26
+
27
+ context 'when unsuccessfully archived' do
28
+
29
+ it 'should render the :show action' do
30
+ Fake.any_instance.stub({ save: false })
31
+ subject.should_receive(:render).with(:edit, { alert: "Fake was not archived successfully." })
32
+ subject.archive
33
+ end
34
+ end
35
+ end
36
+ end
File without changes
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec'
4
+
5
+ require 'action_controller'
6
+
7
+ require 'archivable'
8
+
9
+ RSpec.configure do |config|
10
+ config.color_enabled = true
11
+ end
12
+
13
+ class Fake
14
+ attr_accessor :archived
15
+
16
+ def toggle(dont_care)
17
+ self.archived = archived ? false : true
18
+ end
19
+
20
+ def save
21
+ true
22
+ end
23
+ end
24
+
25
+ class FakesController < ActionController::Base
26
+ include Archivable::Controller
27
+
28
+ attr_accessor :fake
29
+
30
+ def set_fake
31
+ @fake = Fake.new
32
+ end
33
+
34
+ def get_fake
35
+ @fake
36
+ end
37
+
38
+ def render(dont_care, also_dont_care)
39
+ end
40
+
41
+ def redirect_to(dont_care)
42
+ end
43
+
44
+ def edit_fake_path(dont_care)
45
+ end
46
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: archivable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Otander
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-24 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: meta_magic
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
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'
83
+ - !ruby/object:Gem::Dependency
84
+ name: actionpack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Archive your Rails models rather than delete them, with model and controller
98
+ concerns.
99
+ email:
100
+ - johnotander@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - archivable.gemspec
112
+ - lib/archivable.rb
113
+ - lib/archivable/controller.rb
114
+ - lib/archivable/model.rb
115
+ - lib/archivable/version.rb
116
+ - spec/archivable_controller_spec.rb
117
+ - spec/archivable_model_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: ''
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.2.2
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Archive your Rails models rather than delete them.
143
+ test_files:
144
+ - spec/archivable_controller_spec.rb
145
+ - spec/archivable_model_spec.rb
146
+ - spec/spec_helper.rb
147
+ has_rdoc: