duck_record 0.0.1

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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +59 -0
  4. data/Rakefile +29 -0
  5. data/lib/duck_record/attribute/user_provided_default.rb +30 -0
  6. data/lib/duck_record/attribute.rb +221 -0
  7. data/lib/duck_record/attribute_assignment.rb +91 -0
  8. data/lib/duck_record/attribute_methods/before_type_cast.rb +76 -0
  9. data/lib/duck_record/attribute_methods/dirty.rb +124 -0
  10. data/lib/duck_record/attribute_methods/read.rb +78 -0
  11. data/lib/duck_record/attribute_methods/write.rb +65 -0
  12. data/lib/duck_record/attribute_methods.rb +332 -0
  13. data/lib/duck_record/attribute_mutation_tracker.rb +113 -0
  14. data/lib/duck_record/attribute_set/builder.rb +124 -0
  15. data/lib/duck_record/attribute_set/yaml_encoder.rb +41 -0
  16. data/lib/duck_record/attribute_set.rb +99 -0
  17. data/lib/duck_record/attributes.rb +262 -0
  18. data/lib/duck_record/base.rb +296 -0
  19. data/lib/duck_record/callbacks.rb +324 -0
  20. data/lib/duck_record/core.rb +253 -0
  21. data/lib/duck_record/define_callbacks.rb +23 -0
  22. data/lib/duck_record/errors.rb +44 -0
  23. data/lib/duck_record/inheritance.rb +130 -0
  24. data/lib/duck_record/locale/en.yml +48 -0
  25. data/lib/duck_record/model_schema.rb +64 -0
  26. data/lib/duck_record/serialization.rb +19 -0
  27. data/lib/duck_record/translation.rb +22 -0
  28. data/lib/duck_record/type/array.rb +36 -0
  29. data/lib/duck_record/type/decimal_without_scale.rb +13 -0
  30. data/lib/duck_record/type/internal/abstract_json.rb +33 -0
  31. data/lib/duck_record/type/json.rb +6 -0
  32. data/lib/duck_record/type/registry.rb +97 -0
  33. data/lib/duck_record/type/serialized.rb +63 -0
  34. data/lib/duck_record/type/text.rb +9 -0
  35. data/lib/duck_record/type/unsigned_integer.rb +15 -0
  36. data/lib/duck_record/type.rb +66 -0
  37. data/lib/duck_record/validations.rb +40 -0
  38. data/lib/duck_record/version.rb +3 -0
  39. data/lib/duck_record.rb +47 -0
  40. data/lib/tasks/acts_as_record_tasks.rake +4 -0
  41. metadata +126 -0
@@ -0,0 +1,40 @@
1
+ module DuckRecord
2
+ # = Active Record \Validations
3
+ #
4
+ # Active Record includes the majority of its validations from ActiveModel::Validations
5
+ # all of which accept the <tt>:on</tt> argument to define the context where the
6
+ # validations are active. Active Record will always supply either the context of
7
+ # <tt>:create</tt> or <tt>:update</tt> dependent on whether the model is a
8
+ # {new_record?}[rdoc-ref:Persistence#new_record?].
9
+ module Validations
10
+ extend ActiveSupport::Concern
11
+ include ActiveModel::Validations
12
+
13
+ # Runs all the validations within the specified context. Returns +true+ if
14
+ # no errors are found, +false+ otherwise.
15
+ #
16
+ # Aliased as #validate.
17
+ #
18
+ # If the argument is +false+ (default is +nil+), the context is set to <tt>:default</tt>.
19
+ #
20
+ # \Validations with no <tt>:on</tt> option will run no matter the context. \Validations with
21
+ # some <tt>:on</tt> option will only run in the specified context.
22
+ def valid?(context = nil)
23
+ context ||= default_validation_context
24
+ output = super(context)
25
+ errors.empty? && output
26
+ end
27
+
28
+ alias_method :validate, :valid?
29
+
30
+ private
31
+
32
+ def default_validation_context
33
+ :default
34
+ end
35
+
36
+ def perform_validations(options = {})
37
+ options[:validate] == false || valid?(options[:context])
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module DuckRecord
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,47 @@
1
+ require 'active_support'
2
+ require 'active_support/rails'
3
+ require 'active_model'
4
+
5
+ require 'duck_record/type'
6
+ require 'duck_record/attribute_set'
7
+
8
+ module DuckRecord
9
+ extend ActiveSupport::Autoload
10
+
11
+ autoload :Attribute
12
+ autoload :Base
13
+ autoload :Callbacks
14
+ autoload :Core
15
+ autoload :Inheritance
16
+ autoload :ModelSchema
17
+ autoload :Serialization
18
+ autoload :Translation
19
+ autoload :Validations
20
+
21
+ eager_autoload do
22
+ autoload :DuckRecordError, 'duck_record/errors'
23
+
24
+ autoload :AttributeAssignment
25
+ autoload :AttributeMethods
26
+ end
27
+
28
+ module AttributeMethods
29
+ extend ActiveSupport::Autoload
30
+
31
+ eager_autoload do
32
+ autoload :BeforeTypeCast
33
+ autoload :Dirty
34
+ autoload :Read
35
+ autoload :Write
36
+ end
37
+ end
38
+
39
+ def self.eager_load!
40
+ super
41
+ ActiveRecord::AttributeMethods.eager_load!
42
+ end
43
+ end
44
+
45
+ # ActiveSupport.on_load(:i18n) do
46
+ # I18n.load_path << File.dirname(__FILE__) + '/duck_record/locale/en.yml'
47
+ # end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :duck_record do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: duck_record
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - jasl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: "It looks like Active Record and quacks like Active Record, it's Duck
56
+ Record! \n Actually it's extract from Active Record."
57
+ email:
58
+ - jasl9187@hotmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/duck_record.rb
67
+ - lib/duck_record/attribute.rb
68
+ - lib/duck_record/attribute/user_provided_default.rb
69
+ - lib/duck_record/attribute_assignment.rb
70
+ - lib/duck_record/attribute_methods.rb
71
+ - lib/duck_record/attribute_methods/before_type_cast.rb
72
+ - lib/duck_record/attribute_methods/dirty.rb
73
+ - lib/duck_record/attribute_methods/read.rb
74
+ - lib/duck_record/attribute_methods/write.rb
75
+ - lib/duck_record/attribute_mutation_tracker.rb
76
+ - lib/duck_record/attribute_set.rb
77
+ - lib/duck_record/attribute_set/builder.rb
78
+ - lib/duck_record/attribute_set/yaml_encoder.rb
79
+ - lib/duck_record/attributes.rb
80
+ - lib/duck_record/base.rb
81
+ - lib/duck_record/callbacks.rb
82
+ - lib/duck_record/core.rb
83
+ - lib/duck_record/define_callbacks.rb
84
+ - lib/duck_record/errors.rb
85
+ - lib/duck_record/inheritance.rb
86
+ - lib/duck_record/locale/en.yml
87
+ - lib/duck_record/model_schema.rb
88
+ - lib/duck_record/serialization.rb
89
+ - lib/duck_record/translation.rb
90
+ - lib/duck_record/type.rb
91
+ - lib/duck_record/type/array.rb
92
+ - lib/duck_record/type/decimal_without_scale.rb
93
+ - lib/duck_record/type/internal/abstract_json.rb
94
+ - lib/duck_record/type/json.rb
95
+ - lib/duck_record/type/registry.rb
96
+ - lib/duck_record/type/serialized.rb
97
+ - lib/duck_record/type/text.rb
98
+ - lib/duck_record/type/unsigned_integer.rb
99
+ - lib/duck_record/validations.rb
100
+ - lib/duck_record/version.rb
101
+ - lib/tasks/acts_as_record_tasks.rake
102
+ homepage: https://github.com/jasl/duck_record
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 2.2.2
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.6.10
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Active Record without persistence
126
+ test_files: []