hexx 7.1.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +9 -0
  4. data/.metrics +5 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +2 -63
  7. data/.travis.yml +5 -0
  8. data/.yardopts +2 -0
  9. data/Gemfile +3 -0
  10. data/Guardfile +16 -0
  11. data/{LICENSE.rdoc → LICENSE} +2 -2
  12. data/README.md +138 -0
  13. data/Rakefile +8 -14
  14. data/config/initializer.rb +5 -0
  15. data/config/initializers/capture.rb +19 -0
  16. data/config/initializers/sandbox.rb +16 -0
  17. data/config/initializers/sandbox/helpers.rb +38 -0
  18. data/config/initializers/sandbox/matchers.rb +19 -0
  19. data/config/metrics/STYLEGUIDE +230 -0
  20. data/config/metrics/cane.yml +5 -0
  21. data/config/metrics/churn.yml +6 -0
  22. data/config/metrics/flay.yml +2 -0
  23. data/config/metrics/metric_fu.yml +15 -0
  24. data/config/metrics/pippi.yml +3 -0
  25. data/config/metrics/reek.yml +1 -0
  26. data/config/metrics/roodi.yml +24 -0
  27. data/config/metrics/rubocop.yml +79 -0
  28. data/config/metrics/saikuro.yml +3 -0
  29. data/config/metrics/simplecov.yml +6 -0
  30. data/config/metrics/yardstick.yml +37 -0
  31. data/hexx.gemspec +24 -0
  32. data/lib/hexx.rb +8 -15
  33. data/lib/hexx/generator.rb +71 -0
  34. data/lib/hexx/generator/file.rb +83 -0
  35. data/lib/hexx/generator/folder.rb +68 -0
  36. data/lib/hexx/name.rb +122 -46
  37. data/lib/hexx/version.rb +6 -5
  38. data/spec/fixtures/root/_.beta +1 -0
  39. data/spec/fixtures/root/__omega +0 -0
  40. data/spec/fixtures/root/delta.erb.erb +0 -0
  41. data/spec/fixtures/root/gamma.rb.erb +1 -0
  42. data/spec/fixtures/root/subfolder/alfa.yml +0 -0
  43. data/spec/spec_helper.rb +5 -10
  44. data/spec/tests/lib/generator_spec.rb +126 -0
  45. data/spec/tests/lib/name_spec.rb +113 -0
  46. metadata +54 -168
  47. data/README.rdoc +0 -371
  48. data/lib/hexx/coercible.rb +0 -43
  49. data/lib/hexx/configurable.rb +0 -101
  50. data/lib/hexx/creators/base.rb +0 -103
  51. data/lib/hexx/creators/coercion.rb +0 -82
  52. data/lib/hexx/creators/dependency.rb +0 -87
  53. data/lib/hexx/creators/module_dependency.rb +0 -57
  54. data/lib/hexx/creators/parameter.rb +0 -40
  55. data/lib/hexx/dependable.rb +0 -51
  56. data/lib/hexx/helpers/exceptions.rb +0 -53
  57. data/lib/hexx/helpers/messages.rb +0 -26
  58. data/lib/hexx/helpers/parameters.rb +0 -47
  59. data/lib/hexx/helpers/validations.rb +0 -21
  60. data/lib/hexx/message.rb +0 -79
  61. data/lib/hexx/null.rb +0 -218
  62. data/lib/hexx/service.rb +0 -388
  63. data/lib/hexx/service/with_callbacks.rb +0 -104
  64. data/lib/hexx/service_invalid.rb +0 -73
  65. data/spec/hexx/coercible_spec.rb +0 -72
  66. data/spec/hexx/configurable_spec.rb +0 -93
  67. data/spec/hexx/dependable_spec.rb +0 -125
  68. data/spec/hexx/helpers/exceptions_spec.rb +0 -96
  69. data/spec/hexx/helpers/messages_spec.rb +0 -48
  70. data/spec/hexx/helpers/parameters_spec.rb +0 -96
  71. data/spec/hexx/helpers/validations_spec.rb +0 -32
  72. data/spec/hexx/message_spec.rb +0 -83
  73. data/spec/hexx/name_spec.rb +0 -80
  74. data/spec/hexx/null_spec.rb +0 -152
  75. data/spec/hexx/service_invalid_spec.rb +0 -46
  76. data/spec/hexx/service_spec.rb +0 -89
  77. data/spec/support/initializers/focus.rb +0 -5
  78. data/spec/support/initializers/garbage_collection.rb +0 -11
  79. data/spec/support/initializers/i18n.rb +0 -3
  80. data/spec/support/initializers/random_order.rb +0 -4
  81. data/spec/support/initializers/rspec.rb +0 -5
  82. data/spec/support/matchers/methods.rb +0 -11
