essay 1.0.4 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf366521203e669fbe983484c66fa8c90ada19f7
4
- data.tar.gz: 7cf65ba5cc3e47c09ead5bb408422e558391125f
3
+ metadata.gz: afa4aa60e26f51a5545b57b7b0ad99e5088597a8
4
+ data.tar.gz: ee869072166075fe1a224378997d9efdf6f9a06f
5
5
  SHA512:
6
- metadata.gz: 717c01be8ac2546beaf0b4718292fe897d84d24acb1c8f999443b3ca6ca74cae6d562e2e9f2d502e0affebc6efe0bc15f0e7ba683479a89cc37fb5afff56490d
7
- data.tar.gz: 9ef1b952345a08f0dd1b795fe8a02d507c0573d2f64d24ae9d9337e9524a91f41d9ef60ee1e6818c98c5f98bded485df5b7bd29c18575db01463747e9b137f4f
6
+ metadata.gz: cb8a0a69b4a11e3298b773a46aae74474fbebef2362d43488fc7d0698d31966f175a67ab21f89623d06ce6c971f75b14fdfb309bc275dd087e9a1de7801cab67
7
+ data.tar.gz: 79a89ab38c33abf43732266128c3b4368e53a98741814abf16c026aeca31e44796a6ef87f5df35583aa1b622cf76b59053761148622390b5e5ebe4f0b3a575a0
@@ -19,21 +19,17 @@ require 'essay/association/base_feature'
19
19
  class ActiveRecord::Base
20
20
  class << self
21
21
  def features
22
- @features_for_model ||= Essay::ModelFeatures.new(model_class: self)
22
+ @model_features ||= Essay::ModelFeatures.new(active_record: self)
23
23
  end
24
24
 
25
- def attribute_features(attr_name = nil)
26
- @features_for_attrs ||= Essay::AttributeCollection.new(model_class: self)
27
- attr_name ? @features_for_attrs[attr_name] : @features_for_attrs
25
+ def attribute_features(attribute = nil)
26
+ @attributes_features ||= Essay::AttributeCollection.new(active_record: self)
27
+ attribute ? @attributes_features[attribute] : @attributes_features
28
28
  end
29
29
 
30
- def association_features(assoc_name = nil)
31
- @features_for_assocs ||= Essay::AssociationCollection.new(model_class: self)
32
- assoc_name ? @features_for_assocs[assoc_name] : @features_for_assocs
33
- end
34
-
35
- def essay_for(attr_or_assoc)
36
- raise NotImplmentedError
30
+ def association_features(association = nil)
31
+ @associations_features ||= Essay::AssociationCollection.new(active_record: self)
32
+ association ? @associations_features[association] : @associations_features
37
33
  end
38
34
  end
39
35
  end
@@ -7,18 +7,16 @@ module Essay
7
7
  class AbstractCollection
8
8
  include ModelHelper
9
9
 
10
+ attr_reader :env
11
+
10
12
  def initialize(env)
11
- @env = env
12
- @model_class = env.fetch(:model_class)
13
- @features_for = {}
13
+ @env = env
14
+ @active_record = env.fetch(:active_record)
15
+ @features_for = {}
14
16
  end
15
17
 
16
18
  def [](name)
17
- @features_for[convert_key(name)] ||= construct_features(name)
18
- end
19
-
20
- def load_contents
21
-
19
+ @features_for[name.to_sym] ||= construct_features(name)
22
20
  end
23
21
 
24
22
  def to_hash
@@ -29,11 +27,7 @@ module Essay
29
27
 
30
28
  protected
31
29
  def construct_features(name)
32
-
33
- end
34
-
35
- def convert_key(key)
36
- key.kind_of?(Symbol) ? key : key.to_sym
30
+ raise NotImplementedError
37
31
  end
38
32
  end
39
33
  end
@@ -3,17 +3,17 @@
3
3
 
4
4
  require 'essay/helpers/model_helper'
5
5
  require 'essay/helpers/serialize_helper'
6
- require 'essay/helpers/description_helper'
7
6
 
8
7
  module Essay
9
8
  class AbstractFeature
10
9
  include ModelHelper
11
10
  include SerializeHelper
12
- include DescriptionHelper
11
+
12
+ attr_reader :env
13
13
 
14
14
  def initialize(env)
15
- @env = env
16
- @model_class = env.fetch(:model_class)
15
+ @env = env
16
+ @active_record = env.fetch(:active_record)
17
17
  end
18
18
  end
19
19
  end
@@ -14,8 +14,8 @@ module Essay
14
14
  attr_reader :env
15
15
 
16
16
  def initialize(env)
17
- @env = env
18
- @model_class = env.fetch(:model_class)
17
+ @env = env
18
+ @active_record = env.fetch(:active_record)
19
19
  end
20
20
  end
21
21
  end
@@ -5,8 +5,8 @@ require 'essay/abstract_collection'
5
5
 
6
6
  module Essay
7
7
  class AssociationCollection < AbstractCollection
8
- def construct_features(assoc_name)
9
- Essay::AssociationFeatures.new(@env.merge(association_name: assoc_name))
8
+ def construct_features(name)
9
+ Essay::AssociationFeatures.new(env.merge(association: traits.associations.fetch(name)))
10
10
  end
11
11
 
12
12
  protected :construct_features
