eitil 1.0.1.e.2 → 1.0.1.e.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/eitil_core/README.md +288 -0
- data/eitil_core/lib/eitil_core/application_controller/slice_params.rb +14 -0
- data/eitil_core/lib/eitil_core/application_controller.rb +2 -0
- data/eitil_core/lib/eitil_core/application_record/all_associations.rb +16 -0
- data/eitil_core/lib/eitil_core/application_record/find_by_like.rb +15 -0
- data/eitil_core/lib/eitil_core/application_record/where_like.rb +15 -0
- data/eitil_core/lib/eitil_core/application_record.rb +4 -0
- data/eitil_core/lib/eitil_core/argument_helpers/all_args_to_ivars.rb +12 -0
- data/eitil_core/lib/eitil_core/argument_helpers/all_kwargs_to_ivars.rb +12 -0
- data/eitil_core/lib/eitil_core/argument_helpers/args_to_ivars.rb +12 -0
- data/eitil_core/lib/eitil_core/argument_helpers.rb +5 -0
- data/eitil_core/lib/eitil_core/concerns/include_concerns_of.rb +15 -0
- data/eitil_core/lib/eitil_core/concerns.rb +2 -0
- data/eitil_core/lib/eitil_core/datetime/prettify.rb +10 -0
- data/eitil_core/lib/eitil_core/datetime.rb +2 -0
- data/eitil_core/lib/eitil_core/errors/raise_error.rb +11 -0
- data/eitil_core/lib/eitil_core/errors.rb +2 -0
- data/eitil_core/lib/eitil_core/float/safe_to_i.rb +9 -0
- data/eitil_core/lib/eitil_core/float.rb +2 -0
- data/eitil_core/lib/eitil_core/hash/auto_dig.rb +17 -0
- data/eitil_core/lib/eitil_core/hash.rb +2 -0
- data/eitil_core/lib/eitil_core/lookups/all_methods.rb +32 -0
- data/eitil_core/lib/eitil_core/lookups.rb +2 -0
- data/eitil_core/lib/eitil_core/railtie.rb +37 -0
- data/eitil_core/lib/eitil_core/safe_executions/safe_call.rb +12 -0
- data/eitil_core/lib/eitil_core/safe_executions/safe_send.rb +12 -0
- data/eitil_core/lib/eitil_core/safe_executions.rb +3 -0
- data/eitil_core/lib/eitil_core/setters/set_ivars.rb +12 -0
- data/eitil_core/lib/eitil_core/setters.rb +2 -0
- data/eitil_core/lib/eitil_core/type_checkers/is_num_or_nan.rb +96 -0
- data/eitil_core/lib/eitil_core/type_checkers.rb +2 -0
- data/eitil_core/lib/eitil_core/validations/run_validations.rb +10 -0
- data/eitil_core/lib/eitil_core/validations.rb +2 -0
- data/eitil_core/lib/eitil_core.rb +24 -0
- data/eitil_integrate/README.md +8 -0
- data/eitil_integrate/lib/eitil_integrate/railtie.rb +10 -0
- data/eitil_integrate/lib/eitil_integrate.rb +0 -0
- data/eitil_store/README.md +16 -0
- data/eitil_store/lib/eitil_store/railtie.rb +10 -0
- data/eitil_store/lib/eitil_store/regex/regex.rb +41 -0
- data/eitil_store/lib/eitil_store/regex.rb +4 -0
- data/eitil_store/lib/eitil_store.rb +4 -0
- data/eitil_support/README.md +78 -0
- data/eitil_support/lib/eitil_support/directory/lookups.rb +23 -0
- data/eitil_support/lib/eitil_support/directory.rb +2 -0
- data/eitil_support/lib/eitil_support/railtie.rb +10 -0
- data/eitil_support/lib/eitil_support/stacktrace/audit.rb +15 -0
- data/eitil_support/lib/eitil_support/stacktrace/call.rb +17 -0
- data/eitil_support/lib/eitil_support/stacktrace/stack.rb +28 -0
- data/eitil_support/lib/eitil_support/stacktrace.rb +4 -0
- data/eitil_support/lib/eitil_support.rb +5 -0
- data/eitil_wrapper/README.md +181 -0
- data/eitil_wrapper/lib/eitil_wrapper/decorators/application_decorator.rb +19 -0
- data/eitil_wrapper/lib/eitil_wrapper/decorators/controller_decorator.rb +60 -0
- data/eitil_wrapper/lib/eitil_wrapper/decorators.rb +3 -0
- data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job.rb +34 -0
- data/eitil_wrapper/lib/eitil_wrapper/jobs/new_job_debugger.rb +37 -0
- data/eitil_wrapper/lib/eitil_wrapper/jobs/single_method_job.rb +8 -0
- data/eitil_wrapper/lib/eitil_wrapper/jobs.rb +4 -0
- data/eitil_wrapper/lib/eitil_wrapper/railtie.rb +49 -0
- data/eitil_wrapper/lib/eitil_wrapper/routes/extended_resources.rb +40 -0
- data/eitil_wrapper/lib/eitil_wrapper/routes.rb +2 -0
- data/eitil_wrapper/lib/eitil_wrapper/scopes/default_scopes.rb +80 -0
- data/eitil_wrapper/lib/eitil_wrapper/scopes.rb +2 -0
- data/eitil_wrapper/lib/eitil_wrapper.rb +7 -0
- data/lib/eitil/all.rb +18 -0
- data/lib/eitil/engine.rb +38 -0
- data/lib/eitil/railtie.rb +6 -0
- data/lib/eitil/version.rb +5 -0
- data/lib/eitil.rb +6 -0
- data/lib/tasks/eitil_tasks.rake +4 -0
- metadata +72 -1
@@ -0,0 +1,96 @@
|
|
1
|
+
|
2
|
+
# require "eitil_core/type_checkers/is_num_or_nan"
|
3
|
+
|
4
|
+
require "eitil_store/regex/regex"
|
5
|
+
|
6
|
+
class String
|
7
|
+
|
8
|
+
def is_nan?
|
9
|
+
self !~ EitilStore::Regex::IsNum
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_num?
|
13
|
+
!is_nan?
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
# Descending classes which are always numeric
|
19
|
+
|
20
|
+
class Numeric
|
21
|
+
|
22
|
+
def is_nan?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def is_num?
|
27
|
+
true
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
# Classes which are never numeric
|
33
|
+
|
34
|
+
class NilClass
|
35
|
+
|
36
|
+
def is_nan?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_num?
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
class TrueClass
|
48
|
+
|
49
|
+
def is_nan?
|
50
|
+
true
|
51
|
+
end
|
52
|
+
|
53
|
+
def is_num?
|
54
|
+
false
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
class FalseClass
|
61
|
+
|
62
|
+
def is_nan?
|
63
|
+
true
|
64
|
+
end
|
65
|
+
|
66
|
+
def is_num?
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
class Hash
|
74
|
+
|
75
|
+
def is_nan?
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
79
|
+
def is_num?
|
80
|
+
false
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
class Array
|
87
|
+
|
88
|
+
def is_nan?
|
89
|
+
true
|
90
|
+
end
|
91
|
+
|
92
|
+
def is_num?
|
93
|
+
false
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
|
2
|
+
# require "eitil_core"
|
3
|
+
|
4
|
+
# core class patches
|
5
|
+
require "eitil_core/hash"
|
6
|
+
require "eitil_core/float"
|
7
|
+
require "eitil_core/datetime"
|
8
|
+
|
9
|
+
# multi class patches
|
10
|
+
require "eitil_core/type_checkers"
|
11
|
+
|
12
|
+
# rails class patches
|
13
|
+
require "eitil_core/application_record"
|
14
|
+
require "eitil_core/application_controller"
|
15
|
+
|
16
|
+
# helper patches
|
17
|
+
require "eitil_core/errors"
|
18
|
+
require "eitil_core/argument_helpers"
|
19
|
+
require "eitil_core/safe_executions"
|
20
|
+
require "eitil_core/setters"
|
21
|
+
require "eitil_core/validations"
|
22
|
+
require "eitil_core/lookups"
|
23
|
+
require "eitil_core/concerns"
|
24
|
+
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
# EitilStore
|
5
|
+
|
6
|
+
EitilStore stores data in containers, such as Regexp instances.
|
7
|
+
|
8
|
+
|
9
|
+
## EitilSupport::Regex
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
|
13
|
+
require "eitil_store/regex"
|
14
|
+
|
15
|
+
```
|
16
|
+
Provides regular expressions which are of general use. To see which general expressions are available, see /eitil_store/regex/regex.rb
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# require "eitil_store/regex/regex"
|
2
|
+
|
3
|
+
module EitilStore
|
4
|
+
module Regex
|
5
|
+
|
6
|
+
# URL
|
7
|
+
Url = /(\A\z)|(\A(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?\z)/ix
|
8
|
+
|
9
|
+
# Domain
|
10
|
+
Domain = /(\A\z)|(\A[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?)?\z)/ix
|
11
|
+
|
12
|
+
# From the email regex research: http://fightingforalostcause.net/misc/2006/compare-email-regex.php
|
13
|
+
Email = /\A([\w\!\#\z\%\&\'\*\+\-\/\=\?\\A\`{\|\}\~]+\.)*[\w\+-]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)\z/i
|
14
|
+
|
15
|
+
# Validates a UUID as defined: http://en.wikipedia.org/wiki/Universally_unique_identifier
|
16
|
+
UUID = /\A(\h{32}|\h{8}-\h{4}-\h{4}-\h{4}-\h{12})\z/
|
17
|
+
|
18
|
+
# IsNum comes from the Rubinius source code and identifies both integers and floats correctly.
|
19
|
+
IsNum = /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/
|
20
|
+
|
21
|
+
# Validates Credit Card numbers, Checks if it contains 16 numbers in groups of 4 separated by -, space or nothing
|
22
|
+
CreditCard = /\A(\d{4}-){3}\d{4}\z|\A(\d{4}\s){3}\d{4}\z|\A\d{16}\z/
|
23
|
+
|
24
|
+
# MasterCard credit card
|
25
|
+
MasterCard = /\A5[1-5]\d{14}\z/
|
26
|
+
|
27
|
+
# Visa credit card
|
28
|
+
Visa = /\A4\d{15}\z/
|
29
|
+
|
30
|
+
# Source: http://snipplr.com/view/15322/iban-regex-all-ibans/
|
31
|
+
# You have to remove spaces or any separator character from the original field before use this regex
|
32
|
+
Iban = /[a-zA-Z]{2}[0-9]{2}[a-zA-Z0-9]{4}[0-9]{7}([a-zA-Z0-9]?){0,16}/
|
33
|
+
|
34
|
+
# General postal code: validates a 5 digits postal code
|
35
|
+
GeneralPostalCode = /\A\d{5}\z/
|
36
|
+
|
37
|
+
# Validates US ZIP Code (basic and extended format)
|
38
|
+
ZIPCode = /\A(\d{5}\z)|(\d{5}-\d{4}\z)/
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
# EitilSupport
|
5
|
+
|
6
|
+
EitilSupport provides utility through stand-alone classes and modules.
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
## EitilSupport::Directory
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
|
14
|
+
require "eitil_support/directory"
|
15
|
+
|
16
|
+
```
|
17
|
+
|
18
|
+
The EitilSupport::Directory module provides methods which help you introspect your Rails project.
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
EitilSupport::Directory.contents(directory='app')
|
22
|
+
# returns all files and subdirectories of a given directory
|
23
|
+
```
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
EitilSupport::Directory.files(directory='app')
|
27
|
+
# returns all files of a given directory
|
28
|
+
```
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
EitilSupport::Directory.subdirs(directory='app')
|
32
|
+
# returns all subdirectories of a given directory
|
33
|
+
```
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
EitilSupport::Directory.lines(directory='app')
|
37
|
+
# returns the total amount of lines of all files of a given directory
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
## EitilSupport::StackTrace
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
|
45
|
+
require "eitil_support/stacktrace"
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
The classes EitilSupport::Stack and EitilSupport::Call, and the module EitilSupport::Stack::Audit, provide the utility of easily viewing and storing the current stacktrace anywhere in your code – by initializing EitilSupport::Stack:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
stack = EitilSupport::Stack.new
|
53
|
+
```
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
stack.report
|
57
|
+
# returns the stacktrace as array, with each call being a stringified instance of EitilSupport::Call
|
58
|
+
```
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
stack.show
|
62
|
+
# pretty prints the stack.report stacktrace
|
63
|
+
```
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
stack.find
|
67
|
+
# accepts a block to find a specific call
|
68
|
+
```
|
69
|
+
|
70
|
+
You can also store the stacktrace of a record's update action into its audit. In order to do so, you need 1) to include EitilSupport::Stack::Audit into your model, and 2) add a :stacktrace column to your audits through the following migration.
|
71
|
+
|
72
|
+
### Migration
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
def change
|
76
|
+
add_column :audits, :stacktrace, :text, array: true, default: []
|
77
|
+
end
|
78
|
+
```
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module EitilSupport
|
2
|
+
module Directory
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def contents(directory='app')
|
6
|
+
Dir[File.join(directory, '**', '*')]
|
7
|
+
end
|
8
|
+
|
9
|
+
def files(directory='app')
|
10
|
+
contents(directory).select { |file| File.file?(file) }
|
11
|
+
end
|
12
|
+
|
13
|
+
def subdirs(directory='app')
|
14
|
+
contents(directory).select { |file| File.directory?(file) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def lines(directory='app')
|
18
|
+
files(directory).map { |file| File.open(file).count }.sum
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module EitilSupport::Stack::Audit
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
after_update :add_stacktrace_to_audit
|
8
|
+
|
9
|
+
def add_stacktrace_to_audit
|
10
|
+
stacktrace = EitilSupport::Stack.new.report
|
11
|
+
self.audits.last.update(stacktrace: stacktrace)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module EitilSupport
|
2
|
+
class Call
|
3
|
+
|
4
|
+
attr_reader :program, :line, :meth
|
5
|
+
|
6
|
+
CALL_RE = /(.*):(\d+):in `(.*)'/
|
7
|
+
|
8
|
+
def initialize(string)
|
9
|
+
@program, @line, @meth = CALL_RE.match(string).captures
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"#{"#{meth}".ljust(50)} #{"(#{line})".ljust(6)} #{program}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module EitilSupport
|
2
|
+
class Stack
|
3
|
+
|
4
|
+
attr_reader :stack, :backtrace
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@stack = caller[1..]
|
8
|
+
@backtrace = stack.map { |call| EitilSupport::Call.new(call) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def report
|
12
|
+
backtrace.map(&:to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
ap report
|
17
|
+
end
|
18
|
+
|
19
|
+
def find(&block)
|
20
|
+
backtrace.find(&block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.parse(array_as_string)
|
24
|
+
array_as_string.sub('[', ' ').reverse.sub(']','').reverse.split(',').flatten
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
# EitilWrapper
|
5
|
+
|
6
|
+
EitilWrapper wraps core rails operations with extended utilities – such as routing, jobs and decoraters.
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
## EitilWrapper::Decorators
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
|
16
|
+
require "eitil_wrapper/decorators"
|
17
|
+
|
18
|
+
```
|
19
|
+
|
20
|
+
The Eitil decorator wrappers help you to standardize the calling of the right decorator method from within your controller action. Basically it provides you with a decorate macro in each controller.
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
decorate(dec_item, dec_method: nil, dec_class: nil, **dec_kwargs)
|
24
|
+
```
|
25
|
+
|
26
|
+
- dec_item is the instance that will be decorated
|
27
|
+
- dec_method enabled you to set the desired decorator method. If not provided, it will look into the request params: if params["isMobile"] is present it will call .app, if params["isWeb"] is present it will call :app. If neither is provided in the params, it will call the default method :base.
|
28
|
+
- dec_class enables you to overwrite the decorator class that will be called. If not provided, the decorator class will be inferred from the instance model's classname (User => UserDecorator).
|
29
|
+
- dec_kwargs enables you to provide additional arguments, which will be passed to your decorator method.
|
30
|
+
|
31
|
+
|
32
|
+
### Configuration
|
33
|
+
|
34
|
+
1. Your decorator classes should inherit from Eitil::ApplicationDecorator.
|
35
|
+
2. Your controllers should inherit the module Eitil::ControllerDecorator, through inclusion in a superclass.
|
36
|
+
3. If you set controller ivars for each request, you can make them available in your decorators by providing Eitil a method which returns the names of your ivars as an array of symbols:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
# initializers/eitil.rb
|
40
|
+
|
41
|
+
Eitil.set_config do |config|
|
42
|
+
config.get_controller_ivars_method = 'API::BaseController.controller_ivars' # => [:user, :env]
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
## EitilWrapper::Jobs
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
|
54
|
+
require "eitil_wrapper/jobs"
|
55
|
+
|
56
|
+
```
|
57
|
+
|
58
|
+
The Eitil jobs wrapper enables you to create perform_now and perform_later jobs on the fly, without the need to create a new class and file.
|
59
|
+
|
60
|
+
The macro new_job accepts a :method as argument and defines a new method :method_job. The newly defined :method_job, when called, performs the orginal :method in the background. The new_job macro accepts both instance methods and singleton methods, which are defined within there own method scope.
|
61
|
+
|
62
|
+
In contrast, the new_job_debugger macro defines a new :method_job_debugger method, which performs in the foreground.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
# require "eitil_wrapper/jobs/new_job"
|
66
|
+
|
67
|
+
new_job(_method, *args, **kwargs)
|
68
|
+
# assuming a method :hello_world, call as: new_job :hello_world
|
69
|
+
# => defines :hello_world_job
|
70
|
+
```
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# require "eitil_wrapper/jobs/new_job_debugger"
|
74
|
+
|
75
|
+
new_job_debugger(_method, *args, **kwargs)
|
76
|
+
# assuming a method :hello_world, call as: new_job_debugger :hello_world
|
77
|
+
# => defines :hello_world_job_debugger
|
78
|
+
```
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
## EitilWrapper::Routes
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
|
88
|
+
require "eitil_wrapper/routes"
|
89
|
+
|
90
|
+
```
|
91
|
+
|
92
|
+
The Eitil router wrapper enables you to easily create new routes that can be shared among controllers. In that sense, it is as a custom extension of the built-in resourceful routes.
|
93
|
+
|
94
|
+
### New route
|
95
|
+
|
96
|
+
The first macro, .new_route, enables you to create new route objects which may be called and used by different controllers.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
# require "eitil_wrapper/routes/extended_resources"
|
100
|
+
|
101
|
+
new_route(verb, _method, action, scope)
|
102
|
+
# call as: new_route :post, :attachment, "add_attachment", :member
|
103
|
+
```
|
104
|
+
|
105
|
+
- verb refers to the http_verb, e.g. :put.
|
106
|
+
- method refers to the given http method (e.g. 'users/:id'). Additionally, this is the name you will refer to in order to include the route into a controller. Therefore the argument should be unique among all other routes.
|
107
|
+
- action refers to the controller action to which you want to redirect to request, e.g. :update_user.
|
108
|
+
- scope refers to the url and can be set to either :member or :collection.
|
109
|
+
|
110
|
+
### Add route
|
111
|
+
|
112
|
+
The second macro, extended_resources, enables you to create all standard resources for a controller and add your own standardized routes. This macro works the same as the built-in :resources, except that you can pass more arguments to only: [], which adds the routes to your controller.
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
# require "eitil_wrapper/routes/extended_resources"
|
116
|
+
|
117
|
+
extended_resources(controller, **kwargs)
|
118
|
+
# call as: extended_resources :posts, only: [:create, :update, :attachment]
|
119
|
+
```
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
## EitilWrapper::Scopes
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
|
129
|
+
require "eitil_wrapper/scopes"
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
Scopes are generated through the columns of your model's database table. Which scopes are generated depends on the datatype of a column. For example, if your User model with table users has a column is_manager, a scope :is_manager_true is generated for your User model. A scope method is defined only if it does not already responds to another method of the same name. The scopes generated are:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
# require "eitil_wrapper/scopes/default_scopes"
|
137
|
+
|
138
|
+
# columns of datatype: boolean
|
139
|
+
.{column_name}_true
|
140
|
+
.{column_name}_false
|
141
|
+
|
142
|
+
# columns of datatype: datetime
|
143
|
+
.{column_name}_today
|
144
|
+
.{column_name}_past
|
145
|
+
.{column_name}_future
|
146
|
+
.{column_name}_on_date(date)
|
147
|
+
.{column_name}_before_date(date)
|
148
|
+
.{column_name}_after_date(date)
|
149
|
+
.{column_name}_between_dates(start_date, end_date)
|
150
|
+
.{column_name}_oldest_first
|
151
|
+
.{column_name}_newest_first
|
152
|
+
|
153
|
+
# columns of datatype: date
|
154
|
+
.{column_name}_today
|
155
|
+
.{column_name}_past
|
156
|
+
.{column_name}_future
|
157
|
+
.{column_name}_on_date(date)
|
158
|
+
.{column_name}_before_date(date)
|
159
|
+
.{column_name}_after_date(date)
|
160
|
+
.{column_name}_between_dates(start_date, end_date)
|
161
|
+
.{column_name}_oldest_first
|
162
|
+
.{column_name}_newest_first
|
163
|
+
|
164
|
+
# columns of datatype: integer
|
165
|
+
.{column_name}_equal_to(number)
|
166
|
+
.{column_name}_lower_than(number)
|
167
|
+
.{column_name}_higher_than(number)
|
168
|
+
.{column_name}_between(min, max)
|
169
|
+
.{column_name}_ascending
|
170
|
+
.{column_name}_descending
|
171
|
+
|
172
|
+
# columns of datatype: float
|
173
|
+
.{column_name}_equal_to(number)
|
174
|
+
.{column_name}_lower_than(number)
|
175
|
+
.{column_name}_higher_than(number)
|
176
|
+
.{column_name}_between(min, max)
|
177
|
+
.{column_name}_ascending
|
178
|
+
.{column_name}_descending
|
179
|
+
```
|
180
|
+
|
181
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module EitilWrapper
|
2
|
+
class ApplicationDecorator
|
3
|
+
|
4
|
+
include ActiveModel::Model
|
5
|
+
|
6
|
+
def initialize(attributes={}, **kwargs)
|
7
|
+
super attributes
|
8
|
+
all_kwargs_to_ivars binding
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.method_missing(method_name, *args, **kwargs)
|
12
|
+
if %i$ web app $.include?(method_name.to_sym)
|
13
|
+
kwargs.any? ? send(:base, *args, **kwargs) : send(:base, *args)
|
14
|
+
end
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|