@@ -1,72 +1,148 @@
1
1
  # encoding: utf-8
2
- # require "extlib"
2
+ require "extlib"
3
3
 
4
4
  module Hexx
5
5
 
6
+ # Decorates a string with conventional names
6
7
  class Name
7
8
 
8
- # @!attribute [r] object
9
- # The object to be named.
10
- # @return [Object] the object.
11
-
12
- # @!attribute [r] locale
13
- # The locale to be used for naming.
14
- # Equals <tt>I18n.locale</tt> by default.
15
- # @return [Symbol] the locale.
9
+ # @!scope class
10
+ # @!method new(string)
11
+ # Constructs the parser object
12
+ #
13
+ # @example
14
+ # Hexx::Name.new "MyGem::MyClass.methods.chain"
15
+ #
16
+ # @param [#to_s] string
17
+ # The string to be parsed
18
+ #
19
+ # @return [Hexx::Name]
20
+ def initialize(string)
21
+ @list = string.to_s.snake_case.gsub(/\:{2}|-/, "/").split(".")
22
+ end
16
23
 
17
- attr_reader :object, :locale
24
+ # Returns the last part of the singular name
25
+ #
26
+ # @example
27
+ # source = "cats-wildcats/jaguars::PantherTiger.bite"
28
+ # name = Hexx::Name.new(source)
29
+ # name.item
30
+ # # => "panther_tiger"
31
+ #
32
+ # @return [String]
33
+ def item
34
+ @item ||= snakes.last.to_s.singular
35
+ end
18
36
 
19
- # @note The class has a private constructor. Use {.for} method instead.
20
- private_class_method :new
37
+ # Returns the last part of the plural name
38
+ #
39
+ # @example
40
+ # source = "cats-wildcats/jaguars::PantherTiger.bite"
41
+ # name = Hexx::Name.new(source)
42
+ # name.items
43
+ # # => "panther_tigers"
44
+ #
45
+ # @return [String]
46
+ def items
47
+ @items ||= item.plural
48
+ end
21
49
 
22
- # @api hide
23
- # The class instance initializer.
50
+ # Returns the dashes-delimited name
51
+ #
52
+ # @example
53
+ # source = "cats-wildcats/jaguars::PantherTiger.bite"
54
+ # name = Hexx::Name.new(source)
55
+ # name.file
56
+ # # => "cats-wildcats-jaguars-panther_tiger.bite"
24
57
  #
25
- # @param [Object] object The object to be named.
26
- # @param [Symbol] locale The locale to be used for naming.
27
- # @return [Hexx::Name] the class instance.
28
- def initialize(object, locale)
29
- @object, @locale = object, locale
58
+ # @return [String]
59
+ def file
60
+ @file ||= [snakes.join("-"), method].compact.join(".")
30
61
  end
31
62
 
32
- # @abstract
33
- # Returns the name for the current {#object}.
63
+ # Returns the slash-delimited name
34
64
  #
35
- # @return [String] the name.
36
- def for
37
- ""
65
+ # @example
66
+ # source = "cats-wildcats/jaguars::PantherTiger.bite"
67
+ # name = Hexx::Name.new(source)
68
+ # name.path
69
+ # # => "cats/wildcats/jaguars/panther_tiger/bite"
70
+ #
71
+ # @return [String]
72
+ def path
73
+ @path ||= [snakes.join("/"), method].compact.join(".")
38
74
  end
39
75
 
40
- # Constructs the name for given object and locale.
76
+ # Returns the name as a full constant
77
+ #
78
+ # @example
79
+ # source = "cats-wildcats/jaguars::PantherTiger.bite"
80
+ # name = Hexx::Name.new(source)
81
+ # name.type
82
+ # # => "Cats::Wildcats::Jaguars::PantherTiger.bite"
41
83
  #
