rails_stuff 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65e05ba6c678beac4cb3ffe9b343451f18e04b0f
4
- data.tar.gz: 15bcb1d1b7512b366a33ba672c0b79ab9cc3161a
3
+ metadata.gz: b4d05c4a1131bbc5cf6e653451d50aa7f09a2902
4
+ data.tar.gz: 7463af96e7f8c64b3399fb6ce6e9c701b852533a
5
5
  SHA512:
6
- metadata.gz: 5a7094c08403ab00894951527b8652d66d9ac841e95834daab95d1e9ec4fe131aab178b52aa91c8d363789cba98a9c922a88da9108dcf37d55ff8efc4f3b785c
7
- data.tar.gz: fc876d2f0ae219d76109e91450e93cef8474ea22ab40f4eeea0a65da1732c86d21f8047e1b718d1c6baf92b089e811b7352250cbc4c838af45b1cc27821865e4
6
+ metadata.gz: 51871432200910ce3c7e71f4cad3f4112a87c5ddba4bae34a773b179192333e6e1ace524337f8ae23fc9a22d51eaf03c3efca4b202e019f55cb2d294c6c0770e
7
+ data.tar.gz: 439fa7ded29c96cf88db521c40c6a60039d8f6db7e74fe961cbebe97c9e907f9e8f875ec5369eb1abba3e0d1f5de6ec04f4298c7943e5b0f709814769a3c6660
data/.rubocop.yml CHANGED
@@ -19,6 +19,6 @@ Style/SignalException: {EnforcedStyle: only_raise}
19
19
  Style/SpaceInsideHashLiteralBraces: {EnforcedStyle: no_space}
20
20
  Style/TrailingComma: {Enabled: false}
21
21
 
22
- Metrics/AbcSize: {Max: 19}
22
+ Metrics/AbcSize: {Max: 21}
23
23
  Metrics/LineLength: {Max: 100}
24
24
  Metrics/MethodLength: {Max: 30}
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.4.0
2
+
3
+ - TypesTracker defines scopes for every type.
4
+
1
5
  ## 0.3.0
2
6
 
3
7
  - PluginManager & media queries.
data/Gemfile CHANGED
@@ -4,6 +4,7 @@ gemspec
4
4
  group :development do
5
5
  gem 'sdoc', '~> 0.4.1'
6
6
  gem 'pry', '~> 0.10.1'
7
+ gem 'pry-byebug', '~> 3.2.0'
7
8
 
8
9
  gem 'sqlite3', '~> 1.3.10'
9
10
  gem 'database_cleaner', '~> 1.5.0'
data/README.md CHANGED
@@ -258,6 +258,9 @@ class Project::External < Project::Big; end
258
258
  class Project::Small < Project; end
259
259
 
260
260
  Project.types_list # [Internal, External, Small]
261
+
262
+ # Scopes for each type:
263
+ Project.internal or Project.big
261
264
  ```
262
265
 
263
266
  ### ParamsParser
@@ -37,9 +37,11 @@ module RailsStuff
37
37
  msg = f.object.errors[:base].first
38
38
  html << content_tag(:div, msg, class: 'alert alert-danger') if msg
39
39
  html << capture { yield(f) }
40
- html << f.button(:submit, class: 'btn-primary')
41
- html << ' '
42
- html << link_to(translate_action(:cancel), back_url, class: :btn)
40
+ html << content_tag(:div, class: 'form-group') do
41
+ inputs = f.button(:submit, class: 'btn-primary')
42
+ inputs << ' '
43
+ inputs << link_to(translate_action(:cancel), back_url, class: :btn)
44
+ end
43
45
  end
44
46
  end
45
47
  RUBY
@@ -11,6 +11,7 @@ module RailsStuff
11
11
  def extended(base)
12
12
  base.class_attribute :types_list, instance_accessor: false
13
13
  base.types_list = types_list_class.new
14
+ base.instance_variable_set(:@_types_tracker_base, base)
14
15
  end
15
16
 
16
17
  # Class for `types_list`. Default to `Array`. You can override it
@@ -21,16 +22,22 @@ module RailsStuff
21
22
 
22
23
  self.types_list_class = Array
23
24
 
24
- # Add `self` to `types_list`.
25
+ # Add `self` to `types_list`. Defines scope for ActiveRecord models.
25
26
  def register_type(*args)
26
27
  if types_list.respond_to?(:add)
27
28
  types_list.add self, *args
28
29
  else
29
30
  types_list << self
30
31
  end
32
+ if types_tracker_base.respond_to?(:scope) && # rubocop:disable GuardClause
33
+ !types_tracker_base.respond_to?(model_name.element)
34
+ type_name = name
35
+ types_tracker_base.scope model_name.element, -> { where(type: type_name) }
36
+ end
31
37
  end
32
38
 
33
- # Remove `self` from `types_list`.
39
+ # Remove `self` from `types_list`. It doesnt remove generated scope
40
+ # from ActiveRecord models, 'cause it potentialy can remove other methods.
34
41
  def unregister_type
35
42
  types_list.delete self
36
43
  end
@@ -46,5 +53,10 @@ module RailsStuff
46
53
  super
47
54
  base.register_type
48
55
  end
56
+
57
+ # Class that was initilly extended with TypesTracker.
58
+ def types_tracker_base
59
+ @_types_tracker_base || superclass.types_tracker_base
60
+ end
49
61
  end
50
62
  end
@@ -5,7 +5,7 @@ module RailsStuff
5
5
 
6
6
  module VERSION #:nodoc:
7
7
  MAJOR = 0
8
- MINOR = 3
8
+ MINOR = 4
9
9
  TINY = 0
10
10
  PRE = nil
11
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_stuff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Melentiev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-21 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -129,3 +129,4 @@ signing_key:
129
129
  specification_version: 4
130
130
  summary: Collection of useful modules for Rails
131
131
  test_files: []
132
+ has_rdoc: