intrinsic 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,25 @@
1
+ 1.1.0 / 2012-01-08
2
+ ==================
3
+
4
+ * Adding TODO's and bugs to fix
5
+ * Documenting the check_properties_of method
6
+ * Documenting the redefine of the to_s method
7
+ * Documenting the initialize method provided to objects
8
+ * Detailing the internals of the included hook
9
+ * Documenting the included hook
10
+ * Documenting details about the intrinsic model
11
+ * ADding an example of usage from the sample file
12
+ * ADding a list of pros and cons for Virtus
13
+ * Adding a list of pros and cons for activemodel
14
+ * Adding a section on alternatives
15
+ * Adding in the two people who deserve credit the most
16
+ * Updating the gem version
17
+ * Adding chainable syntax detail
18
+ * Extrapolating on idea
19
+ * Adding code markup
20
+ * Adding code markup
21
+
22
+
1
23
  1.0.3 / 2012-01-08
2
24
  ==================
3
25
 
data/README.md CHANGED
@@ -7,21 +7,71 @@ The intrinsic gem is for giving your objects typed attributes, defaults, and val
7
7
  usage
8
8
  -----
9
9
 
10
- Using the intrinsic library is pretty simple.
10
+ Using the intrinsic library is pretty simple and it works much like [ActiveModel](https://github.com/rails/rails/tree/master/activemodel) or [Virtus](https://github.com/solnic/virtus).
11
11
  The basic features are:
12
12
 
13
- - Getters & Setters for named properties (similar to attr_accessor)
14
- - Default values, both in regular and Proc (ie callable lambda) form
15
- - Easy API for dumping object attributes (similar to ostruct)
13
+ - Getters & Setters for named properties (similar to `attr_accessor`)
14
+ - Default values, both in regular and Proc (ie callable `lambda`) form
15
+ - Easy API for dumping object attributes (similar to `ostruct`)
16
16
  - Type and Argument errors for incorrectly supplied properties
17
17
  - Type coercion for attributes, as well as easily defininable new types
18
18
 
19
19
 
20
20
  In addition you get these cool features:
21
21
 
22
- - Validate your properties with simple boolean logic, no complex Validator classes!
23
- - Get errors when your validations don't work (simple errors for now)
24
- -
22
+ - Validate your properties with simple boolean logic, no complex `Validator` classes!
23
+ - Simple error messages when your validations don't work (basic strings for now)
24
+ - Chainable syntax for property setting: `Person.new.name("Kurtis").age(24)`
25
+
26
+
27
+ Here's an example of a Class modified by intrinsic:
28
+
29
+ ``` ruby
30
+ require 'intrinsic'
31
+
32
+ class Person
33
+ include Intrinsic
34
+ include Intrinsic::Intrinsicism::Validation
35
+
36
+ property :name
37
+ property :email
38
+ property :age, Integer, default: 13
39
+
40
+ validation_for :name { name.match /\w/ }
41
+ validation_for :age { (13..100).include? age }
42
+ validation_for :email { email.count('@') == 1 and (5..256).include? email.length }
43
+ end
44
+
45
+ person = Person.new name: "Kurtis" # => #<Person:2152879000 name="Kurtis", email=nil, age=13>
46
+ person.name("Hurly Burly").age("34") # => #<Person:2153464580 name="Hurly Burly", age=34>
47
+ person.name # => "Hurly Burly"
48
+ person.is_valid? # => false
49
+ person.errors # => ["email is not valid"]
50
+ ```
51
+
52
+
53
+ **Alternatives**
54
+
55
+ You may have noticed some alternative gems out there!
56
+ This is great, because it gives you a keen eye on how to make intrinsic better.
57
+ Here's a list of what those alternatives are and why I think Intrinsic should exist:
58
+
59
+ * *ActiveModel*
60
+ - **Pro**: Extremely large community and support over intrinsic
61
+ - Pro: Well tested, documented, and designed
62
+ - Pro: Continually worked on by many
63
+ - **Con**: Large and bulky, with far too many tools in the toolbox
64
+ - Con: Always tied to Rails
65
+ - Con: Complex inner workings for even simple things
66
+ * *Virtus*
67
+ - **Pro**: Well maintained and contributed too.
68
+ - Pro: Extremely well tested and documented
69
+ - Pro: Extended feature set above and beyond intrinsic
70
+ - **Con**: Always tied to DataMapper
71
+ - Con: Still not version 1.0.0, and thus has an unstable API
72
+ - Con: No validation system planned or in feature set
73
+
74
+ All of these alternatives are worth looking into!
25
75
 
26
76
 
27
77
  installing
@@ -43,7 +93,7 @@ Or add it to your `Gemfile`:
43
93
  ``` ruby
44
94
  source :rubygems
45
95
 
46
- gem "intrinsic", "1.0.1"
96
+ gem "intrinsic", "1.1.0"
47
97
  ```
48
98
 
49
99
  That's all you have to do.
@@ -70,8 +120,8 @@ We welcome any pull requests or commits that improve `intrinsic`.
70
120
  changelog
71
121
  ---------
72
122
 
73
- - 1.0.3:
74
- * Adding helpful README and license, updating example script
123
+ - 1.1.0: Documentation of the intrinsic module, updating of readme details
124
+ - 1.0.3: Adding helpful README and license, updating example script
75
125
  - 1.0.0: Initial release
76
126
 
77
127
 
@@ -96,15 +146,14 @@ contributing
96
146
  Credits
97
147
  -------
98
148
 
99
- - []()
100
- - []()
101
- - []()
149
+ - [Piotr Solnica](https://github.com/solnic) for starting [Virtus](https://github.com/solnic/virtus) and inspiring me to build my own version of the concept.
150
+ - [Yehuda Katz](https://github.com/wycats) for pulling out [ActiveModel](https://github.com/rails/rails/tree/master/activemodel), thus inspiring me to work on my own.
102
151
 
103
152
 
104
153
  License
105
154
  -------
106
155
 
107
- Copyright (c) 2011 Kurtis Rainbolt-Greene
156
+ Copyright (c) 2012 Kurtis Rainbolt-Greene
108
157
 
109
158
  Permission is hereby granted, free of charge, to any person obtaining
110
159
  a copy of this software and associated documentation files (the
@@ -2,27 +2,62 @@ require 'intrinsic/version'
2
2
  require 'intrinsic/intrinsicism'
3
3
  require 'intrinsic/extrinsicism'
4
4
 
5
+ # The Intrinsic model is the gateway to all the sub models, and by including
6
+ # it into a model or class you gain all of the power of the library
5
7
  module Intrinsic
8
+
9
+ # Defines a hooks onto `include` so that the subject is also extended with the model
10
+ # meaning that singleton and instance methods exist on the class and instance
11
+ # of the class.
6
12
  def self.included(subject)
13
+ # Make a call to the superclass original included method
7
14
  super
15
+ # Extend the class with the model to get the singleton methods
8
16
  subject.extend Intrinsicism
17
+ # Send the include method with the model as an argument
18
+ # TODO: Find out if this is needed?
9
19
  subject.send :include, Intrinsicism
10
20
  end
11
21
 
22
+ # Defines the initialize method that takes a hash and sets the properties
23
+ # to those values. It also takes the defaults and assigns them to the properties.
24
+ # TODO: Rename the parameter to something else, like `initial_properties`
25
+ # TODO: Make sure all the keys are symbols, or at least turn them into symbols
12
26
  def initialize(values = {})
27
+ # Create a new empty table for the properties, and then merge in the defaults
28
+ # TODO: Make defaults a class variable
13
29
  @properties = {}.merge self.class.defaults
30
+ # Check to make sure all of the given properties are within the acceptable list
31
+ # TODO: Rename this method, it's terribly named
32
+ # TODO: Move it above everything else, and in an if block to save CPU time
14
33
  check_properties_of values
34
+ # Go over each property-value pair and send the value to the correct
35
+ # property method
15
36
  values.each { |property, value| send property.to_sym, value }
37
+ # Return the object for chaining purposes
38
+ # TODO: Is this even needed?
16
39
  self
17
40
  end
18
41
 
42
+ # Redefining the `to_s` method so that print out is prettier
43
+ # TODO: Change object_id to the correct hash
44
+ # TODO: Remove self from object_id
19
45
  def to_s
20
46
  "#<#{self.class}:#{self.object_id} #{properties.map{|k,v| k.to_s + '=' + v.inspect}.join(', ')}>"
21
47
  end
22
48
 
23
49
  private
50
+ # Defining a method that makes sure all of the properties are within
51
+ # the list of class properties
52
+ # TODO: Look into expanding this to allow for "subclass with slightly different
53
+ # attributes" situation
54
+ # TODO: Rename the parameter like with initialize
24
55
  def check_properties_of(values)
56
+ # Go over each key, and if it results in false raise an ArgumentError
57
+ # TODO: Provide helpful raise message
25
58
  raise ArgumentError unless values.each_key.all? do |property|
59
+ # Check to see if the property is included in the class property list
60
+ # TODO: Raise properties into a class variable
26
61
  self.class.properties.include? property
27
62
  end
28
63
  end
@@ -1,3 +1,3 @@
1
1
  module Intrinsic
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intrinsic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &2156056780 !ruby/object:Gem::Requirement
16
+ requirement: &2157876040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - =
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.2.2
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2156056780
24
+ version_requirements: *2157876040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: yard
27
- requirement: &2156056260 !ruby/object:Gem::Requirement
27
+ requirement: &2157875520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 0.7.4
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2156056260
35
+ version_requirements: *2157875520
36
36
  description: Intrinsic adds properties to your objects
37
37
  email:
38
38
  - kurtisrainboltgreene@gmail.com
@@ -74,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  segments:
76
76
  - 0
77
- hash: 1445375515393034073
77
+ hash: -3006681913647196833
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  none: false
80
80
  requirements:
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  segments:
85
85
  - 0
86
- hash: 1445375515393034073
86
+ hash: -3006681913647196833
87
87
  requirements: []
88
88
  rubyforge_project:
89
89
  rubygems_version: 1.8.10