active_regulation 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ee29d99c3d4372c7c8e9bd32e4d6060d81164a1d
4
+ data.tar.gz: 7d49c2268b1c094b90978d125d0ac25200f384b1
5
+ SHA512:
6
+ metadata.gz: 5afb2a5923f2d4465dfe661d76766ee5af2a9133da3d33c87bd87c08f5888c5b0c8f1bbff15f441f961378ccb5786ded22ef8b1c79ffa0be50b5e7380bf63995
7
+ data.tar.gz: 574caf9bac2a2112f42c587836d6c110e330858434e0ca44dce8018587074e659df2a34589e2bcb8064e89a8609d6be535c28d299cc5257e7d03207f50346bad
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --backtrace
2
+ --color
3
+ --format progress
4
+ --order random
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ before_install:
2
+ - sudo apt-get install libxml2-dev
3
+ cache: bundler
4
+ language: ruby
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - j.gomez@drexed.com
9
+ on_failure: change
10
+ on_success: never
11
+ rvm:
12
+ - ruby-head
13
+ script: 'bundle exec rake'
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_regulation.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # ActiveRegulation
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/active_regulation.svg)](http://badge.fury.io/rb/active_regulation)
4
+ [![Build Status](https://travis-ci.org/drexed/active_regulation.svg?branch=master)](https://travis-ci.org/drexed/active_regulation)
5
+ [![Coverage Status](https://coveralls.io/repos/drexed/active_regulation/badge.png)](https://coveralls.io/r/drexed/active_regulation)
6
+
7
+ ActiveRegulation is a library for commonly used record states.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'active_regulation'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install active_regulation
24
+
25
+ ## Table of Contents
26
+
27
+ * [Methods](#methods)
28
+ * [Usage](#usage)
29
+
30
+ ## Methods
31
+
32
+ **Modules:**
33
+ * activation
34
+ * containment
35
+ * visibility
36
+
37
+ **Attributes:**
38
+ * :inactivated_at
39
+ * :contained_at
40
+ * :invisible_at
41
+
42
+ ```ruby
43
+ class User < ActiveRecord::Base
44
+
45
+ # Add one of the datetime attributes
46
+ # above to the corresponding table.
47
+
48
+ include ActiveRegulation::Containment
49
+
50
+ end
51
+ ```
52
+
53
+ ## Usage
54
+ ```ruby
55
+ user = User.create!
56
+
57
+ user.active? #=> true
58
+ user.inactive? #=> false
59
+
60
+ user.inactive!
61
+ user.active? #=> false
62
+
63
+ user.active!
64
+ user.active? #=> true
65
+
66
+ user.to_activation #=> 'Active'
67
+
68
+ User.active #=> retrieves all active records
69
+ User.inactive #=> retrieves all inactive records
70
+ ```
71
+
72
+ ## Contributing
73
+
74
+ 1. Fork it ( https://github.com/[my-github-username]/active_regulation/fork )
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
77
+ 4. Push to the branch (`git push origin my-new-feature`)
78
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task default: :spec
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_regulation/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_regulation"
8
+ spec.version = ActiveRegulation::VERSION
9
+ spec.authors = ["Juan Gomez"]
10
+ spec.email = ["j.gomez@drexed.com"]
11
+
12
+ spec.summary = %q{Commonly used record states.}
13
+ spec.description = %q{Manage the states of records by commonly used attributes.}
14
+ spec.homepage = "https://github.com/drexed/active_regulation"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib", "support"]
21
+
22
+ spec.add_runtime_dependency "activerecord"
23
+ spec.add_runtime_dependency "activesupport"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "coveralls"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "sqlite3"
30
+ spec.add_development_dependency "database_cleaner"
31
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_regulation"
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
data/bin/rake ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rake' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('rake', 'rake')
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ en:
2
+ active_regulation:
3
+ activation:
4
+ active: "Active"
5
+ inactive: "Inactive"
6
+ containment:
7
+ contained: "Contained"
8
+ uncontained: "Uncontained"
9
+ visibility:
10
+ invisible: "Invisible"
11
+ visible: "Visible"
@@ -0,0 +1,33 @@
1
+ require "active_regulation/version"
2
+ require "active_regulation/activation"
3
+ require "active_regulation/containment"
4
+ require "active_regulation/visibility"
5
+
6
+ if defined?(Rails)
7
+ require 'rails'
8
+
9
+ module ActiveRegulation
10
+ class Railtie < ::Rails::Railtie
11
+
12
+ initializer 'active_regulation' do |app|
13
+ ActiveRegulation::Railtie.instance_eval do
14
+ locales_from(app.config.i18n.available_locales).each do |locale|
15
+ (I18n.load_path << path(locale)) if File.file?(path(locale))
16
+ end
17
+ end
18
+ end
19
+
20
+ protected
21
+
22
+ def self.path(locale)
23
+ File.expand_path("../../config/locales/#{locale}.yml", __FILE__)
24
+ end
25
+
26
+ def self.locales_from(args)
27
+ array = Array(args || [])
28
+ array.blank? ? '*' : array
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ module ActiveRegulation
2
+ module Activation
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ scope :active, -> { where(inactivated_at: nil) }
7
+ scope :inactive, -> { where.not(inactivated_at: nil) }
8
+ end
9
+
10
+ def active!
11
+ update(inactivated_at: nil) if inactive?
12
+ end
13
+
14
+ def inactive!
15
+ update(inactivated_at: Time.now) if active?
16
+ end
17
+
18
+ def active?
19
+ inactivated_at.nil?
20
+ end
21
+
22
+ def inactive?
23
+ !active?
24
+ end
25
+
26
+ def to_activation
27
+ I18n.t("active_regulation.activation.#{active? ? :active : :inactive}")
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module ActiveRegulation
2
+ module Containment
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ scope :contained, -> { where.not(contained_at: nil) }
7
+ scope :uncontained, -> { where(contained_at: nil) }
8
+ end
9
+
10
+ def contain!
11
+ update(contained_at: Time.now) if uncontained?
12
+ end
13
+
14
+ def uncontain!
15
+ update(contained_at: nil) if contained?
16
+ end
17
+
18
+ def contained?
19
+ !uncontained?
20
+ end
21
+
22
+ def uncontained?
23
+ contained_at.nil?
24
+ end
25
+
26
+ def to_containment
27
+ I18n.t("active_regulation.containment.#{uncontained? ? :uncontained : :contained}")
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveRegulation
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+ module ActiveRegulation
2
+ module Visibility
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ scope :visible, -> { where(invisible_at: nil) }
7
+ scope :invisible, -> { where.not(invisible_at: nil) }
8
+ end
9
+
10
+ def invisible!
11
+ update(invisible_at: Time.now)
12
+ end
13
+
14
+ def visible!
15
+ update(invisible_at: nil)
16
+ end
17
+
18
+ def invisible?
19
+ !visible?
20
+ end
21
+
22
+ def visible?
23
+ invisible_at.nil?
24
+ end
25
+
26
+ def to_visibility
27
+ I18n.t("active_regulation.visibility.#{visible? ? :visible : :invisible}")
28
+ end
29
+
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_regulation
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Gomez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
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: activesupport
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: '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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
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: rake
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: rspec
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
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: database_cleaner
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Manage the states of records by commonly used attributes.
126
+ email:
127
+ - j.gomez@drexed.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".coveralls.yml"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - README.md
139
+ - Rakefile
140
+ - active_regulation.gemspec
141
+ - bin/console
142
+ - bin/rake
143
+ - bin/setup
144
+ - config/locales/en.yml
145
+ - lib/active_regulation.rb
146
+ - lib/active_regulation/activation.rb
147
+ - lib/active_regulation/containment.rb
148
+ - lib/active_regulation/version.rb
149
+ - lib/active_regulation/visibility.rb
150
+ homepage: https://github.com/drexed/active_regulation
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ - support
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.4.8
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Commonly used record states.
175
+ test_files: []