acts_as_moonable 0.3.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: 6a414f083829901b361655c18a82bb3751d476fddcf28468a5e3bf7da2052e3a
4
+ data.tar.gz: 3b0803ce32e2b72e2ae4a3c4cdec5ce665d28078697c42e6c14ebdfd1a27b406
5
+ SHA512:
6
+ metadata.gz: 562a06370cf1c31aa85c6af7c78b11edbe4779a9905c07cde985300feeeeab7df8f6b02fe9a208da9db689be475d5abab05928fb88f64fbd05cb5811b327848e
7
+ data.tar.gz: 5b87dc6855e60b0ff4fdba276f2e876cd1a462a62c8887373436bb08a74f0e46e76cc6a84e7cea8951225afe1a493d7065f37cd04a0829fb1deecac61a3cb16f
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2021 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
+ # ActsAsMoonable
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_moonable'
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_moonable
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,13 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require "rake/testtask"
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
12
+
13
+ task default: :test
@@ -0,0 +1,9 @@
1
+ require "acts_as_moonable/version"
2
+ require "acts_as_moonable/railtie"
3
+ require "acts_as_moonable/core_ext"
4
+ require "acts_as_moonable/humanable"
5
+ require "acts_as_moonable/interval"
6
+
7
+ module ActsAsMoonable
8
+ # Your code goes here...
9
+ end
@@ -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,39 @@
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
11
+ I18n.t("layouts.action.#{action}", model: self.model_name.human)
12
+ end
13
+
14
+ def human_enum_name(enum_name, enum_value)
15
+ # I18n.t("activerecord.attributes.#{self.model_name.i18n_key}.#{enum_name.to_s.pluralize}.#{enum_value}")
16
+ self.human_attribute_name "#{enum_name}.#{enum_value}"
17
+ end
18
+
19
+ def human_enum_choices enum_name
20
+ enum_hash = self.public_send enum_name.to_s.pluralize
21
+ enum_hash.keys.map { |enum_value| [ self.human_enum_name(enum_name, enum_value), enum_value ] }
22
+ end
23
+
24
+ def human_array_choices enum_name
25
+ array_values = self.const_get enum_name.upcase
26
+ array_values.map { |enum_value| [ self.human_enum_name(enum_name, enum_value), enum_value ] }
27
+ end
28
+ end
29
+
30
+ def i18n_attribute_name attr
31
+ self.class.human_attribute_name attr
32
+ end
33
+
34
+ def human_enum_name enum_name
35
+ enum_value = self.public_send enum_name
36
+ self.class.human_enum_name enum_name, enum_value
37
+ end
38
+ end
39
+ 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/time
40
+ scope :local_field_interval, -> (field, dt1, dt2) {
41
+ t1 = dt1.to_time if dt1.present?
42
+ t2 = dt2.to_time if dt2.present?
43
+ time_field_interval(field, t1, t2)
44
+ }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,4 @@
1
+ module ActsAsMoonable
2
+ class Railtie < ::Rails::Railtie
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module ActsAsMoonable
2
+ VERSION = '0.3.0'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :acts_as_moonable do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acts_as_moonable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Li Qi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-11 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_moonable.rb
38
+ - lib/acts_as_moonable/core_ext.rb
39
+ - lib/acts_as_moonable/humanable.rb
40
+ - lib/acts_as_moonable/interval.rb
41
+ - lib/acts_as_moonable/railtie.rb
42
+ - lib/acts_as_moonable/version.rb
43
+ - lib/tasks/acts_as_moonable_tasks.rake
44
+ homepage: http://github.com/cloudbsd/acts_as_moonable
45
+ licenses:
46
+ - MIT
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.2.15
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Acts As Moonable Gem.
71
+ test_files: []