acts_as_railable 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
+ SHA256:
3
+ metadata.gz: d5d54d944f56b70ed779d7be62d18e528106a3b71e03ac55c991c930aa15bab7
4
+ data.tar.gz: f86a1c086b761eaf296ef55b17523d677da0aae07032c4cdb1e5a279ec5891e7
5
+ SHA512:
6
+ metadata.gz: c71ec735fdb453633cb9b5f56648d4e23a34f41349a0f74f1cc8ef087830cdb443303c0de04e1d22274cf46c8119241f25d60d356015a5bd98128b856d14db75
7
+ data.tar.gz: a015bb53280646c958dc43a6636789175710c9815f0a55da793b3c05d3af8bd38240956a1bb01f2a26c1edb1e9b35bef858869d19240f3b23984519fc2f5d2aa
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Li Qi
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
+ # ActsAsRailable
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 "acts_as_railable"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install acts_as_railable
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,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ class String
2
+ def numeric?
3
+ return true if self =~ /\A\d+\Z/
4
+ true if Float(self) rescue false
5
+ end
6
+
7
+ def is_numeric?
8
+ # `!!` converts parsed number to `true`
9
+ !!Kernel.Float(self)
10
+ rescue TypeError, ArgumentError
11
+ false
12
+ end
13
+
14
+ def deep_strip!
15
+ pattern = /([[:blank:]])+/
16
+ if self.match? pattern
17
+ self.gsub!(pattern, ' ').strip!
18
+ else
19
+ self.strip!
20
+ end
21
+ end
22
+
23
+ def deep_strip
24
+ self.gsub(/([[:blank:]])+/, ' ').strip
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ module ActsAsMoonable
2
+ module Humanable
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def i18n_attribute_name attr
7
+ self.human_attribute_name attr
8
+ end
9
+
10
+ def human_action_name action, views="defaults"
11
+ I18n.t("#{views}.action.#{action}", model: self.model_name.human)
12
+ end
13
+
14
+ def human_enum_name(enum_name, enum_value)
15
+ self.human_attribute_name "#{enum_name}.#{enum_value}"
16
+ end
17
+
18
+ def human_enum_choices enum_name
19
+ enum_hash = self.public_send enum_name.to_s.pluralize
20
+ enum_hash.keys.map { |enum_value| [ self.human_enum_name(enum_name, enum_value), enum_value ] }
21
+ end
22
+
23
+ # constants
24
+ # CURRENCIES = %w( CNY USD EUR GBP JPY )
25
+ def human_array_choices enum_name
26
+ array_values = self.const_get enum_name.to_s.pluralize.upcase
27
+ array_values.map { |enum_value| [ self.human_enum_name(enum_name, enum_value), enum_value ] }
28
+ end
29
+ end
30
+
31
+ def i18n_attribute_name attr
32
+ self.class.i18n_attribute_name attr
33
+ end
34
+
35
+ def human_enum_name enum_name
36
+ enum_value = self.public_send enum_name
37
+ self.class.human_enum_name enum_name, enum_value
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ module ActsAsMoonable
2
+ module Interval
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ # database: local date
7
+ # parameter: local date
8
+ scope :date_field_interval, -> (field, d1, d2) {
9
+ tname = self.table_name
10
+ if d1.present? and d2.present?
11
+ where("#{tname}.#{field} >= ?", d1).where("#{tname}.#{field} <= ?", d2)
12
+ elsif d1.present?
13
+ where("#{tname}.#{field} >= ?", d1)
14
+ elsif d2.present?
15
+ where("#{tname}.#{field} <= ?", d2)
16
+ end
17
+ }
18
+
19
+ # database: time
20
+ # parameter: utc/local time
21
+ scope :time_field_interval, -> (field, t1, t2) {
22
+ tname = self.table_name
23
+ if t1.present? and t2.present?
24
+ where("#{tname}.#{field} >= ?", t1).where("#{tname}.#{field} <= ?", t2)
25
+ elsif t1.present?
26
+ where("#{tname}.#{field} >= ?", t1)
27
+ elsif t2.present?
28
+ where("#{tname}.#{field} <= ?", t2)
29
+ end
30
+ }
31
+
32
+ # database: time
33
+ # parameter: utc time
34
+ scope :utc_field_interval, -> (field, t1, t2) {
35
+ time_field_interval(field, t1, t2)
36
+ }
37
+
38
+ # database: utc time
39
+ # parameter: local date
40
+ scope :local_field_interval, -> (field, d1, d2) {
41
+ t1 = d1.to_time.beginning_of_day if d1.present?
42
+ t2 = d2.to_time.end_of_day if d2.present?
43
+ time_field_interval(field, t1, t2)
44
+ }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,4 @@
1
+ module ActsAsRailable
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module ActsAsRailable
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,7 @@
1
+ require "acts_as_railable/version"
2
+ require "acts_as_railable/railtie"
3
+ require "acts_as_railable/core_ext"
4
+
5
+ module ActsAsRailable
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :acts_as_railable do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_railable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Li Qi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-01 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'
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'
27
+ description: ActsAsMoonable gem provides extended methods for rails.
28
+ email:
29
+ - cloudbsd@qq.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/acts_as_railable.rb
38
+ - lib/acts_as_railable/core_ext.rb
39
+ - lib/acts_as_railable/humanable.rb
40
+ - lib/acts_as_railable/interval.rb
41
+ - lib/acts_as_railable/railtie.rb
42
+ - lib/acts_as_railable/version.rb
43
+ - lib/tasks/acts_as_railable_tasks.rake
44
+ homepage: http://github.com/cloudbsd/acts_as_moonable
45
+ licenses:
46
+ - BSD
47
+ metadata:
48
+ allowed_push_host: https://rubygems.org
49
+ homepage_uri: http://github.com/cloudbsd/acts_as_moonable
50
+ source_code_uri: http://github.com/cloudbsd/acts_as_moonable
51
+ changelog_uri: http://github.com/cloudbsd/acts_as_moonable/CHANGELOG.md
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.3.7
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Acts As Moonable Gem.
71
+ test_files: []