42
- # @param [Object] object The object to be named.
43
- # @param [Symbol, nil] locale (I18n.locale)
44
- # The locale to be used for naming.
45
- # @return [String] the name.
46
- def self.for(object, locale: I18n.locale)
47
- new(object, locale).for
84
+ # @return [String]
85
+ def type
86
+ @type ||= [camels.join("::"), method].compact.join(".")
48
87
  end
49
88
 
50
- # Translates the value in the current scope and locale.
89
+ # Returns the name as a last part of constant
90
+ #
91
+ # @example
92
+ # source = "cats-wildcats/jaguars::PantherTiger.bite"
93
+ # name = Hexx::Name.new(source)
94
+ # name.const
95
+ # # => "PantherTiger.bite"
51
96
  #
52
- # @param [Symbol, String] value The value to be translated.
53
- # @param [Hash] options ({}) The options for the translation.
54
- # @return [String] The translation.
55
- def t(value, options = {})
56
- return value unless value.is_a? Symbol
57
- I18n.t value, options.merge(locale: locale, scope: scope)
97
+ # @return [String]
98
+ def const
99
+ @const ||= [camels.last, method].compact.join(".")
58
100
  end
59
101
 
60
- # The scope for object translation.
61
- # @return [Array<String, Symbol>] the list of scopes.
62
- def scope
63
- @scope ||= %w(activemodel models) << object_name
102
+ # Returns the array of namespaces (module names) for the constant
103
+ #
104
+ # @example
105
+ # source = "cats-wildcats/jaguars::PantherTiger.bite"
106
+ # name = Hexx::Name.new(source)
107
+ # name.namespaces
108
+ # # => ["Cats", "Wildcats", "Jaguars"]
109
+ #
110
+ # @return [Array<String>]
111
+ def namespaces
112
+ @namespaces ||= camels[0..-2]
64
113
  end
65
114
 
66
115
  private
67
116
 
68
- def object_name
69
- self.class.name.underscore.gsub("::", "/")
117
+ # String of chained methods
118
+ #
119
+ # @return [String]
120
+ # @return [nil]
121
+ # if source has no methods
122
+ #
123
+ # @api private
124
+ def method
125
+ @method ||= @list[1..-1] if @list.count > 1
126
+ end
127
+
128
+ # List of snake-cased parts of the constant
129
+ #
130
+ # @return [Array<String>]
131
+ #
132
+ # @api private
133
+ def snakes
134
+ @snakes ||= @list.first.to_s.split("/")
135
+ end
136
+
137
+ # List of camel-cased parts of the constant
138
+ #
139
+ # @return [Array<String>]
140
+ #
141
+ # @api private
142
+ def camels
143
+ @camels ||= snakes.map(&:camel_case)
70
144
  end
71
- end
72
- end
145
+
146
+ end # class Name
147
+
148
+ end # module Hexx
@@ -1,6 +1,7 @@
1
- # Namespace for the gem.
2
- module Hexx
1
+ # encoding: utf-8
3
2
 
4
- # Current release.
5
- VERSION = "7.1.0"
6
- end
3
+ module Hexx
4
+ # The semantic version of the module.
5
+ # @see http://semver.org/ Semantic versioning 2.0
6
+ VERSION = "8.0.0".freeze
7
+ end # module Hexx
@@ -0,0 +1 @@
1
+ <%= 2 * 2 -%>
File without changes
File without changes
@@ -0,0 +1 @@
1
+ <%= 2 * 2 -%>
File without changes
@@ -1,11 +1,6 @@
1
- require "coveralls"
1
+ # Loads the RSpec test suit.
2
+ require "hexx-suit"
3
+ Hexx::Suit.load_metrics_for(self)
2
4
 
