enum_style 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
+ SHA256:
3
+ metadata.gz: 98b788e7423c8a01cca8f6e820e6c78354a9d7ea6a4840f6f75710b862277030
4
+ data.tar.gz: 1ec01276ae7ad5d751141c6e7b024c29c35decf34b4efb5db439d24e67e36767
5
+ SHA512:
6
+ metadata.gz: 7e5f59d2dcae051995be12ded6f64bffb90584bb88cb8ebcd50bbb9fe23958b9ba43e9ecbe23f9edade5a39eb2f6c99044950e2fdcbe69ab3f8b59172aff56f4
7
+ data.tar.gz: bd435ebad1a689ad057ce56ee079d004cfec16ee74b7f40f37a3d6df3894b074785fad104997300957dd29f3266139830583a16fde236ffe49571cc9e53776d6
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2019 kenzooooo
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # EnumStyle
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'enum_style'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install enum_style
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'bundler/setup'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rdoc/task'
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = 'rdoc'
13
+ rdoc.title = 'EnumStyle'
14
+ rdoc.options << '--line-numbers'
15
+ rdoc.rdoc_files.include('README.md')
16
+ rdoc.rdoc_files.include('lib/**/*.rb')
17
+ end
File without changes
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,4 @@
1
+ module EnumStyle
2
+ class Engine < ::Rails::Engine
3
+ end
4
+ end
@@ -0,0 +1,20 @@
1
+ module EnumStyle
2
+ class Railtie < Rails::Railtie
3
+
4
+ def preload
5
+
6
+ file_path = ::Rails.root.join('config', 'enum_style.yml')
7
+ result = File.exist?(file_path) ? YAML.load(ERB.new(IO.read(file_path))).result : {}
8
+
9
+ Kernel.const_set('EnumStyles', result)
10
+ end
11
+
12
+ initializer "enum_style" do
13
+ ActiveSupport.on_load(:active_record) do
14
+ extend EnumStyle::Style
15
+ end
16
+ end
17
+
18
+ config.before_configuration { preload }
19
+ end
20
+ end
@@ -0,0 +1,35 @@
1
+ module EnumStyle
2
+
3
+ module Style
4
+
5
+ # overwrite the enum method
6
+ def enum( definitions )
7
+ super( definitions )
8
+ definitions.each do |name, _|
9
+ Helper.define_attr_style_method(self, name)
10
+ end
11
+ end
12
+
13
+ def self.extended(receiver)
14
+ # receiver.class_eval do
15
+ # # alias_method_chain :enum, :enum_help
16
+ # end
17
+ end
18
+
19
+ end
20
+
21
+ module Helper
22
+
23
+ def self.define_attr_style_method(klass, attr_name)
24
+
25
+ attr_style_method_name = "#{attr_name}_style"
26
+
27
+ klass.define_method(attr_style_method_name) do
28
+
29
+ styles = EnumStyles[klass.to_s.underscore]
30
+
31
+ styles ? styles[attr_name.to_s][self.send(attr_name)] : nil
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module EnumStyle
2
+ VERSION = '0.1.0'
3
+ end
data/lib/enum_style.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "enum_style/engine"
2
+ require 'enum_style/style'
3
+ require 'enum_style/railtie'
@@ -0,0 +1,17 @@
1
+ module EnumStyle
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+
5
+ desc "Generates a enum styles yml file."
6
+
7
+ def self.source_root
8
+ @_config_source_root ||= File.expand_path("../templates", __FILE__)
9
+ end
10
+
11
+ def generate_style_yml
12
+
13
+ template 'enum_style.yml', 'config/enum_style.yml'
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ article:
2
+ publish:
3
+ draft: '#ff4500'
4
+ preview: green
5
+ published: blue
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enum_style
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kenzooooo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: mysql2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - ruby.on.nishizawa@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - MIT-LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - app/assets/config/enum_style_manifest.js
52
+ - config/routes.rb
53
+ - lib/enum_style.rb
54
+ - lib/enum_style/engine.rb
55
+ - lib/enum_style/railtie.rb
56
+ - lib/enum_style/style.rb
57
+ - lib/enum_style/version.rb
58
+ - lib/generators/enum_style/install_generator.rb
59
+ - lib/generators/enum_style/templates/enum_style.yml
60
+ homepage: https://github.com/kenzooooo
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.7.6
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: define enum style for rails
84
+ test_files: []