Class: PryTheme::Theme Private
- Inherits:
-
Object
- Object
- PryTheme::Theme
- Defined in:
- lib/pry-theme/theme.rb,
lib/pry-theme/definition.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Creates a new Pry Theme theme. This class is not meant for the direct instantiation. Use create instead.
Defined Under Namespace
Modules: DefaultAttrs, DynamicMethod Classes: Definition
Constant Summary collapse
- DEFAULT_CONFIG =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ :name => "prytheme-#{ rand(1_000_000_000) }", :color_model => 256, :author => 'Unknown Author', :description => '', }
- VALID_NAME =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Matches against valid theme name. It must start with a letter. The letter case is not important.
/\A[A-z][A-z0-9-]*\z/i
Instance Attribute Summary collapse
-
#active ⇒ Boolean
(also: #active?)
readonly
private
Whether this theme is a current theme.
-
#definition ⇒ Theme::Definition
readonly
private
The heart of every theme: the colour definitions.
Instance Method Summary collapse
- #activate ⇒ Object private
- #author(options = nil) ⇒ Object private
- #color_model ⇒ Object private
- #define_theme(&block) ⇒ Object private
- #description(text = nil) ⇒ Object private
- #disable ⇒ Object private
-
#initialize(config = {}, &block) ⇒ Theme
constructor
private
A new instance of Theme.
- #name ⇒ Object private
- #to_coderay ⇒ Object private
Constructor Details
#initialize(config = {}, &block) ⇒ Theme
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Theme.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pry-theme/theme.rb', line 35 def initialize(config = {}, &block) @config = DEFAULT_CONFIG.merge(config) @authors = [{ :name => @config[:author] }] @default_author = true @active = false validate_config instance_eval(&block) end |
Instance Attribute Details
#active ⇒ Boolean (readonly) Also known as: active?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether this theme is a current theme.
31 32 33 |
# File 'lib/pry-theme/theme.rb', line 31 def active @active end |
#definition ⇒ Theme::Definition (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the heart of every theme: the colour definitions.
28 29 30 |
# File 'lib/pry-theme/theme.rb', line 28 def definition @definition end |
Instance Method Details
#activate ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
90 91 92 93 |
# File 'lib/pry-theme/theme.rb', line 90 def activate ::CodeRay::Encoders::Terminal::TOKEN_COLORS.merge!(to_coderay) @active = true end |
#author(options = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/pry-theme/theme.rb', line 46 def ( = nil) if if [:name].length > 32 raise PryTheme::ThemeError, "author's name must be no longer than 32 characters" end if @default_author @default_author = false @authors[0] = else @authors << end end @authors end |
#color_model ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
82 83 84 |
# File 'lib/pry-theme/theme.rb', line 82 def color_model @config[:color_model] end |
#define_theme(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 |
# File 'lib/pry-theme/theme.rb', line 74 def define_theme(&block) @definition = Definition.new(color_model, &block) end |
#description(text = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/pry-theme/theme.rb', line 63 def description(text = nil) if text if text.length > 280 raise PryTheme::ThemeError, "description must be no longer than 280 characters" end @config[:description] = text end @config[:description] end |
#disable ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'lib/pry-theme/theme.rb', line 86 def disable @active = false end |
#name ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
78 79 80 |
# File 'lib/pry-theme/theme.rb', line 78 def name @config[:name] end |
#to_coderay ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/pry-theme/theme.rb', line 95 def to_coderay {}.tap do |coderay| @definition.class.instance_methods(false).each { |attr| attr = attr.to_sym val = @definition.__send__(attr) if @definition unless val.kind_of?(Color) coderay[attr] = {} ivars = val.instance_variables.delete_if { |v| v =~ /color_model/} ivars.each do |ivar| coderay[attr][ivar.to_s.chomp('_')[1..-1].to_sym] = val.instance_variable_get(ivar).to_ansi end else coderay[attr.to_s.chomp('_').to_sym] = val.to_ansi end } end end |