3
- # Application root
4
- root = File.expand_path "../..", __FILE__
5
-
6
- # Support files and Rspec settings
7
- Dir[File.join(root, "spec/support/**/*.rb")].each { |file| require file }
8
-
9
- # Application files
10
- Coveralls.wear!
11
- require File.join(root, "lib/hexx.rb")
5
+ # Loads the gem.
6
+ require "hexx"
@@ -0,0 +1,126 @@
1
+ # encoding: utf-8
2
+
3
+ # See settings for :sandbox and :capture tags in `config/initializers` folder
4
+ describe Hexx::Generator do
5
+
6
+ # source path is set to spec/fixtures
7
+ let(:fixtures) { ::File.expand_path "../../../fixtures", __FILE__ }
8
+ before { allow(described_class).to receive(:source_root).and_return fixtures }
9
+
10
+ describe ".new" do
11
+
12
+ it "constructs Thor::Group instance" do
13
+ expect(subject).to be_kind_of Thor::Group
14
+ end
15
+
16
+ it "constructs Thor::Actions instance" do
17
+ expect(subject).to be_kind_of Thor::Actions
18
+ end
19
+
20
+ end # describe .new
21
+
22
+ describe "##source_root" do
23
+
24
+ it "returns a source root" do
25
+ expect(subject.send :source_root)
26
+ .to eq described_class.send(:source_root)
27
+ end
28
+
29
+ end # describe ##source_root
30
+
31
+ describe "#copy_folder", :sandbox, :capture do
32
+
33
+ shared_examples "copying files" do
34
+
35
+ # target should be described in context
36
+
37
+ it "[copy file as is]" do
38
+ expect("#{ target }/subfolder/alfa.yml").to be_present_in_sandbox
39
+ end
40
+
41
+ end # examples
42
+
43
+ shared_examples "removing last .erb only" do
44
+
45
+ # target should be described in context
46
+
47
+ it "[removes last .erb]" do
48
+ expect("#{ target }/gamma.rb").to be_present_in_sandbox
49
+ end
50
+
51
+ it "[leaves previous .erb]" do
52
+ expect("#{ target }/delta.erb").to be_present_in_sandbox
53
+ end
54
+
55
+ end # examples
56
+
57
+ shared_examples "removing first underscores only" do
58
+
59
+ it "[removes first _]" do
60
+ expect("#{ target }/.beta").to be_present_in_sandbox
61
+ end
62
+
63
+ it "[leaves later _]" do
64
+ expect("#{ target }/_omega").to be_present_in_sandbox
65
+ end
66
+
67
+ end # examples
68
+
69
+ shared_examples "preprocessing ERB only" do
70
+
71
+ # target should be described in context
72
+
73
+ it "[preprocesses erb]" do
74
+ content = read_in_sandbox("#{ target }/gamma.rb")
75
+ expect(content).not_to include "<%= 2 * 2 -%>"
76
+ expect(content).to include "4"
77
+ end
78
+
79
+ it "[leaves non-erb]" do
80
+ content = read_in_sandbox("#{ target }/.beta")
81
+ expect(content).to include "<%= 2 * 2 -%>"
82
+ expect(content).not_to include "4"
83
+ end
84
+
85
+ end # examples
86
+
87
+ context "when the target isn't set" do
88
+
89
+ let(:target) { "root" }
90
+
91
+ before { try_in_sandbox { subject.send :copy_folder, "root" } }
92
+
93
+ it_behaves_like "copying files"
94
+ it_behaves_like "removing last .erb only"
95
+ it_behaves_like "removing first underscores only"
96
+ it_behaves_like "preprocessing ERB only"
97
+
98
+ end # context
99
+
100
+ context "with the target is set" do
101
+
102
+ let(:target) { "spec" }
103
+
104
+ before { try_in_sandbox { subject.send :copy_folder, "root", target } }
105
+
106
+ it_behaves_like "copying files"
107
+ it_behaves_like "removing last .erb only"
108
+ it_behaves_like "removing first underscores only"
109
+ it_behaves_like "preprocessing ERB only"
110
+
111
+ end # context
112
+
113
+ end # describe ##copy_folder
114
+
115
+ describe "#from_template", :sandbox, :capture do
116
+
117
+ let(:content) { subject.send :from_template, "root/_.beta" }
118
+
119
+ it "returns the ERB-preprocessed content of the template" do
120
+ expect(content).not_to include "<%= 2 * 2 -%>"
121
+ expect(content).to include "4"
122
+ end
123
+
124
+ end # describe ##from_template
125
+
126
+ end # describe Hexx::Generator
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+
3
+ describe Hexx::Name do
4
+
5
+ describe ".new" do
6
+
7
+ it "requires an argument" do
8
+ expect { described_class.new }.to raise_error
9
+ expect { described_class.new "" }.not_to raise_error
10
+ expect { described_class.new "", "" }.to raise_error
11
+ end
12
+
13
+ end # describe .new
14
+
15
+ let(:a) { described_class.new nil }
16
+ let(:b) { described_class.new "cats" }
17
+ let(:c) { described_class.new "cats.names" }
18
+ let(:d) { described_class.new "cats-wildcats/jaguars::PantherTiger" }
19
+ let(:e) { described_class.new "cats-wildcats/jaguars::PantherTigers" }
20
+ let(:f) { described_class.new "cats-wildcats/jaguars::PantherTiger.a.B.c" }
21
+
22
+ describe "#item" do
23
+
24
+ it "returns a proper value" do
25
+ expect(a.item).to eq ""
26
+ expect(b.item).to eq "cat"
27
+ expect(c.item).to eq "cat"
28
+ expect(d.item).to eq "panther_tiger"
29
+ expect(e.item).to eq "panther_tiger"
30
+ expect(f.item).to eq "panther_tiger"
31
+ end
32
+
33
+ end # describe #item
34
+
35
+ describe "#items" do
36
+
37
+ it "returns a proper value" do
38
+ expect(a.items).to eq ""
39
+ expect(b.items).to eq "cats"
40
+ expect(c.items).to eq "cats"
41
+ expect(d.items).to eq "panther_tigers"
42
+ expect(e.items).to eq "panther_tigers"
43
+ expect(f.items).to eq "panther_tigers"
44
+ end
45
+
46
+ end # describe #items
47
+
48
+ describe "#file" do
49
+
50
+ it "returns a proper value" do
51
+ expect(a.file).to eq ""
52
+ expect(b.file).to eq "cats"
53
+ expect(c.file).to eq "cats.names"
54
+ expect(d.file).to eq "cats-wildcats-jaguars-panther_tiger"
55
+ expect(e.file).to eq "cats-wildcats-jaguars-panther_tigers"
56
+ expect(f.file).to eq "cats-wildcats-jaguars-panther_tiger.a.b.c"
57
+ end
58
+
59
+ end # describe #file
60
+
61
+ describe "#path" do
62
+
63
+ it "returns a proper value" do
64
+ expect(a.path).to eq ""
65
+ expect(b.path).to eq "cats"
66
+ expect(c.path).to eq "cats.names"
67
+ expect(d.path).to eq "cats/wildcats/jaguars/panther_tiger"
68
+ expect(e.path).to eq "cats/wildcats/jaguars/panther_tigers"
69
+ expect(f.path).to eq "cats/wildcats/jaguars/panther_tiger.a.b.c"
70
+ end
71
+
72
+ end # describe #path
73
+
74
+ describe "#type" do
75
+
76
+ it "returns a proper value" do
77
+ expect(a.type).to eq ""
78
+ expect(b.type).to eq "Cats"
79
+ expect(c.type).to eq "Cats.names"
80
+ expect(d.type).to eq "Cats::Wildcats::Jaguars::PantherTiger"
81
+ expect(e.type).to eq "Cats::Wildcats::Jaguars::PantherTigers"
82
+ expect(f.type).to eq "Cats::Wildcats::Jaguars::PantherTiger.a.b.c"
83
+ end
84
+
85
+ end # describe #type
86
+
87
+ describe "#const" do
88
+
89
+ it "returns a proper value" do
90
+ expect(a.const).to eq ""
91
+ expect(b.const).to eq "Cats"
92
+ expect(c.const).to eq "Cats.names"
93
+ expect(d.const).to eq "PantherTiger"
94
+ expect(e.const).to eq "PantherTigers"
95
+ expect(f.const).to eq "PantherTiger.a.b.c"
96
+ end
97
+
98
+ end # describe #const
99
+
100
+ describe "#namespaces" do
101
+
102
+ it "returns a proper value" do
103
+ expect(a.namespaces).to eq %w()
104
+ expect(b.namespaces).to eq %w()
105
+ expect(c.namespaces).to eq %w()
106
+ expect(d.namespaces).to eq %w(Cats Wildcats Jaguars)
107
+ expect(e.namespaces).to eq %w(Cats Wildcats Jaguars)
108
+ expect(f.namespaces).to eq %w(Cats Wildcats Jaguars)
109
+ end
110
+
111
+ end # describe #namespaces
112
+
113
+ end # describe Hexx::Name