@@ -2,15 +2,15 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'essay/abstract_features'
5
- require 'essay/helpers/association_helper'
6
5
 
7
6
  module Essay
8
7
  class AssociationFeatures < AbstractFeatures
9
- include AssociationHelper
8
+ attr_reader :association
9
+ alias this_association association
10
10
 
11
11
  def initialize(env)
12
12
  super
13
- @association_name = env.fetch(:association_name)
13
+ @association = env.fetch(:association)
14
14
  end
15
15
  end
16
16
  end
@@ -2,15 +2,15 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'essay/abstract_feature'
5
- require 'essay/helpers/association_helper'
6
5
 
7
6
  module Essay
8
7
  class AssociationFeatures::Base < AbstractFeature
9
- include AssociationHelper
8
+ attr_reader :association
9
+ alias this_association association
10
10
 
11
11
  def initialize(env)
12
12
  super
13
- @association_name = env.fetch(:association_name)
13
+ @association = env.fetch(:association)
14
14
  end
15
15
  end
16
16
  end
@@ -5,8 +5,8 @@ require 'essay/abstract_collection'
5
5
 
6
6
  module Essay
7
7
  class AttributeCollection < AbstractCollection
8
- def construct_features(attr_name)
9
- Essay::AttributeFeatures.new(@env.merge(attribute_name: attr_name))
8
+ def construct_features(name)
9
+ Essay::AttributeFeatures.new(env.merge(attribute: traits.attributes.fetch(name)))
10
10
  end
11
11
 
12
12
  protected :construct_features
@@ -2,15 +2,15 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'essay/abstract_features'
5
- require 'essay/helpers/attribute_helper'
6
5
 
7
6
  module Essay
8
7
  class AttributeFeatures < AbstractFeatures
9
- include AttributeHelper
8
+ attr_reader :attribute
9
+ alias this_attribute attribute
10
10
 
11
11
  def initialize(env)
12
12
  super
13
- @attribute_name = env.fetch(:attribute_name)
13
+ @attribute = env.fetch(:attribute)
14
14
  end
15
15
  end
16
16
  end
@@ -2,15 +2,15 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'essay/abstract_feature'
5
- require 'essay/helpers/attribute_helper'
6
5
 
7
6
  module Essay
8
7
  class AttributeFeatures::Base < AbstractFeature
9
- include AttributeHelper
8
+ attr_reader :attribute
9
+ alias this_attribute attribute
10
10
 
11
11
  def initialize(env)
12
12
  super
13
- @attribute_name = env.fetch(:attribute_name)
13
+ @attribute = env.fetch(:attribute)
14
14
  end
15
15
  end
16
16
  end
@@ -3,28 +3,28 @@
3
3
 
4
4
  module Essay
5
5
  module ModelHelper
6
- def model_class
7
- @model_class
6
+ def active_record
7
+ @active_record
8
8
  end
9
9
 
10
- def model_traits
11
- model_class.traits
10
+ def traits
11
+ active_record.traits
12
12
  end
13
13
 
14
- def model_associations
15
- model_traits.associations
14
+ def active_record_traits
15
+ traits
16
16
  end
17
17
 
18
- alias all_associations model_associations
19
-
20
- def model_attributes
21
- model_traits.attributes
18
+ def active_record_attributes
19
+ traits.attributes
22
20
  end
23
21
 
24
- alias all_attributes model_attributes
22
+ def active_record_associations
23
+ traits.associations
24
+ end
25
25
 
26
- def model_features
27
- model_class.features
26
+ def active_record_features
27
+ traits.features
28
28
  end
29
29
  end
30
30
  end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Essay
5
- VERSION = '1.0.4'
5
+ VERSION = '1.1.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: essay
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yaroslav Konoplov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-21 00:00:00.000000000 Z
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -86,9 +86,6 @@ files:
86
86
  - lib/essay/attribute/attribute_collection.rb
87
87
  - lib/essay/attribute/attribute_features.rb
88
88
  - lib/essay/attribute/base_feature.rb
89
- - lib/essay/helpers/association_helper.rb
90
- - lib/essay/helpers/attribute_helper.rb
91
- - lib/essay/helpers/description_helper.rb
92
89
  - lib/essay/helpers/feature_helper.rb
93
90
  - lib/essay/helpers/model_helper.rb
94
91
  - lib/essay/helpers/serialize_helper.rb
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module Essay
5
- module AssociationHelper
6
- def association_name
7
- @association_name
8
- end
9
-
10
- def association_traits
11
- model_traits.associations[association_name]
12
- end
13
-
14
- alias association association_traits
15
- alias this_association association
16
- end
17
- end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module Essay
5
- module AttributeHelper
6
- def attribute_name
7
- @attribute_name
8
- end
9
-
10
- def attribute_traits
11
- model_traits.attributes[attribute_name]
12
- end
13
-
14
- alias attribute attribute_traits
15
- alias this_attribute attribute
16
- end
17
- end
@@ -1,18 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module Essay
5
- module DescriptionHelper
6
- extend ActiveSupport::Concern
7
-
8
- included do
9
- class_attribute :description, instance_predicate: false, instance_writer: false
10
- end
11
-
12
- module ClassMethods
13
- def describe(description)
14
- self.description = description
15
- end
16
- end
17
- end
18
- end