lasha 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -5
  3. data/lib/lasha/version.rb +1 -1
  4. data/lib/lasha.rb +68 -53
  5. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e129bf80b045a8204652ab9563b6b5013d79085076e1aa7b2d136c0fd195f348
4
- data.tar.gz: 5ebe50a6e11ceedda1f557f2cc628c3e341c0ebafe167fdbe89792be0367a4a3
3
+ metadata.gz: cb44bec536c98c3f3d09775fce58d7137191d6dcd82dc76021cad122d60b3a5c
4
+ data.tar.gz: 5eaef9a2d71a073a75246e822952b87304ad966284b20d2ecd601db90892286c
5
5
  SHA512:
6
- metadata.gz: d05c0043757063688ef52ad80b4afdd50cbec8de3738e3cd1841d1edfba2555a6dbb8dde67378f0074a81562bcc67afb3c6fc189e5aff859bc7b472eb6e4bae1
7
- data.tar.gz: e3be2b56c4c34639c061f1dca1dcca0ce0e8ad953938ab56efedef2a5f3c9d0f22f3230404293168e6b0b353dc1fb5693501dd2191445085083332a552e951fd
6
+ metadata.gz: 0132c6f43a77cafa2357684186f0d828e99fa4efe661216d740ab561aca3c4bd9d867c551b3f750a0f23c39a0908325788e427ce47efac8ff73ba07e653f1125
7
+ data.tar.gz: 6111476ee63ce4f814aa7bbc9d9ad2d5bc3b12ff9e96f8a7f602d78762ecc11f71a05d71c3abe2c718db702fde34be4b6e8911c37e97e830f0ac28e7ff746da5
data/README.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Lasha
2
- Short description and motivation.
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: TxFee, # optional
11
- collection: TxFee.all.order(created_at: :desc).limit(20),
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 'lasha'
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.4.gem
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
@@ -1,3 +1,3 @@
1
1
  module Lasha
2
- VERSION = "0.2.7"
2
+ VERSION = "0.3.0"
3
3
  end
data/lib/lasha.rb CHANGED
@@ -1,68 +1,83 @@
1
1
  require "lasha/engine"
2
2
 
3
3
  module Lasha
4
- @index_actions = %i[new show edit destroy]
4
+ INDEX_ACTIONS = %i[new show edit destroy]
5
5
 
6
- def self.index_data(
7
- controller:,
8
- namespace: nil,
9
- model: nil,
10
- actions: nil,
11
- collection:,
12
- attributes:
13
- )
14
- index_data_hash = {
15
- namespace: set_or_guess_namespace(namespace, controller),
16
- model: set_or_guess_model(model, collection),
17
- collection: collection,
18
- attributes: attributes,
19
- actions: set_or_guess_actions(actions, controller)
20
- }
21
- raise ArgumentError unless index_data_valid?(**index_data_hash)
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
- index_data_hash
24
- rescue ArgumentError => e
25
- puts "***** index_data argument error report"
26
- puts "#{e} #{e.message}"
27
- puts e.backtrace
28
- end
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
- private
32
+ private
31
33
 
32
- def self.set_or_guess_namespace(namespace, controller)
33
- if namespace.present?
34
- namespace
35
- elsif controller.class.name.include?("::")
36
- controller.class.name.deconstantize.underscore.to_sym
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
- def self.set_or_guess_model(model, collection)
41
- model.present? ? model : collection.first.class
42
- end
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
- def self.set_or_guess_actions(actions, controller)
45
- if actions.present?
46
- actions
47
- else
48
- controller.action_methods.to_a.map(&:to_sym) & @index_actions
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
- def self.index_data_valid?(**index_data_hash)
53
- index_data_hash.each do |key, value|
54
- case key
55
- when :model
56
- (value.present? || index_data_hash[:collection].present?)
57
- when :actions
58
- (value - @index_actions).blank?
59
- # when :namespace
60
- # truthy_array << false
61
- # when :collection
62
- # truthy_array << false
63
- # when :attributes
64
- # truthy_array << false
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
- end
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.2.7
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-07-31 00:00:00.000000000 Z
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: 5.2.3
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: 5.2.3
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sassc-rails
29
29
  requirement: !ruby/object:Gem::Requirement