lasha 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -5
- data/lib/lasha/version.rb +1 -1
- data/lib/lasha.rb +68 -53
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb44bec536c98c3f3d09775fce58d7137191d6dcd82dc76021cad122d60b3a5c
|
4
|
+
data.tar.gz: 5eaef9a2d71a073a75246e822952b87304ad966284b20d2ecd601db90892286c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0132c6f43a77cafa2357684186f0d828e99fa4efe661216d740ab561aca3c4bd9d867c551b3f750a0f23c39a0908325788e427ce47efac8ff73ba07e653f1125
|
7
|
+
data.tar.gz: 6111476ee63ce4f814aa7bbc9d9ad2d5bc3b12ff9e96f8a7f602d78762ecc11f71a05d71c3abe2c718db702fde34be4b6e8911c37e97e830f0ac28e7ff746da5
|
data/README.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Lasha
|
2
|
-
|
2
|
+
This rails plugin aims to be a general helper gem for as many rails apps as possible.
|
3
|
+
It will to be a collection of features and helpers that many rails apps would need.
|
4
|
+
Potential of this gem is endless, please fork and add more features!
|
5
|
+
|
6
|
+
## Features
|
7
|
+
### Helpers
|
8
|
+
* Index table generator
|
3
9
|
|
4
10
|
## Usage
|
5
11
|
Controller `index` action
|
@@ -7,8 +13,8 @@ Controller `index` action
|
|
7
13
|
@data = Lasha.index_data(
|
8
14
|
controller: self,
|
9
15
|
# namespace: :admin, # optional
|
10
|
-
# model:
|
11
|
-
collection:
|
16
|
+
# model: Model, # optional
|
17
|
+
collection: Model.all.order(created_at: :desc).limit(20),
|
12
18
|
attributes: %i[amount node_id created_at],
|
13
19
|
# actions: %i[show] # optional
|
14
20
|
)
|
@@ -32,7 +38,7 @@ index view `index.html.slim`
|
|
32
38
|
Add this line to your application's Gemfile:
|
33
39
|
|
34
40
|
```ruby
|
35
|
-
gem
|
41
|
+
gem "lasha"
|
36
42
|
```
|
37
43
|
|
38
44
|
And then execute:
|
@@ -45,11 +51,15 @@ Or install it yourself as:
|
|
45
51
|
$ gem install lasha
|
46
52
|
```
|
47
53
|
|
54
|
+
## Dependencies
|
55
|
+
* rails (5+)
|
56
|
+
* sassc-rails
|
57
|
+
|
48
58
|
## Development Helpers
|
49
59
|
Snippet for quickly rebuilding gem
|
50
60
|
```
|
51
61
|
cd ~/gem_dir
|
52
|
-
gem uninstall lasha; rake build; gem install pkg/lasha-0.2.
|
62
|
+
gem uninstall lasha; rake build; gem install pkg/lasha-0.2.7.gem;
|
53
63
|
```
|
54
64
|
|
55
65
|
## Contributing
|
data/lib/lasha/version.rb
CHANGED
data/lib/lasha.rb
CHANGED
@@ -1,68 +1,83 @@
|
|
1
1
|
require "lasha/engine"
|
2
2
|
|
3
3
|
module Lasha
|
4
|
-
|
4
|
+
INDEX_ACTIONS = %i[new show edit destroy]
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
6
|
+
class << self
|
7
|
+
def index_data(
|
8
|
+
controller:,
|
9
|
+
namespace: nil,
|
10
|
+
model: nil,
|
11
|
+
actions: nil,
|
12
|
+
collection:,
|
13
|
+
attributes:
|
14
|
+
)
|
15
|
+
index_data_hash = {
|
16
|
+
namespace: set_or_guess_namespace(namespace, controller),
|
17
|
+
model: set_or_guess_model(model, collection),
|
18
|
+
collection: collection,
|
19
|
+
attributes: attributes,
|
20
|
+
actions: set_or_guess_actions(actions, controller)
|
21
|
+
}
|
22
|
+
validate_index_data(**index_data_hash)
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
index_data_hash
|
25
|
+
rescue ArgumentError => e
|
26
|
+
puts "******** index_data argument error report"
|
27
|
+
puts "Class: #{e.class}"
|
28
|
+
puts "Message: #{e.message}"
|
29
|
+
puts e.backtrace
|
30
|
+
end
|
29
31
|
|
30
|
-
|
32
|
+
private
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def set_or_guess_namespace(namespace, controller)
|
35
|
+
if namespace.present?
|
36
|
+
namespace
|
37
|
+
elsif controller.class.name.include?("::")
|
38
|
+
controller.class.name.deconstantize.underscore.to_sym
|
39
|
+
end
|
37
40
|
end
|
38
|
-
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
def set_or_guess_model(model, collection)
|
43
|
+
if model.present?
|
44
|
+
model
|
45
|
+
elsif collection.present?
|
46
|
+
collection.first.class
|
47
|
+
end
|
48
|
+
end
|
43
49
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
def set_or_guess_actions(actions, controller)
|
51
|
+
if actions.present?
|
52
|
+
actions
|
53
|
+
else
|
54
|
+
controller.action_methods.to_a.map(&:to_sym) & INDEX_ACTIONS
|
55
|
+
end
|
49
56
|
end
|
50
|
-
end
|
51
57
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
def validate_index_data(**index_data_hash)
|
59
|
+
index_data_hash.each do |key, value|
|
60
|
+
case key
|
61
|
+
when :collection
|
62
|
+
next if value.present?
|
63
|
+
|
64
|
+
raise_args_error("Collection cannot be blank")
|
65
|
+
# when :attributes
|
66
|
+
when :model
|
67
|
+
next if value.present?
|
68
|
+
|
69
|
+
raise_args_error("Model cannot be deduced")
|
70
|
+
when :actions
|
71
|
+
next if (value - INDEX_ACTIONS).blank?
|
72
|
+
|
73
|
+
raise_args_error("Uknown index action supplied")
|
74
|
+
# when :namespace
|
75
|
+
end
|
65
76
|
end
|
66
77
|
end
|
67
|
-
|
78
|
+
|
79
|
+
def raise_arg_error(message)
|
80
|
+
raise ArgumentError, message
|
81
|
+
end
|
82
|
+
end
|
68
83
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lasha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lasha Abulashvili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sassc-rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|