classy 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/classy/templatable.rb +37 -0
  3. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -1,3 +1,36 @@
1
+ # Templatable allows a class to set default variables for its instances.
2
+ #
3
+ # == Example
4
+ #
5
+ # class Widget
6
+ # extend Templatable
7
+ #
8
+ # templatable_attr :awesomeness, :temperature
9
+ # awesomeness :total
10
+ # end
11
+ #
12
+ # Widget.awesomeness # => :total
13
+ # Widget.temperature # => nil
14
+ #
15
+ # doodad = Widget.new
16
+ # doodad.awesomeness # => :total
17
+ # doodad.temperature # => nil
18
+ #
19
+ # # New defaults affect existing instances.
20
+ # Widget.temperature = :cool
21
+ # Widget.temperature # => :cool
22
+ # doodad.temperature # => :cool
23
+ #
24
+ # # Instances can override the defaults.
25
+ # doodad.awesomeness = nil
26
+ # doodad.temperature = :cool
27
+ #
28
+ # == Note
29
+ #
30
+ # The default values are stored as class variables of the same name as the
31
+ # associated instance variables. This may lead to some surprising results, eg,
32
+ # if you set a default value on a subclass.
33
+ #
1
34
  module Templatable
2
35
 
3
36
  # A hash to track templatable variables that have been locally set.
@@ -6,6 +39,10 @@ module Templatable
6
39
  #
7
40
  @@ever_been_set = Hash.new { |hash, key| hash[key] = {} }
8
41
 
42
+ # Defines one or more templatable attrs, which will add instance methods
43
+ # similar to Ruby's standard attr_accessor method, and will also add class
44
+ # methods to set or get default values, as described above.
45
+ #
9
46
  def templatable_attr (*symbols)
10
47
  symbols.each do |symbol|
11
48
  # define the instance setter method
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: classy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hyland